Turn Your Old, Cracked Android Phone Into a Backup Server! (UrBackup/Linux Deploy Tutorial Part I)
Today, I'm going to show you how to run a full-fledged backup server on a rooted Android phone with UrBackup and Linux Deploy! Plastic waste isn't going away, but the next big pollution problem to compound our anxieties is e-waste. So why toss out a perfectly good, albeit cracked and worn, phone?
Besides, that old phone of yours:
1. Probably isn't even that old (do you get a new computer every 1-2 years????)
2. Probably has 4-8 processors and ~4 GB of RAM- and definitely has a built-in UPS. Slap an external hard drive on it, and it looks like the perfect candidate to back up your entire home network!
Fair warning: This is a "because I can" type of project. Since we're still working with Android, we have a few hoops we'll have to jump through and we are limited in many ways. This probably won't be the easiest way to do backups on your home network, nor will it be the best use of UrBackup. HOWEVER, once it's set up and running, it's very easy to manage backups for multiple machines and to add storage.
If you're still with me, here's the plan of action for today:
Root your phone. I won't be going over this today, but head over to Magisk to root your phone and come back when you're finished.
Keep in mind, I'm making some very specific configuration decisions in this tutorial, and most of them are to accommodate the quirks of working with Debian on Android in a chroot environment.
OPTIONAL EQUIPMENT (HIGHLY RECOMMENDED)
Although you can technically store your backups on an SD card, this is NOT recommended. SD cards are slower, less reliable and cannot handle constant writing for an extended period of time. If you're planning on backing up to an SD card, just plan on it getting corrupted within a year (or even within a month, if you have a lot of data).
Step 1: Install Linux Deploy and Deploy Debian Buster
b. Once installed, open up BusyBox. Select Install. Once installation is complete, take note of where BusyBox was installed; here, you can see it was installed at "/system/xbin". You will need this location later.
C. Open up Linux Deploy and navigate to the settings icon on the bottom right.
c. Configure the following settings:
PSA: ONCE YOU MOUNT YOUR BLOCK DEVICE, YOU MUST UNMOUNT BEFORE PHYSICALLY DISCONNECTING YOUR BLOCK DEVICE.
This can be by stopping the Linux Deploy container or with the command "umount /path/to/mountpoint". If you disconnect while the device is mounted, you may lose all data. As a precaution, always unmount if you need to physically move the phone with the block device connected.
d. Navigate back to the welcome screen and select the top left menu. Select Settings and scroll all the way down to PATH variable. Here is where you want to set the location BusyBox was installed in step 1.b. Once the PATH variable is set, select Update ENV.
e. Navigate back to the welcome screen and select the top right menu. Select Install. You will see a live log of the installation. Once complete, the log will end with "deploy". Select START at the bottom left of your screen. You are now running a Debian server on your Android phone!
Step 2: Install UrBackup Server
a. SSH into your newly deployed server.
The IP address is the same as your phone, the port will be 22, and you can login with the credentials you set in step 1.c. The rest of this tutorial assumes you are logged in as root. You can see your IP when you open Linux Deploy:
b. Update your system:
apt update && apt upgrade -y && apt install wget
c. Download the .deb package for UrBackup:
This is the latest stable release as of writing. Check their download page for updates.
d. Install the package:
apt install -f ./urbackup-server_2.4.13_arm64.deb
During installation, you will be asked where you want your backup directory to be. Remember this location for the next step. If you've already mounted storage in step 1.c, set this to that mountpoint.
e. Create backup directory.
In this example, I will set the backup directory at "/mnt/backup". If you've already mounted your storage, your directory will already be created; if not, create the directory:
mkdir -p /mnt/backup
Update the permissions:
chown urbackup /mnt/backup
chgrp urbackup /mnt/backup
(This will allow the UrBackup to write to this directory.)
f. Install start script:
We will not be able to call systemd in a chroot environment, so we need to start the service manually:
/usr/bin/urbackupsrv run --config /etc/default/urbackupsrv --no-consoletime
But instead of typing this out all the time, we can just create a script for this:
Copy this into the file:
#!/bin/sh /usr/bin/urbackupsrv run --config /etc/default/urbackupsrv --no-consoletime
Save and exit.
Add executable permissions:
chmod 755 /usr/local/bin/urbackupsrv-start
g. Start the service:
This will result in a log of the server starting up. CTRL-C will stop the service, so open up another SSH session.
To stop this service, you'll simply need to kill it:
h. Add cronjob.
Since we can't "enable" the UrBackup service the traditional way, we'll set a cron job to start at boot.
Add this job:
Save and exit.
i. Navigate to the web interface.
From a web browser, navigate to port 55414 on your server: http://YOUR_SERVER_IP:55414
And now you're up!
Step 3: Connect Clients
a. On the bottom right of your status screen, click "Add new client":
b. Select "Add new Internet client/client behind NAT" and enter your new client's name:
This should be the hostname of your new client.
c. Install client.
For Windows Clients:
Follow the "Download preconfigured client installer for Windows" link and install the client. Follow the instructions to install, and you're done.
For Linux Clients:
Take note of your "Default authentication key" at the top. You will need this.
Login to your client and run this installation script:
(Do NOT run the script provided by the server)
TF=$(mktemp) && wget "https://hndl.urbackup.org/Client/2.4.11/UrBackup%20Client%20Linux%202.4.11.sh" -O $TF && sudo sh $TF; rm -f $TF
During the installation, the script will ask you to select a snapshot mechanism. Enter "2" for "LVM - Logical Volume Manager snapshots":
Once installation is complete, ensure your client is running:
service urbackupclientbackend status
If it is not running, run:
service urbackupclientbackend start
Finally, connect your client to the server with the command:
urbackupclientctl set-settings \ -k internet_mode_enabled -v true \ -k internet_server -v "YOUR_SERVER_IP" \ -k internet_server_port -v "55415" \ -k computername -v "YOUR_CLIENT_NAME" \ -k internet_authkey -v "YOUR_DEFAULT_AUTHENTICATION_KEY"
d. Configure server:
Return to your web interface and you may find that your client is not online. Click Settings on the top navigation bar:
In Settings, Click on the Internet tab and ensure the following are set:
(You can uncheck "Do image backups over the internet" and "Do full file backups over the internet" if all of your clients are local.)
Scroll to the bottom and click Save.
e. Set backup directory:
Still in Settings, click Client settings. Check "Separate settings for this client" and set the directories you want backed up in "Default directories to backup" under File Backups. Multiple directories can be added with a semi-colon ";" in between.
You can also set your backup intervals while you're here.
Click Save at the bottom.
For Linux clients, this can also be set from the client's command line with:
urbackupclientctl add-backupdir -d FILE_PATH
Restart your server:
f. Log back into the web interface.
Your client should now be connected. You might see "No paths to backup configured" under "File backup status", but this is ok. This is what it will say until you've completed your first backup. Also note that, if you have connected a Linux client, image backups are not supported. However, you can simply run an image backup from your Linux client and set the directory of the backup images to be backed up by this server.
You can now run your first backup!
To Be Continued...
If you've already mounted your storage and you're happy with your setup, you're done! If you want to add some flexibility to your storage, continue to Part II! LVM allows you to add or remove storage without having to transfer data to another storage device; you can simply add the amount of storage you need, or simply remove unused storage you want to use elsewhere. Part II will mostly be an exercise in LVM (Logical Volume Management), and, although it isn't difficult, it's definitely a process.
Have more questions about UrBackup? Need help? Check out the complete Administration Manual. This is a fussy project, and every phone will have its own challenges, so feel free to leave your questions in the comments or browse the UrBackup community forums.
Updated 6/21/2021: Added "Security and Reliability Considerations"