2008-12-26

iPhone backup and upgrade

Filed under: Geekiness — iain @ 17:10:33

The iPhone 2.2 firmware has been available for a while now but I’d thus far resisted the urge to upgrade because I’d heavily customised my jailbroken phone with my own sound effects, ringtones and Winterboard settings.

Official Apple stuff is backed up and restored after an upgrade but I knew I’d lose the personalised changes.

I decided to use Subversion to archive my tweaks and restore them after the upgrade. The exact steps I used aren’t precisely the same as I’ll describe here. I’ll change the description to be easier to follow along for people with no experience using Subversion before.

Creating a repository

First of all I needed to create a repository on some server somewhere. I could have done this viz:

    $ svnadmin create /home/iain/iphonesvn

Then I created the standard directories that all Subversion tutorials tell you to.

    $ mkdir iphonetmp
    $ cd iphonetmp
    $ mkdir trunk tags branches
    $ svn import -m "Initial import." file:///home/iain/iphonesvn
    $ cd ..
    $ rm -r iphonetmp

iPhone prep

I needed to install some packages on the iPhone. Cydia can be used to install OpenSSH, Subversion and AptBackup.

Having SSHed to the phone as root I checked out my (empty) Subversion branch.

    # cd /
    # svn co svn+ssh://iain@server/home/iain/iphonesvn/trunk .
    Checked out revision 1.

Now the phone was ready to add files.

Adding files on the phone

Usually when you add files and directories to a Subversion working copy the client likes to recurse and add stuff in subdirectories too. I didn’t want to back up all 16Gb of standard stuff so I added the parent directories non-recursively. For example my custom ringtone is in /private/var/stash/Ringtones so I had to do this:

    # svn add -N /private
    # svn add -N /private/var
    # svn add -N /private/var/stash
    # svn add -N /private/var/stash/Ringtones
    # svn add "/private/var/stash/Ringtones/My cool ringtone.m4r"

I also added my SMS received and other sounds from /System/Library/Audio/UISounds and Winterboard themes from /Library/Themes. The latter was a symlink to /private/var/stash/Themes.<random> and that was the path I added.

With everything done I ran svn commit to save stuff in the repository.

Tagging

Just for reference I checked out the files on my server and committed them to a tag branch so I could associate this fileset with the 2.1 firmware.

    $ svn co file:///home/iain/iphonesvn/ iphonetmp
    $ cd iphonetmp
    $ mkdir tags/2.1
    $ svn add tags/2.1
    $ svn copy trunk/* tags/2.1
    $ svn commit

Application backup

The AptBackup tool takes a snapshot of the phone’s installed applications and SSH settings, writing them to the preferences directory so that they will be backed up and restored by iTunes. I ran this last of all:

    # /Applications/AptBackup.app/backup

iTunes sync

Finally I connected the phone to iTunes so it would take a backup of everything including the AptBackup settings.

Restoring everything

After upgrading to the jailbroken 2.2 firmware I once again installed OpenSSH, AptBackup and Subversion from Cydia, connected to the phone and ran

    # /Applications/AptBackup.app/restore

Restoring my custom stuff was slightly more tricky than simply checking out the repository as Subversion, unlike say Perforce, won’t allow you to check out on top of an existing directory structure. Instead I checked out to a subdirectory and "moved" the working copy.

    # svn co svn+ssh://iain@server/home/iain/iphonesvn/trunk /trunk
    # find /trunk -name .svn -type d | while read in; do mv "$i" "${i##/trunk}; done
    # cd /
    # svn up
    # rm -r /trunk

I mentioned earlier that /Library/Themes was a symlink to a particular random location. Needless to say this had changed. I contemplated moving its contents to the version I’d checked out and retargetting the symlink but eventually I decided to move the files in the repository.

    # svn add -N /private/var/stash/Themes.newlink
    # svn mv /private/var/stash/Themes.oldlink /private/var/stash/Themes.newlink
    # svn commit

Behold the restored iPhone!

No Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

You must be logged in to post a comment.

Powered by WordPress