To backup data of an Android application, you will need to connect your Android device to a Linux PC using a USB cable. Once connected you will need “Android Debug Bridge” or “adb” command line utility to interact with your phone.
To install ADB in Ubuntu, use the command specified below:
You can install ADB in other Linux distributions from the package manager. You can also download executable binaries for ADB from here.
Enable USB Debugging on Your Phone
To interact with your Android device using the “adb” command on your Linux PC, you will need to enable USB debugging on your Android device first.
To enable USB debugging, you will have to enable the “Developer options” menu on your Android device. This can be done by going to the “Settings > About phone” menu on your Android device and tapping on “Build number” around seven times. Depending on your Android device, the location of the “Build number” option can be different. You can use the search bar in system settings to find it quickly.
After you tap seven times on “Build number”, a new entry called “Developer options” should be available in the system settings of your Android device. Go to “Developer options” and enable “USB debugging”, as shown in the screenshot below:
Authenticate ADB Connection
Connect your Android device to Linux PC through a USB cable. Run the command below to initiate authorization:
You should get a prompt similar to this on your Android device:
Click on the “Allow” option to authenticate your Android device. You can also check the “Always allow from this computer” option to automatically authenticate your Android device on subsequent connections.
After a successful connection, you should see some output in the terminal showing the serial number of your Android device.
If you see an “unauthorized” string instead of “device” in front of the serial number, something went wrong and your device could not be authenticated. To retry, unplug the USB cable, reconnect your Android device to your Linux PC and repeat the authentication steps listed above.
Get Package ID
Now that your Android device is connected to your Linux PC and authenticated with ADB, you are ready to take application backup. But to do so, you will first need the package ID for the application you want to backup.
You can find the package ID using two ways. The first method involves visiting the Play Store listing for your desired application. You will find package ID after “id=” characters, as highlighted in yellow below. You can also get link for a listing from the Play Store app itself by searching for the application and using the “share” feature to copy the link to the clipboard.
In the second method, you can use an adb command to get package names and their IDs. Run the command below to do so.
You will get some output like this:
The left hand side in each line in the output will give you a hint about the application name, while the right hand side (after “=” symbol) will give you package ID. You can also make use of the “grep” command to quickly find your desired package ID.
Run Backup Command
Now that your Android device is connected to your Linux PC, authenticated to an ADB connection and you have a package ID, you are ready to take application backup. To do so, run a command in the following format:
For instance, to backup VLC player on Android, you will need to run the following command:
You can remove the “-apk” switch if you don’t want to backup the “.apk” package file for your desired app.
On newer Android versions, you may be asked to encrypt backup using a password. When prompted, enter a password for the backup.
Wait for the backup process to finish. You should now have a “backup.ab” file containing data backup. You can also supply a custom name for the backup file using the “-f” switch.
While the process mentioned above should work with most third party Android applications, certain Android apps, especially pre-installed system apps, do not allow taking backups of application data through the “adb” command. The backup process doesn’t give any warning that backups are disabled in such cases. If the backup file is extremely small (less than 1KB), your application data may not have been backed up correctly as backups may be disabled for it.
Restore the Backup
You can restore a “.ab” backup file on your Android device using the command below:
Replace “backup.ab” name as required. Keep in mind that restoring backups may not work if the application doesn’t support taking backups through ADB in the first place.
Explore Contents of the Backup
You can explore the contents of a “.ab” file using a utility called “Android Backup Extractor”. You can download it from here. Once downloaded, you should have a “abe.jar” file on your system.
To use it in Linux, you will need to have Java installed on your system. You can install Java in Ubuntu using the command below:
You can install Java in other Linux distributions by searching for the term “OpenJDK runtime” in the package manager.
To extract a “.ab” backup file to a “backup.tar” extractable archive, run a command in the following format:
Replace the file names as needed. In the last part of the command, supply the password in plain text. Here is an example of the command:
You can now freely explore the “.tar” file and extract the data to browse the backup files.
You can backup application data through the “adb” command as long as the application allows it. It is the most reliable way available today to backup and restore application data in Android, though Google has been imposing some restrictions on data backups with each iteration of a new Android version.