Tag Archives: android

In a previous post I discussed how to backup android with rsync. In this post, I’ll improve on that solution so it happens when you plug the phone in, rather than manually. My solution happens to know I have only one phone; you should adjust accordingly.

The process is

Plug the phone in

Unlock the screen (you’ll see a prompt to do this).

Backup starts automatically

Wait for the backup to finish before unplugging

First, let’s add a udev rule to auto-mount the phone when it’s plugged in and unlocked, and run appropriate scripts.

We’ll add something to mount and unmount the system. Keeping in mind that mounting only works when the screen is unlocked we’ll put that in a loop that checks if the mount worked:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

#!/bin/sh

# /usr/local/bin/android-mountfs

android_locked()

{

ls/media/android2&gt;/dev/null&gt;/dev/null

["$?"-eq2]

}

jmtpfs/media/android# mount

whileandroid_locked;do

fusermount-u/media/android

sleep3

jmtpfs/media/android# mount

done

1

2

3

#!/bin/sh

# /usr/local/bin/android-umountfs

fusermount-u/media/android

The contents of /usr/local/bin/phone-backup are pretty me-specific so I’ll omit it, but it copies /media/android over to a server. (fun detail: MTP doesn’t show all information even on a rooted phone, so there’s more work to do)

Connecting android to Windows and Mac, pretty easy. On arch linux? Major pain. Here’s what I did, mostly via the help of the arch wiki:

Rooted my phone. Otherwise you can’t back up major parts of the file system (including text messages and most application data) [EDIT: Actually, you can’t back these up over MTP even once you root your phone. Oops.]

Installed jmtpfs, a FUSE filesystem for mounting MTP, the new alternative to mount-as-storage on portable devices.

Enabled ‘user_allow_other’ in /etc/fuse.conf. I’m not sure if I needed to, but I did.

Plugged in the phone, and mounted the filesystem:

1

jmtpfs/media/android

The biggest pitfall I had was that if the phone’s screen is not unlocked at this point, mysterious failures will pop up later.

Synced the contents of the phone. For reasons I didn’t diagnose (I assume specific to FUSE), this actually fails as root: