Android Backup with adb (Android Debug Bridge, Ubuntu)
This guide was tested with Ubuntu 16.04 and 18.04
Installation of required tools
- Install adb: https://www.ullright.org/ullWiki/show/android-adb-installation-ubuntu
- Got to your personal home directory (e.g. /home/klemens, "~" is a shortcut for that) and create a directory named "bin"
- mkdir ~/bin
- Download android-backup-toolkit from https://sourceforge.net/p/android-backup-toolkit/ and extract it to ~/bin/android-backup-toolkit
- android-backup-toolkit requires the "star" utilty, it is deliverd with the package. Install:
- sudo dpkg -i ~/bin/android-backup-tookit/star-bin/star-ubuntu-lucid/star_1.5final-2ubuntu2_amd64.deb
Actual Backup
Note that "adb backup" creates "backup.ab" file in the current working directory. So create a separate directory for each of your backups to avoid overwriting "backup.ab" accidentally.
- Open a terminal.
- Create a separate directory, example:
- mkdir android_adb_backup_2020-03-03
- cd android_adb_backup_2020-03-03
I recommend to exclude the internal storage ("-shared" option). Better backup the internal storage by copying the files.
- adb backup -apk -all
Or create a full backup (all apps, settings and internal storage):
Warning: the filesize can get very big. I recommend to backup the internal storage by copying the files in explorer.
- adb backup -apk -all -shared
Or backup a single app:
- adb shell 'pm list packages'
-
... package: com.vendor.appname ...
-
- adb backup -noapk com.vendor.appname
Note: there is some confusion if, and what kind of quotes are needed for the adb backup options (adb backup "-apk -all" ?)
Important note
adb backup is buggy!
* "backup-apk-all.ab.tar" archive is corrupt.
* TIP: probably this is caused by a bug in android, which generates an invalid backup or crashes during the process.
* TIP: Google has been notified several times about buggy backup service, but refuses to fix it.
* TIP: Run 'adb logcat -s BackupManagerService' on another terminal before and while making the backup to detect the error.
Check for E in fifth column
try backup with -nocompress
Get APK from device
Example for app "Locus Maps"
- adb shell pm list packages -f -3 | grep locus
- package:/data/app/menion.android.locus.pro.asamm-svK6V4X5LdghyKHV7nqG1g==/base.apk=menion.android.locus.pro.asamm
- The path is:
- /data/app/menion.android.locus.pro.asamm-svK6V4X5LdghyKHV7nqG1g==/base.apk
- adb pull /data/app/menion.android.locus.pro.asamm-svK6V4X5LdghyKHV7nqG1g==/base.apk locus.apk
- Get also the data
- adb backup -noapk menion.android.locus.pro.asamm
- mv backup.ab nextcloud.ab
Restore
Theoretically you could simply restore a complete backup (adb backup "-apk -all -shared") but I don't think it would make sense in many cases.
I like to select specific apps to restore. That is easy when you backed up only one app with "adb backup -noapk com.vendor.appname":
-
adb restore backup.ab
But this is quite tedious. The best way I found is the following:
Best Practice
- Create a full backup without shared ("adb backup "-apk -all")
- adb backup "-apk -all"
- Split the backup with android-backup-toolkit:
- cp ~/bin/android-backup-tookit/abe.jar .
- cp ~/bin/android-backup-tookit/tar-bin-split.jar .
- ~/bin/android-backup-tookit/adb-split-no-extraction.sh backup.ab
- Now there is a separate .ab backup file for each app in split-ab/ directory.
- ls -l split-ab/
- Restore the apps of your choice with
- adb restore split-ab/com.vendor.appname