# 3-Way Linux and Android Backup

• What do you want to backup?

This probably includes you personal data (pictures, music, documents, etc…) as well as essential system configurations (See the Arch Wiki for a rundown of this)

• Where do you want it to go (from where, how often)?
• How are you gonna get it there (local storage, cloud, home-based server, automatic, incremental)?

I prefer to have bot “local” and “remote” options. That is, one backup in case I screw someting up (local) and another (remote) in case the house burns down or something.

Here I’m going to go over a simple 3-way backup solution featuring a host (pc), a remote (Android phone), and cloud (Google Drive). I wrote an earlier post about Syncthing and you can get a general idea there. I’m also going to assume you’ve read the Syncthing ‘Get Started Guide’.

### Step 1 (Remote > Host)

On your phone you’ll want to install a file manager app (such as OI) for this step and get GDriveSync for later. Open the syncthing on your phone and configure the files you want to share with your Linux machine.

You want to avoid duplicating data, so read Syncthing’s documention on ignoring files / folders.
In the setup above, phone_storage is the root of my phone (which is the folder’s master) and linked to my pc, thus backing up my phones media and documents. Simple enough.

However, I want some of that media to acessible on my pc rather than burried in the file tree (e.g. ~/music rather than ~/phone/storage/emulated/0/Music). So, the exceptions I have configured are for /storage/emulated/0/{Music,Pictures,Downloads,pc_backup} (See below about pc_backup. I created separate folder links for these (to ~/downloads ~/music ~/pictures respectively) and made the phone the master for them as well since I do much more dowloading, music listening, and picture taking there anyhow.

### Step 2 (Host > Remote):

Next, fire up Syncthing on your Linux computer:

$systemctl --user start syncthing On your phone, use the file manager app you downloaded to create a folder that you want to sync your pc to (e.g. /storage/emulated/0/pc_backup). Configure Syncthing to linke your home directory (/home/user_name) to the folder you created on the phone’s internal storage. Just like above you’ll want to configure some exceptions so that you’re not duplicating date. The list will probably be the same. For example, I don’t want the backups of my phone (stored on my computer) being included when my computer backs up to my phone. With the app and server running, things should be chugging away nicely though they will take a good bit of time for the initial sync. ### Step 3 (Remote > Cloud): Open the GDriveSync app and connect the appropriate Google account. Tap the + button on the bottom left of the screen, then “select” (we want to be using /storage/emulated/0). For the Google Drive folder selection, create a folder called phone_backup (this will also include a backup of your pc since it is synced to your phone). Then select “Two Way Sync - Upload”. This is the same thing as checking “master” in Syncthing when you want the phone’s data to have discretion over the destination. GDriveSync also has options for configuring automatic backups and syncing over WiFi only, which are both very good ideas in this case. ### Bonus: You may want to backup more than just /home. What do you absolutely need to backup? I’ve found the simplest and effective way to be the Arch Wiki link posted in the introduction. What do you need to backup? • System settings (/etc) • Packages (/var/cache/pacman/pkg/*) • Personal data (/home) We’ve already covered the last bullet, so let’s look at the others. Firstly, consider the amount of storage you have available on your phone. If you have copious amounts of storage, then you could rsync copies of /etc and /var/cache/pacman/pkg to ~/home/use/r, but it saves storage space and takes marginally more effort to restore if you use tar and pacman respectively. To backup system settings, run: $ sudo XZ_OPT=-9 tar -cjf /home/user/etc.tar.xz /etc

For a list of installed packages from the official repository, run:

$pacman -Qqe | grep -v "$(pacman -Qqm)" > /home/user/pkglist.off

For a list of unofficial packages installed on your system, do:

\$ pacman -Qqm > /home/user/pkglist.aur

Creating a cron job with these commands allows us to automate the process.

### Conclusion:

The important things to backup are A) system settings, B) installed programs, and C) personal data. Also, one backup is never enough.
Ideally backups should be incremental (which those in this tutorial are not) and accomodate different potential for data loss (e.g. theft, fire, user error). The process covered here looks like this when finished:

• Phone uses Syncthing to backup internal storage to pc
• PC uses Syncthing to backup user’s /home, a copy of system settings, and list of installed packages to phone’s internal storage
• Phone uses GDriveSync to send a copy of phone’s internal storage (including backup content sent from pc to phone) to Google Drive.