Android Backup with adb (Android Debug Bridge, Ubuntu)

This guide was tested with Ubuntu 16.04 and 18.04

Installation of required tools

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

@see https://lyubomyr-shaydariv.github.io/posts/2016-08-27-when-android-backup-and-restore-tools-may-fail/

try backup with -nocompress

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