Extract pictures and videos from iPhone backup

September 23, 2021    Blog Post

How to get access to backup iPhone files if you no longer have iPhone ???


Where is a problem ???

Let’s say that you have iPhone backup and your’re not longer have iPhone or you’re trying to restore iPhone from backup but it’s failing.

I have been in one of these situation, where I was not able to restore iPhone from local backup where one of my phones broke and I got newer iPhone model.

I looked to backup directory, and what I seen there was only directories and files with no commonsense filenames:

drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 f4
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 f5
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 f6
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 f7
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 f8
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 f9
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 fa
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 fb
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 fc
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 fd
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 fe
drwxr-xr-x 2 vagrant  vagrant      4096 Sep  6 08:23 ff
-rw-rw-r-- 1 vagrant  vagrant    646402 Sep  6 08:11 Info.plist
-rw-rw-r-- 1 vagrant  vagrant  26308608 Sep  6 08:23 Manifest.db
-rw-rw-r-- 1 vagrant  vagrant     72968 Sep  6 08:23 Manifest.plist
-rw-rw-r-- 1 vagrant  vagrant       189 Sep  6 08:23 Status.plist
-rw-rw-r-- 1 vagrant  vagrant    31156 Sep  6 08:11 ff03989743f9e2bb9b86c6a969c546aaaa502918
-rw-rw-r-- 1 vagrant  vagrant  1833457 Sep  6 08:14 ff0b7b56ff5fae4cfb88ffd43920a38524bce9db
-rw-rw-r-- 1 vagrant  vagrant     8530 Sep  6 08:22 ff0be3c557df13474245636a5bcc446193a0bcef

This is how your backup looks like. No meaning something filenames and directories.

Not really handy :-(


Let’s Crack On


What is Manifest.db ??

First looks to files inside backup directory landed on Manifest.db file. Running well known file command, helped to identified this file:

$ file Manifest.db 
Manifest.db: SQLite 3.x database, user version 2, last written using SQLite version 3024000

This information told me that Manifest.db file is SQLite 3.x database file and at this point, I started examination of it using sqlite3 command line tool. After few queries I decided to use graphical too called “DB Browser for SQLLite” as it makes whole examination match easier.


Sneaking around Manifest.db

I started looking closer to what is inside Manifest.db file and I found that most intreating for me is Files table as it contains file hash mapping to real filenames with directory path. Another important information in this table is inside domain column, as it tells to what group files belongs.

I picked few filenames from backup, and run SELECT query to check if my informations are correct.

It’s working !!!

After running few queries, I discovered that files in backup directory are located in separated directories where directory name is this same as two first characters from hashed filename:

\backup\ff$ ls -l
total 23552
-rw-rw-r-- 1 vagrant  vagrant    31156 Sep  6 08:11 ff03989743f9e2bb9b86c6a969c546aaaa502918
-rw-rw-r-- 1 vagrant  vagrant  1833457 Sep  6 08:14 ff0b7b56ff5fae4cfb88ffd43920a38524bce9db
-rw-rw-r-- 1 vagrant  vagrant     8530 Sep  6 08:22 ff0be3c557df13474245636a5bcc446193a0bcef
-rw-rw-r-- 1 vagrant  vagrant    69632 Sep  6 08:19 ff0cc36c378ad41b616c82bda1f6ffb864cb8d87


iPhone backup pictures extractor script

After few successful manual restoration of pictures, I started thinking about automation of this process to make it more useful.

I started writing script in Bash which was working OK, but I decided that I’m going to try write final script in Python 3 to allow its to be run from Windows as well.

And this is how iPhone backup pictures extractor born.

This script is quite simple and his source code is available in my GitHub repository https://github.com/monsoft/iphrestore

Its main purpose is to extract pictures and videos from iPhone backup and place these files in corresponding location inside destination directory.

Extraction

To run extraction process you will have to know where is your iPhone backup located.

If you used idevicebackup2 to make your backup (like I did), location of your backup files is easy to identified as it is [your_choice_directory]\[ID]\. If your backup was done using iTune on Windows, its location will be \Users\[USERNAME]\AppData\Roaming\Apple Computer\MobileSync\Backup\[ID]\.

[ID] is a directory name which is different per each phone.

Running iphrestore.py script with -h option will show small help with required information about how to run it.

./iphrestore.py -h
iPhone backup pictures extractor v.0.1 (c) 2021 by Irek 'Monsoft' Pelech

usage: iphrestore.py [-h] backup_dir restore_dir

This small script will extract pictures and videos from iPhone backup.

positional arguments:
  backup_dir   directory where iPhone backup is located
  restore_dir  directory to save restored pictures

optional arguments:
  -h, --help   show this help message and exit

With this infromations, we can run extraction process:

$ ./iphrestore.py iphone_irek_backup/4d7d51a92c2d75e4a99d19e8daa62d17a9fc86c9 restored_backup
iPhone backup pictures extractor v.0.1 (c) 2021 by Irek 'Monsoft' Pelech

..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
 Job Done !!!

After script finished its job, we can go to directory restored_backup and check restored files:

/restored_backup/Media/DCIM$ ls
100APPLE  101APPLE  102APPLE  103APPLE  104APPLE  105APPLE  106APPLE
/restored_backup/Media/DCIM$ ls -l 100APPLE/|head
total 4047816
-rw-rw-r-- 1 vagrant  vagrant    1737252 Sep 23 14:02 IMG_0002.JPG
-rw-rw-r-- 1 vagrant  vagrant    1675372 Sep 23 14:02 IMG_0003.JPG
-rw-rw-r-- 1 vagrant  vagrant     170811 Sep 23 14:02 IMG_0004.JPG
-rw-rw-r-- 1 vagrant  vagrant    1190123 Sep 23 14:02 IMG_0005.MP4
-rw-rw-r-- 1 vagrant  vagrant     268016 Sep 23 14:02 IMG_0006.JPG
-rw-rw-r-- 1 vagrant  vagrant     590916 Sep 23 14:02 IMG_0007.JPG
-rw-rw-r-- 1 vagrant  vagrant     682919 Sep 23 14:02 IMG_0008.JPG
-rw-rw-r-- 1 vagrant  vagrant     169456 Sep 23 14:02 IMG_0009.JPG
-rw-rw-r-- 1 vagrant  vagrant     392936 Sep 23 14:02 IMG_0015.JPG

Let’s check file, to be able to confirm that extraction was correct:

$ file IMG_0998.JPG
IMG_0998.JPG: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, baseline, precision 8, 800x533, components 3

Success !!!

FIN

I hope that you will find my small script useful, especially that I seen on internet similar application to buy for around $30.