Recover iPhone contacts from the iTunes backup

Locate your most recent iPhone backup created by iTunes, which will be in %AppData%\Roaming\Apple Computer\MobileSync\Backup and ~/Library/Application Support/MobileSync/Backup on Windows and Mac respectively.

Make a copy of the entire backup directory and work on the copy.

Now locate the file which contains your contacts. I worked on Mac and what I did is:

  1. to come up with a friend’s first (or last) name which is of a single word and not very common,
  2. grep the name to find out the files containing it,
  3. read each file’s first line to see if it’s an SQLite database file, which starts with the magic string SQLite format 3,
  4. load the database file using the SQLite command-line client, e.g., sqlite3 <database>, and check if there’s any table that contains the contact, which for me was a table named ZCONTACT,
  5. and identify which fields contain the name and the phone number, which in my case were ZNAME and ZKEY respectively.

To see the list of tables in a database and the schema of a table, issue the command .tables, and .schema <table>, respectively.

Once you identify the SQLite database, you simply export the contact details in the table you've just found by issuing the following commands in the SQLite console:

.header on
.mode csv
.output contacts.csv
select zname as Name, zkey as Number from zcontact order by zname;
.quit

You will find all your contacts in contacts.csv as in the comma-separated values format, which opens in Numbers or in Excel for instance.

You could also save them as an HTML file by setting the mode to HTML, e.g., .mode html, or something else as you like.

Recover iPhone contacts from the iTunes backup