christoph ender's

blog

monday the 21st of october, 2024

restoring data from macOS addressbook backup

Today I noticed that one of my contact cards from my macOS's address book was missing. Since I've got Apple's advanced data protection enabled, there's no way to rewind the address book via icloud.com. To work around this I'm regulary creating local backups using address book's “Choose File” → “Export” → “Contacts Archive”. I didn't want to simply restore last week's backup though, I rather frist wanted to know what had changed between last week's and today's state. I also didn't want to run a restore operation since I've linked two external carddav accounts into the address book and I had no idea what would happen to them.

There are probably better ways to achive this goal, but this one worked for me: I found out that the contact archive that's exported simply represents the contents from ${HOME}/Library/Application Support/AddressBook. I quit address book, moved the current AddressBook folder aside and moved the backup into it's position. When address book was now restarted it began re-syncing the contents from iCloud, however, in the short period of time before it does so it's possible to export the restored data in form of VCFs by just selecting everything and dragging it onto the desktop. The same can then be done with the current, “broken” state, which then allows comparing both dumps:

# Using “FN” field, which contains the full name, for comparison:
grep FN: old.vcf > old-fns
grep FN: new.vcf > new-fns
diff old-fns new-fns

The resulting list can now be used to evaluate the “damage” done to the current address book and whether it makes sense to run a full restore or maybe – as in my case – just to restore a single, lost contact card while keeping the current address book.