Useful Tips | Don’t throw away your old phone, here’s a step-by-step guide to DIY a server[Copy link]
This article will show you how to use UrBackup and Linux Deploy to build a backup server on an old Android phone. The pollution problem of old phones is well known. I have an old phone. Although the shell has cracks and wear, the performance is still good, so I plan to reuse it.
Not that old (do you replace your computer every one or two years like you replace your phone?)
There are 4-8 processors and about 4GB of memory, and a built-in UPS. Just add an external hard drive and you can back up your entire home network!
Warning: This is just a project to try out what's possible. Since we're using Android, we had to jump through some hoops and are limited in many ways. This may not be the easiest way to back up your home network, or the best use of UrBackup. But once you have it set up and the server is running, you can easily manage backups for multiple machines and add storage.Here are some limitations:
The file system can only use EXT4. This is the only file system compatible with UrBackup and Android. Therefore, there is no file system level compression and other features.
It is not possible to call systemd directly from a chroot environment. We will install a simple startup script that starts the UrBackup service and stops it using pkill. In addition, we will add a cronjob to start the service at system boot.
UrBackup is primarily Windows-based. Although it offers full backup capabilities for Linux, the full image for Linux is still in beta. We're installing the stable version here, so our server can't support full image backups with Linux clients. However, you can create backup images on the client and then back up the directories containing those images. Finally, the UrBackup team is also working on Mac client support, but it's also in beta. For me, I don't have a Windows server and I don't want to back up my Windows laptop, so I only use UrBackup on my Linux servers.
Linux Deploy has limited support for distributions and versions. I tried Centos7, Ubuntu 18.04, and Debian 10, and only Debian 10 worked without errors. UrBackup also has the worst support for Debian (no other distributions have .deb packages for ARM64).
If you're going to try this with me, here's the action plan:
Root your phone. Please refer to the relevant documents for the specific steps, which will not be described here.
Install Linux Deploy and deploy Debian Buster.
Install the UrBackup server.
Connect the client.
Keep in mind that this tutorial uses a very specific configuration, much of it adapted to using Debian on Android in a chroot environment.
Root Android PhoneMy phone is a Pixel 4a (8-core CPU, 6GB RAM). The specific model of your phone shouldn't matter too much, but different models may experience different issues. If your phone was released within the last five years, you should be fine in terms of specs. I recommend at least a 4-core CPU and 2GB of RAM, which should be enough for most home networks, but you'll have to think about backup requirements. Also don't forget that the Android OS itself will take up some resources.If you plan to root your phone via Magisk, please note:
Make sure you use the correct boot.img file for your phone's current bootloader version.
If you are using Android 11 and the Magisk app is not working, downgrade to Android 10 and try again. I fiddled with Android 11 on my Pixel 4a for a whole day.
If you don't want to use Magisk, be very cautious with other tools. There are many other apps that may contain malware. CF-Auto-Root is also a good root tool, but make sure you download it from a safe source.
Linux Deploy ApplicationThe application can be run in a chroot environment on a Debian server.You can download the latest version from GitHub. The version in the app store is no longer maintained.BusyBox ApplicationThis application provides Unix utilities for Linux Deploy. There are several "Busy Box" applications available, but only this version is compatible with Linux Deploy.You can download the latest version from GitHub. The version in the app store is no longer maintained.Charging cableCharging cable for mobile phone.Connect to the server via SSH from another machineAlthough it is theoretically possible to install Termux or SSH apps on your phone to do this, it is definitely easier to do it through the keyboard.
Optional Equipment (Highly Recommended)
Although you can technically store your backups on an SD card, it is not recommended. SD cards are slower, less reliable, and cannot handle continuous writes for long periods of time. If you plan to back up to an SD card, expect it to fail within a year (or even a month if you have a lot of data).External HDD/SSD with USB cableSize and write speed are up to you, but I care more about reliability than storage and speed. Speed is important if you have a lot of storage (hundreds or even thousands of GB). In this case, write speed is critical so that you can complete the backup in a timely manner. For reliability, we have to consider the brand. With cheap drives, be prepared for I/O errors during the backup process.USB docking stationDepending on your phone, it may need to support micro USB or USB-C. The dock should have at least one USB port to connect to an external drive and a port for charging, but I recommend choosing one that comes with an Ethernet adapter. You can run the server over WiFi, but Ethernet is faster and more reliable.Ethernet cableIf you are running your server on Ethernet, you will need an Ethernet cable.
Step 1: Install Linux Deploy and deploy Debian Buster
1-1. After rooting your phone, open GitHub, download the .apk packages of Linux Deploy and BusyBox, and install these two applications.
1-2. After the installation is complete, open BusyBox. During the installation, record the installation location of BusyBox. In the figure below, BusyBox is installed to "/system/xbin". We will use this location later.
ArchitectureAll Android phones are AARCH64/ARM64. Make sure it says "arm64" (or "aarch64" for other distributions).Installation PathThe default is "${EXTERNAL_STORAGE}/linux.img". This is your SD card, and you can leave it as is (it will work on the Raspberry Pi). However, if the SD card is not inserted or is not formatted correctly, the installation will fail. I recommend installing to your internal storage. I'm assuming you won't be using the phone for anything else, as it needs to be plugged in at all times.Image size (MB)I recommend keeping at least 15 GB, but make sure you leave enough storage space for Android. This space will take up internal storage, so you may not end up with as much space as 50 GB.Initialize the systemIf not set to "sysv", cronjobs will not be run at boot time.MountIf you are not worried about future storage expansion, you can mount external block devices by simply adding their paths directly to the mount point. If you plan to expand storage in the future, you can consider logical partitions. The devices we load here can be directly accessed at boot time, but cannot be used for partitioning and formatting. However, keep in mind that the name of the block device (/dev/block/sdX) may change when you restart the phone, so you may need to check/update this configuration on reboot. If you are mounting a logical volume, the name will not change and does not need to be checked.How to find the path to an external block deviceOn Android, you can find block devices at "/dev/block/sdX" (not "/dev/sdX"). To determine which sdX device is the external block device, you need to run "lsblk" on the server where the device is plugged in. Then search for the various devices and see which one matches your device (in terms of storage capacity/existing partitions). If you plugged in the device after booting, it will probably be the last device.Note: After mounting a block device, you must unmount it or shut down the server before you can physically disconnect the block device. If you disconnect the block device without unmounting it, you will most likely lose all your data.1-4. Go back to the home page and open the menu in the upper left corner. Select "Settings" and scroll all the way down to "PATH variable". This is where you installed BusyBox. After setting the "PATH variable", select "Update ENV".
1-5. Return to the homepage and open the menu in the upper right corner. Click "Install". You will see a real-time log of the installation. When it is finished, the log will end with "deploy". Select "START" in the lower left corner of the screen. You will now have a Debian server running on your Android phone!
2-1. SSH to the newly deployed server.The IP address is the same as your phone, and the port is 22. You can log in using the credentials you set in steps 1-3. The rest of this tutorial assumes you are logged in as root. Open Linux Deploy and you can see your IP:
apt update && apt upgrade -y && apt install wget2-3. Download the .deb package of UrBackup.
wget https://hndl.urbackup.org/Server/2.4.13/urbackup-server_2.4.13_arm64.debThis is the latest stable version.2-4. Create a backup directory.In this example, I set the backup directory to "/mnt/backup". If you have mounted the storage, the directory has already been created; if not, create the directory:
mkdir -p /mnt/backup
Update permissions:
chownurbackup/mnt/backupchgrp urbackup /mnt/backupAllow UrBackup to write to this directory.2-5. Install the startup script.We cannot call systemd in the chroot environment, so we need to start the service manually:
/usr/bin/urbackupsrv run --config /etc/default/urbackupsrv --no-consoletimeTo avoid typing this command every time, we can create a script:
nano /usr/bin/urbackupsrv-starCopy it into the following file:
#!/bin/sh /usr/bin/urbackupsrv run --config /etc/default/urbackupsrv --no-consoletimeSave and exit.Add execute permissions:
chmod 755 /usr/bin/urbackupsrv-start2-6. Start the service.
urbackupsrv-startThis command will start logging to the server. You can stop the server by pressing CTRL-C, so you will need to open another SSH session.If you want to stop this service, just kill it:
pkill urbackup2-7. Add scheduled jobs.Since we can't "enable" the UrBackup service in the traditional way, we need to set up a cron job to start the service. In addition, if you disconnect the external block storage or restart the phone, the permissions of the backup directory may be restored. To ensure that these settings are preserved on reboot, we need to add a cron job.Open crontab:
crontab -eAdd a job:
@REBOOT chown urbackup [full/path/to/backup_directory] && chgrp urbackup [full/path/to/backup_directory] && urbackupsrv-startSave and exit.2-8. Open the web interface.Navigate to port 55414 of the server via a web browser:http://YOUR_SERVER_IP:55414
This is the hostname of the new client.3-3. Install the client.For Windows clients:Follow the instructions in Download preconfigured client installer for Windows to install the client.For Linux clients:Make a note of the "Default authentication key" at the top, you'll need it later.
Log in to the client and run this installation script:(Do not run scripts 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(Check for the latest client downloads.)During the installation, the script will ask you to select a snapshot mechanism. For "LVM - Logical Volume Manager snapshots", enter "2":
After the installation is complete, please confirm that the client is running normally:
service urbackupclientbackend statusIf the client is not running, run the following command:
service urbackupclientbackend startFinally, connect the client to the server using the following command:
urbackupclientctlset-settings\-kinternet_mode_enabled-vtrue\-kinternet_server-v"YOUR_SERVER_IP"\-kinternet_server_port-v"55415"\-kcomputername-v"YOUR_CLIENT_NAME"\-k internet_authkey -v "YOUR_DEFAULT_AUTHENTICATION_KEY"Please make sure that "YOUR_CLIENT_NAME" is the same as the hostname set in 3-2, and "YOUR_DEFAULT_AUTHENTICATION_KEY" is the key generated by the server earlier.3-4. Configure the server.Return to the web interface, you will find that the client is not online, click "Settings" on the top navigation bar:Click the Internet tab on the Settings page and check the following settings:
(If all clients are local, you can uncheck "Do image backups over the internet" and "Do full file backups over the internet.")Scroll to the bottom and click Save.3-5. Set the backup directory.On the "Settings" page, click "Client settings". Select "Separate settings for this client" and set the directories you want to back up in "Default directories to backup" under "File Backups". If you want to add multiple directories, you can separate them with a semicolon ";".
You can also set the backup interval here.At the bottom, click Save.For Linux clients, you can also set it from the client command line:
urbackupclientctl add-backupdir -d FILE_PATHRestart the server:
pkillurbackupurbackupsrv-start3-6. Log back into the web interface.At this point, the client is connected. The "File backup status" may show "No paths to backup configured", but it doesn't matter, it will show this before the first backup is completed.Also note that if you are connecting via a Linux client, image backups are not supported. However, you can run image backups via a Linux client and set the directory to which the backup image should be located.Next, you can try backing up!
Don't sell your old phone to buy a wash basin, learn about making your own server! https://en.eeworld.com/bbs/thread-1170616-1-1.html
Details
Published on 2021-10-20 00:35