108

I am running an android 4.0.3 device, and I want to extract the back up file created by :

adb backup -f ~/data.ab -noapk app.package.name

The above line works inside the CMD (windows) and I am able to get the data.ab file inside the '~' directory.

What I can't do is extact that file using CMD . I tried the below two methods.

dd if=data.ab bs=1 skip=24 | openssl zlib -d | tar -xvf -

dd if=data.ab bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" | tar -xvf -

I get the below error

error

I tried extracting it via CYGWIN, however, I failed too.

error

Where should I do the extraction ? In which directory should my command prompt be ? Any insights ?

Adis
  • 4,512
  • 2
  • 33
  • 40
tony9099
  • 4,567
  • 9
  • 44
  • 73
  • The commands are designed for Linux. The only reason that command didn't work in Cygwin is you don't have openssl installed in Cygwin. For anyone else reading with this exact problem... install openssl – user253751 Jul 04 '21 at 20:44

2 Answers2

132

As per https://android.stackexchange.com/a/78183/239063 you can run a one line command in Linux to add in an appropriate tar header to extract it.

( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 backup.ab ) |  tar xfvz -

Replace backup.ab with the path to your file.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
Puddler
  • 2,619
  • 2
  • 17
  • 26
  • 15
    Seemed to work, though it ended with `gzip: stdin: unexpected end of file` `tar: Child returned status 1` `tar: Error is not recoverable: exiting now` - assuming that's normal? – tobek Dec 27 '17 at 21:09
  • 10
    @tobek, yep, if you run the command as given it does complain, but produces the correct output. It is probably complaining because the backup.ab doesn't have the proper gzip file footer with CRC-32 checksum and length. – hft Feb 22 '18 at 03:46
  • 14
    Just a small annotation how to do it without Linux commandline. Open **backup.ab** with an HexEditor, and replace the first 24 Bytes (0x18) with `1F 8B 08 00 00 00 00 00` and save as **backup.tar.gz** . It can then be opened with WinRAR or any other extractor tool. – Daniel Marschall Oct 07 '18 at 01:22
  • 2
    Now working: `gzip: stdin: invalid compressed data--format violated tar: Child died with signal 13 tar: Error is not recoverable: exiting now ` – redanimalwar Oct 21 '19 at 21:45
  • 1
    I believe none of the answers without using Java will work on encrypted phones. See my answer here: https://android.stackexchange.com/a/224474/95893 and more importantly nelenkov's app (https://github.com/nelenkov/android-backup-extractor) and answer – alchemy Apr 28 '20 at 22:40
  • yes, so the README file linked below (is actually a link to the release file, but comes from nelenkov's GitHub project. There is a second question that is very similar: https://android.stackexchange.com/questions/23357/is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file – alchemy Apr 28 '20 at 22:52
75

I have had to unpack a .ab-file, too and found this post while looking for an answer. My suggested solution is Android Backup Extractor, a free Java tool for Windows, Linux and Mac OS.

Make sure to take a look at the README, if you encounter a problem. You might have to download further files, if your .ab-file is password-protected.

Usage:
java -jar abe.jar [-debug] [-useenv=yourenv] unpack <backup.ab> <backup.tar> [password]

Example:

Let's say, you've got a file test.ab, which is not password-protected, you're using Windows and want the resulting .tar-Archive to be called test.tar. Then your command should be:

java.exe -jar abe.jar unpack test.ab test.tar ""

mantal
  • 1,093
  • 1
  • 20
  • 38
finefoot
  • 9,914
  • 7
  • 59
  • 102
  • 7
    Just an FYI, for newbies trying to figure out how the above command works on Linux. `java -jar path/to/abe.jar unpack path_to/backup.ab path_for_generated/backup.tar ""` – sghosh968 Apr 16 '18 at 11:16
  • 1
    What's the likely problem if the unpacking operation succeeds and an apparently-valid tar file is created, only to be reported as "corrupt or password-protected" by `Ark`? It seems like the unpacking would fail if the backup was corrupt or password-protected. Just bizarre. – Tom Russell Jul 24 '18 at 05:40
  • 1
    When attempting to use `tar -xf` to extract the tar file generated by `abe`, the file is reported as "not a valid archive". Trouble, trouble, boil and bubble... – Tom Russell Jul 24 '18 at 05:48
  • 8
    Android backup Extractor's source code and official releases are on Github: https://github.com/nelenkov/android-backup-extractor/releases/latest. The SourceForge repository linked in this answer is repackaging an older version. – Syfer Polski Feb 06 '20 at 22:52
  • as a heads up, for me it was complaining that my encrypted extraction has an end of file unexpected error and winrar kept telling me the tar file was corrupt. It's possible some or maybe many files were, but not all and I was able to get the ones I needed completely intact. – user99999991 Jun 03 '21 at 05:24
  • @SyferPolski Per https://sourceforge.net/projects/android-backup-processor/files/README.TXT, the project on SourceForge is now a fork of the one on GitHub. – Chih-Hsuan Yen Sep 19 '21 at 05:57
  • 1
    They have Replaced android-backup-extractor with android-backup-processor but the command is still the same – Saleh Dec 23 '21 at 19:14
  • Used the latest abe.jar from github as mentined by @SyferPolski and the command from sghosh968 worked for me on fedora36. If the backup is passowrd protected it will prompt you to enter the password you used during the backup. – chamalabey Nov 15 '22 at 00:45