Local backup to Debian 9 Stretch

I am stupid, lazy, and paranoid. That means that I must back my phone up locally, far from Google’s prying eyes. It also means that I don’t want to think about this. Today was Backup and Pay Bills Day, so I wrote a simple shell script to pull stuff from my phone to my ${HOME}.

The Teracube 1 apparently uses mtp (“Media Transfer Protocol”) to move files over a USB connection. I have usually backed my phone up either through USB Mass Storage, or by installing an sftp server on the phone and talking to that. Fortunately, Debian Stretch has some mtp support which appears to work with the Teracube.

This script requires the jmtpfs package, available through apt in the main repo. It also uses fusermount, which is in the “fuse” package; I did not have to install that. I played a little bit with mtp-tools, but I do not believe they are necessary. This script currently backs up only /‘Internal shared storage’. I use TitaniumBackup to put my Contacts database in there before running it. You will also need to make sure first that your phone is connected to a USB port and then that Settings->Connected devices->USB->File Transfer is turned on. You do not need to mount the phone from your desktop.

The backup will turn up in the file named in the ${BACKUP} symbol. I don’t back up my downloaded podcasts. If there are other files in /‘Internal shared storage’ which you do not wish to back up, you can add "–EXCLUDE=’ lines to the tar command as appropriate.

---------------Script starts below this line-------------------

#!/bin/bash
################################
#
# Back up Teracube Phone with mtp and jmtpfs  
#
################################

MTPT=${HOME}/Teracube/mount
BACKUP=${HOME}/Teracube/backup/teracube.tgz
if ! jmtpfs ${MTPT}
then
    echo Oops.  Is the phone properly connected?
fi

cd ${MTPT}
tar --exclude=Android/data/com.podkicker/files/PodkickerDownloads/* -czvf ${BACKUP} 'Internal shared storage'
cd -
fusermount -u ${MTPT}

Have fun out there!

3 Likes

Awesome stuff! Reminds me of my local backup scripts for WebOS and FireFoxOS. Ah, those were the days :sob:

Snrk. I am very much a Command Line kinda guy. Of course, you could stick this script under a desktop icon if you so desired.