Search the Site

Sponsors

bottom corner

Backing up Android Phone to Linux

This note demonstrates a simple way to back up files from Android to Linux.

This page is filed under keyword(s): linux, android.

My environment: Smart phone running Android version 5.1.1, and computer running Ubuntu 14.04 LTS

I have a few key folders on my phone that I would like to back up regularly. For simplicity sake, let us say that I am just dealing with the "Camera" folder which holds all my latest photographs. The following commands makes use of gvfs-commands (Gnome virtual file system) to copy/move files, assuming the phone has been connected via USB to the computer, and the phone has been unlocked.

The bash script I currently run looks like this:

#!/bin/bash
gvfs-copy /run/user/1000/gvfs/mtp*/Phone/DCIM/Camera/*.* /home/username/Pictures/phone/
gvfs-move /run/user/1000/gvfs/mtp*/Phone/DCIM/Camera/*.* /home/username/tmp/
gvfs-move /home/username/tmp/*.* /run/user/1000/gvfs/mtp*/Phone/Pictures/archive/

As you may have noticed, I took the safe approach of copying the photos to my computer, then moving the same photos again to a temporary directory on my computer, and finally moving the temporary files back onto the phone in an archive folder. The final steps effectively represents a move from the Camera folder on the phone to the archive folder on the phone; this is because gvfs-move does not support the move of files within the same device at this time.

A more direct way to do so might be the following, but again, I decided to do the safer approach above; just in case something goes wrong, there should always be a copy of the files to fall back on.

#!/bin/bash
gvfs-move /run/user/1000/gvfs/mtp*/Phone/DCIM/Camera/*.* /home/username/Pictures/phone/
gvfs-move /home/username/Pictures/phone/*.* /run/user/1000/gvfs/mtp*/Phone/Pictures/archive/

Did you find this page useful? Please consider browsing other articles or subscribing to the RSS feed to keep up with latest.

This page is filed under keyword(s): linux, android.
Author: C. Peter Chen
Last updated: 26 Jul 2016

bottom corner