Simplifying data backup on Android devices

Backup Assistant

© Photo by Jandira Sonnendeck on Unsplash

© Photo by Jandira Sonnendeck on Unsplash

Article from Issue 264/2022
Author(s):

Linux Android Backup offers an open source solution to backing up the most important content from your Android devices in just a few steps.

Backing up data from a Linux installation doesn't pose a problem for most users thanks to open source solutions for almost every scenario, from a single machine to a cluster, as well as command line and GUI options. However, backing up Android devices such as smartphones or tablets can be a little trickier. Up until Android 4, backing up such devices was only possible if the bootloader was unlocked, and unlocking was no easy task because most manufacturers tried to prevent it. And if you did unlock the bootloader, you could void your warranty, and, even worse, risk bricking your device. An advance backup would have made sense, but it was only possible after rooting.

Starting with Android 4, adb backup [1] (which Google has since deprecated for security reasons) worked reliably without rooting, even between devices by different manufacturers, which differed from many other manufacturer tools or third-party apps. Today, the only official tool left for backups is Android Debug Bridge (ADB), which lets you control Android devices using a computer with Linux, macOS, or Windows. However, using ADB requires many manual steps and still comes with the risk of bricking the device.

Linux Android Backup (LAB), a fledgling project developed on GitHub, offers an alternative to ADB [2]. Under the hood, LAB, which consists of a small shell script and a Flutter app, greatly simplifies backing up Android devices. LAB works entirely without vendor lock-in or closed source software that could compromise your data. While the script is based on ADB, it does not use the deprecated adb backup command. Despite its name, LAB also works on macOS and Windows, in the Windows Subsystem for Linux (WSL) [3]. In fact, the developers are currently looking for a more suitable name.

Keeping It Simple

LAB aims to keep the backup process for Android devices to just a few steps with minimal interaction with the user. To take advantage of this simplification, you will need to prepare your device up front. However, once you launch the script, LAB requires virtually no intervention. LAB currently backs up installed apps (in APK file format [4]), photos, videos, and other downloads on your device. In contrast to the manual procedure via ADB, LAB also backs up saved contacts in vCard format by installing a small open source helper app. You can submit suggestions for further data to be backed up as an issue on GitHub [2].

The backed up data can be accessed as encrypted archives compressed to the max by 7-Zip; these archives remain accessible even if the script stops working. For this, you will need to install the p7zip-full, adb, curl, and bc packages on your computer. Listing 1 shows the commands for doing this on Debian and Fedora.

Listing 1

Installing Dependencies

### Debian
$ sudo apt update && sudo apt install p7zip-full adb curl bc
### Fedora
$ dnf update && dnf install p7zip p7zip-plugins adb curl bc

Developer Mode

On your Android device, you now need to unlock developer mode. To do this, go to About the phone at the very bottom of the settings, tap the Build number entry seven times (Figure 1), and then enter your PIN when prompted. The You are now a developer message flashes up briefly on the display. To copy data between the Android device and your computer or laptop, you also need to enable USB debugging (Figure 2). You will find this option hidden in the settings below System & Updates | Developer options. When done, your Android device is ready for backup.

Figure 1: You must unlock developer mode on your Android device before you can exchange data between the device and your computer.
Figure 2: The USB Debugging function can be hidden in various places in your Android device's settings. If you don't find it here, search the Internet with your device name to determine the exact location of this option.

On the PC or laptop where you plan to save your device's backup files, first download LAB [5], unpack the archive, and change to the unpacked directory at the command line. Make sure that your Android device is properly connected to the computer. A prompt then pops up on the connected Android device, asking you whether you want to load or copy data. Select Copy. After pressing Enter the connected device should be detected and tagged as device. If this doesn't happen, press Ctrl+C to cancel the script, check the connection, and restart the script (Figure 3).

Figure 3: After starting the script, the Android device is first detected and tagged as device. If this does not work, make sure your device is properly connected.

Once your device is successfully detected, you will then see the two operating modes: Backup and Restore (Backup will be selected by default). By pressing Enter, you will install the helper app for backing up your contacts from the Android device. The script output (Figure 4) suggests the app has been opened on the smartphone, but this was not true in my test. After manually opening the Linux Android Backup app on your device, you will see an Export Data button, which lets you copy your contacts.

Figure 4: After confirming the backup, the helper app downloads and installs if it is not already present.

Next, you need to specify the directory where you want LAB to copy the backup data. For the current directory, simply press Enter and the data backup from Android to Linux now begins. Depending on the volume of data to be copied, this can take a few minutes. You can follow the progress in detail on the screen. In my first test with a Huawei Mate 20 Pro, transferring over 16,000 files with a total size of around 18GB took about eight minutes.

Finally, you need to set a password for the encrypted archive; afterward, LAB will create the encrypted archive within a few minutes. The entire process including downloading the app and configuration took about 30 minutes in my test. If successful, LAB will tell you Everything is Ok (Figure 5). The resulting archive from the Huawei Mate 20 Pro was 13GB. Make sure you save your password; without it you will not be able to access your data again. Don't forget to revert the settings you configured for USB Debugging and Developer Mode, as they give more rights than you need in everyday use.

Figure 5: The Everything is Ok message tells you that the backup process is complete. Keep the assigned password safe for possible recovery.

I also repeated this procedure with the new Murena One [6] smartphone, which uses /e/OS as its operating system. /e/OS is based on LineageOS [7], an Android custom ROM based on the Android Open Source Project (AOSP) [8]. I wanted to ensure that LAB also works with custom ROMs. Unlocking developer mode on the Murena One was the same as on the Huawei, but USB debugging was named Android-Debugging on the Murena One and resided in System | Advanced | Developer Options. Again, if you do not find the setting as described here, your best bet is to search the Internet for the specifics for your device.

Restore

Restoring data works the same way as backing up data. However, after the device is detected, do not use the default Backup option. Instead select Restore using the down arrow (Figure 6). First, the helper app should open on the Android device; this did not work on the Murena One either. Instead, I had to open the app manually and this time press Auto-restore contacts. After doing so, I only needed to specify the backup archive's location. You could also insert the archive into the script running in the terminal window using drag and drop. After pressing the Enter key, LAB asked for the password and then opened the archive. The data was then restored automatically (Figure 7).

Figure 6: Restore works in the same way as backup, except that you select Restore.
Figure 7: On the Murena One test device, only 27MB needed to be restored, and the process was impressively fast. The Data restored message indicates that the action has completed successfully.

I also tried out this process on a Google Pixel 3a running GrapheneOS, but the device was not recognized, which is probably due to the security features of this distribution. Upon closer inspection, I found that GrapheneOS comes with its own backup app named SeedVault. Even after disabling SeedVault, the Pixel 3a could not be backed up using LAB.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus