11

I have non-rooted Android 7.0 device (NVIDIA Shield Tablet) which was previously backed up with

adb backup -apk -shared -all -nosystem -f mybackup.ab

But restoring it with

adb restore mybackup.ab

results in that /Android/data, etc are restored, but the applications are not installed from apk files, no errors.

I've had to extract apk files from mybackup.ab and install them manually in batch with adb install <...>.apk. After that everything was fine.

I'm quite sure that I've previously had similar problem with 6.0. and Helium/Carbon before but thought that it was specific to backup method I've chosen.

What is the problem with adb restore? Is it because the device is non-rooted? Why does adb install work as expected then?

Estus Flask
  • 161
  • 1
  • 1
  • 5

3 Answers3

5

I've adapted niels' script a little to fix some issues with it:

#!/bin/bash

set -e

if [ $# -ne 1 ]; then echo "Usage: $0 <package-name>" exit 1 fi

echo -n "Enter password: " read -s password echo

java -jar abe.jar unpack $1 $1.tar "$password" tar -xf $1.tar --wildcards '/base.apk' rm $1.tar for apk in apps/*/a/base.apk; do adb install "$apk" || true done

adb restore $1

echo "Ready"

Just download the latest abe.jar from https://github.com/nelenkov/android-backup-extractor/releases and run the script with your backup file as an argument. The script requires java to be installed.

felschr
  • 51
  • 1
  • 3
4

I solved it with the following script

#!/bin/bash
killall adb > /dev/null 2>&1
set -e

if [ $# -ne 1 ]; then
  echo "Usage: $0 <package-name-without-ab>"
  exit 1
fi

export PATH=/opt/jdk1.8.0_152_jce/jre/bin:$PATH
ab=$1.ab
java -jar /opt/android-backup-extractor-20160710-bin/abe.jar unpack $ab $ab.tar apw; tar -xf $ab.tar --wildcards '*.apk' --strip-components=3
mv base.apk $ab.apk
rm $ab.tar
adb install $ab.apk

adb restore $ab

echo "Ready"

You need furthermore the android-backup-extractor. How ever in my experience adb backup is still not really safe. First of all some apps can set a flag, so they won't be backup. And the restore works only sometimes and not sure, for example if you change the device. It's a shame that in 2018 only Titanium Backup make good job, if you have a rooted phone.

niels
  • 141
  • 2
2

Command adb restore are not install .apk back. Actually, this command is only write back system and data files. -Android dev site

If you want automate apps installation process:

  1. Add all extracted .apk to one folder
  2. Type for %f in (C:\_apk folder location_\*.apk) do adb install "%f" NOTE: If you have .apk files which have "spaces" in their names adb has not recognize spaces rewrite it with _ or whatever else.
MaTT Belis
  • 63
  • 1
  • 1
  • 7
  • Can you please specify the reference for this information if it's correct? Since adb backup backs up everything including apks, I would expect that adb restore does the opposite thing. Because otherwise it appears that apks just waste space in .ab file. – Estus Flask Jun 20 '17 at 14:53
  • In table 1.> Backup and Restore Commands on android dev site is adb restore command describe as "Restore the device contents from file" it is interpret for me as uncompress files and put in device only, not installation packages. it make sense, i think, for installation was define command adb install (its not necessarily have install funkcionality in other commands) but i agree it would be nice :) – MaTT Belis Jun 21 '17 at 07:14
  • @MaTTBelis "Restore contents from file" to me means restore everything the file holds (which includes installing the APK if it's there). And until MM it did exactly that (I'm using this since Android 4, when it was introduced). Problems started only with Android 7, where a bug seems to prevent installing the APK. On some devices, you find in logcat that it tries exactly that (but fails without saying so). Actually, for those devices Nils' answer works. – Izzy Oct 04 '18 at 11:44