Backing up an Android phone

2020/04/24

One day my wife asked me to help her backup about 30Gb of photos from her android phone. At first we had tried to copy files over MTP (in Win10). This idea quickly showed its incapacity. You see, Win10 wants to be nice and tries to calculate ETA. But 30Gb is a lot of files and over MTP it takes one request per file to get its size. So, we waited half an hour while Win10 was preparing to start the transfer and I had aborted this madness.

Here is a sane approach to do the job.

  1. Install SimpleSSHD on the phone. Set "Start on Open" in app settings.

  2. Grab adb-channel script and add this snippet to ~/.ssh/config

       Host sshelper
           Port 2222
           ProxyCommand adb-channel tcp:%p org.galexander.sshd/.SimpleSSHD 1
    
  3. Copy your public key to the phone.

    Please note that ssh-copy-id won’t work. Just ssh sshelper and then paste the key from ssh-add -L into authorized_keys. Details here.

  4. Now backup with rsync as usual.

       rsync -e ssh -av sshelper:/sdcard/DCIM .
    
  5. Optional

    This setup assumes that you copy files over USB. But nothing stops you from starting SimpleSSHD manually and copy files over WiFi.

       rsync -e 'ssh -p 2222' -av 192.168.178.42:/sdcard/DCIM .
    

Now that newer Android versions (newer than 12 I believe) don’t allow apps to access files of other apps, I had to revisit my backup solution.

Now I simply use the adb-sync script, but I also do adb root to give the script full access to any files. The script is pretty smart and it works kind of like rsync, downloading only newer files. It fits perfect the use case.