Repairing a Damaged Lightroom Catalog
So you open Lightroom one day to start that Keywording job you’ve been putting off for years. Lightroom, chirpy as ever, warns you that the catalog is corrupt and can’t be opened. Well, yay! I don’t have to do that damn keywording!
Or not, of course. You also can’t do anything else with it. Hmm… if it’s corrupt, can I bribe it? Nope. Tried that. Maybe not so yay.
What’s happened? To answer that, we need to look at different kinds of damage, and how they can be repaired.
Structural Damage
Think of the catalog as a book. That’s one of those old-fashioned piles of ironed-out wood pulp that can’t run apps, but it’s way easier to visualise how it works; you open it, you turn pages, pages have information on them. Nice and simple. So, how could you damage a book? (Don’t. I’ll hate you, burning books is for Nazis. This is just an example.)
The most obvious way would be to rip a bunch of pages out, or change the order around. Either way, this is physical damage; even if you glued all the pages back in in the wrong order after you’ve ripped them out, it’s still physical damage and the book’s contents don’t make sense any more. This is the first type of damage you can do – structural (since ‘physical’ doesn’t really make sense in the context of a file on a hard disk).
The digital equivalent is overwriting part of a file with random data, or writing a bit of it in the wrong place. Obviously this shouldn’t happen, but equally obviously, sometimes it does. This kind of damage is usually picked up by Lightroom immediately, because it tries to turn to page 231 and it’s just plain not there.
But Why???!?
Your computer hates you. Everybody knows this.
It manifests this hatred by taking revenge on you when you’re not nice to it. For example, if you force-kill the Lightroom task, or suddenly kill the power, this is a good way to cause structural catalog damage. Changes to files are written to disks in chunks and if the power, or the instructions on what to write where, unexpectedly stop halfway through then you can end up with the catalog stuck between two states.
In the book analogy, you were in the middle of ripping out all the pages for chapter 3 because you’d totally re-written it, but somebody swiped the book after you’d only managed to change all the even-numbered pages. (If you manage to actually do this, please let me know exactly how!) The previous copy was fine, the intended copy would have been fine, but stuck halfway between it’s meaningless.
OK, but how do I fix it?
Restore from backup. You keeps backups? Right?
Even if you don’t think you do, there’s a good chance you do. Lightroom keeps it’s own backups automatically unless you’ve told it not to. Look in the same folder as the catalog and, if you’re lucky, you’ll find another folder called “Backups”.
- Take a copy of your current, damaged, catalog just in case.
- Copy one of the backed-up catalogs over the damaged one.
- Re-open Lightroom and cross any functioning digits.
Incidentally, if you find you’ve got a huge number of backups in there taking up 30 percent of your hard disk space, you can use a handy Backup Cleaner plugin to keep on top of it.
You don’t have a backup? Neither the catalog nor your hard disk? No “Time Machine” or “Restore to Previous Versions”? Oh.
Oh dear.
Well, option one is to a) learn a lesson and b) start from scratch with a new catalog, and re-import all your photos. There’s a good chance you’ll lose most or all of the extra information that Lightroom offers unless you’ve been writing absolutely everything out to XMP files.
Option two is to use the web search engine of your choice to find a “SQLite Repair Tool”. Yes, SQLite, not Lightroom. Lightroom’s catalog is actually a SQLite database file, nothing more, and so any generic tool or method for repairing SQLite files might be able to get something back. It might work. Maybe. Assuming your computer doesn’t hate you.
Logical Damage
Back to the book analogy. All the pages are intact, the table of contents is there and all should be good. Except that at some point, some idiot has replaced chapter 3 with a Klingon translation. (If you’re the kind of person who can actually read Klingon, assume that most people can’t and bear with me here.)
Structurally it’s fine, but the information contained in that intact structure is still meaningless (to normal humans. See note above.) If you could find a Klingon reader to translate it back, you’d be sorted. (Or you might be dead because it was actually Romulan, not Klingon, and the Klingon reader you employed to translate it was mortally offended and that’s usually a fatal state of affairs. Maybe I’ll stop with the Star Trek references now, I’m sure you’ve got the point.)
The real problem here is that until you try to actually read chapter 3, you don’t know that it’s in Klingon. If you assume that each chapter is one photo record and this is chapter 3 of 43,012, it might take you a very long time to notice a problem at all.
But Why???!?
This time it’s more down to bad luck. Part of your computer’s malevolence has backfired on it, and it has confused itself. Lightroom has tried, in good faith, to write some information back to the catalog but the information itself was somehow damaged. That damaged information has been faithfully and accurately stored (structural integrity is still OK), but it’s faithfully and accurately stored nonsense (logical integrity is not OK).
OK, but how do I fix it?
Easy. You find the damaged records, remove that photo from the catalog, and re-import it. You might lose the Lightroom-specific data for that photo, but maybe not. It depends on exactly what the damage was.
Finding the damaged records, I hear you ask? Also easy. Start with the first photo and allow Lightroom to show the details in the Metadata panel on the right. If Lightroom starts to act shifty, not showing anything or just giving a spinning “hold on a sec” pointer, this is likely a damaged photo record. Not the photo itself, that’s probably just fine, it’s just Lightroom’s record of it that’s knackered. If this photo has the details shown immediately and correctly, try the next. Repeat until done, and remember that just because you’ve found a problem doesn’t mean you’ve found the problem.
You have something better to do with the next two weeks? Oh, that’s an issue. OK, in that case you might want to try the Duplicate Finder plugin. It’s not really what it’s for, but it does have an “Identify Damaged Records” function that does the whole scan in a few seconds. Once it’s done you remove and re-add the damaged photos and you’re good to go.
Actually removing the damaged photo may be… tricky. Some kinds of damage cause no problem, you can remove the photo from the catalog by using the old “show in folder” and “remove from catalog” trick. Alternatively you can reject it and use the “Delete Rejected Photos” menu item. If these work, awesome, you’re done. If not…
If not, we get sneaky. If it’s damaged in a way that means you can’t even remove it, then we create a new catalog containing everything except the damaged one(s). Lightroom has a useful but rarely-used featured on the File menu called “Export as Catalog…” . It does what it says; for all selected photos, create an entirely new catalog containing everything in the current catalog. Normally, the catch here is that this is the one place that isn’t affected by some types of logical catalog damage, so those bad records end up being cloned into the new catalog.
Not helpful.
So get sneakier. Reject the damage photos, go to Lightroom’s “All Photographs” collection, and use the Filter Bar to exclude any rejected photos. Now you can select all (or none, because Lightroom) and use the “Export as Catalog…” option. In practise, I’ve found that the damaged photos are always shown right at the start of the “All Photographs” collection because there’s no information on how they should be sorted, which makes it even easier to select everything else.
So fine, damaged records, you can stay. But we’re all leaving. Nyeh.
Sounds like a faff…?
Finally, there is always the option to just ignore the catalog damage and pretend it’s not there. I mean, all your other photos are still in there. Well, most of them. Probably. Assuming your computer doesn’t hate you.