Backup an iPhone with Linux

This is a follow-up on Connect an iPhone to a Raspi.

Install the necessary packages

Find the event iPhone connected

  1. Connect your iPhone:
  2. Run this script:
lsusb | grep iPhone
Bus 001 Device 007: ID 05ac:12a8 Apple, Inc. iPhone5/5C/5S/6

Catch the event iPhone connected

# Content of /etc/udev/rules.d/99-iphone.rules
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="5ac/12[9a][0-9a-f]/*", ACTION=="add", ENV{SYSTEMD_WANTS}="iphone-connect.service"

Create the trigger iPhone connected

#Content of /etc/systemd/system/iphone-connect.service
[Service]
Type=oneshot
ExecStart=/bin/sh /home/pi/scripts/backup_iphone.sh

Create the action Backup iPhone

# Content of ~/scripts/backup_iphone.sh
src=/mnt/iphone/ #Must exist in prior
dst=/media/pi/usb500gb #Must exist in prior
log=/home/pi/backup_iphone.log
sleep 5
ifuse $src &&
    rsync --verbose --archive --compress --update --log-file=$log $src $dst

Restart and reload all actors (not the iPhone though)

sudo udevadm control --reload-rules && udevadm trigger
service udev restart
systemctl daemon-reload #THIS one is crucial

Monitor the backup process

journalctl -f --unit=iphone-connect.service --output=cat