Android Data Backup: gvfs and rsync are Your Friends!

Most of you might know the feeling one has when that precious smartphone glides out of your hands, hits the street and goes straight to smartphone heaven: Horror followed by “damn, I haven’t copied my pictures yet”. The problem I had for many years is that backing up meant to know which pictures (or files in general) I had already copied and then only copying the new ones. That’s an exercise I didn’t even want to do once a month.

How nice would it be if it was just possible to rsync the phone to a backup drive. Turns out that this is actually possible!

The key to rsync’ing my Android based phone is that when connecting it over USB with the default “MTP” file transfer setting, Linux mounts the device with the Gnome Virtual File system (gvfs). This means it can be used with the file explorer, AND, that’s the important part, it is mounted into the overall file system!

The file system path looks like this:

/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C010%5D/Internal shared storage

Looks a bit ugly but rsync works just fine with this path. Over a USB-3 cable I could achieve a data transfer rate of around 20 MB/s with my Samsung S9. That’s not stellar but good enough. And here’s my rsync command that makes a copy of everything on the device:

rsync --dry-run -h --progress --stats -r -tgo -p -l -D --delete \
"/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C010%5D/Internal shared storage" \
/media/data/backup-drive/S9-backup

When running rsync you will probably see quite a number of error messages because some special files (which I don’t need anyway) can’t be copied.

Two quircks I have noticed over the past couple of weeks that need a bit of attention:

  • The ‘host’ part of the path name unfortunately changes every time the device is connected. That means that the rsync command needs to be adapted every time. I haven’t had the time yet to find out if this could be automated, so if you have an idea, please let me know
  • The MTP implementation of my S9 sometimes doesn’t show the latest files. Rebooting the phone before running rsync fixes that.

3 thoughts on “Android Data Backup: gvfs and rsync are Your Friends!”

  1. I can recommend syncthing. I use it on my phone to (one-way) sync my photos and other files to my PC and NAS. After set-up, it’s fully automatic and works in the background and can be set to only be active in my home network. No need for any manual intervention at all.

Comments are closed.