Adb backup does not work
Solution 1
Rather than trying to find an old version of adb, it's easier to add quotes to the arguments to adb backup :
adb backup "-apk -shared -all -f C:\Users\NAME\backup.ab"
Solution 2
The line, which correctly invokes adb
, needs to look like this at my side:
adb backup "-apk -obb -shared -all -system" -f phone-20180522-120000.adb
This line is for Linux, but should do for Windows and OS-X as well. For Linux (and probably OS-X), you can use a script like following, which automatically assigns a timestamp to the file:
adb backup "-apk -obb -shared -all -system" -f "${PHONE:-phone}-`date +%Y%m%d-%H%M%S`.adb`"
Important After doing a backup, verify your data! At my side, sometimes some corruption of the file shows up (and I doubt it is my computer, as I only observe such errors with
adb
).Here is a
check
instruction I use:set -o pipefail for a in *.adb; do echo "$a"; dd if="$a" bs=24 skip=1 | zlib-flate -uncompress | tar tf - >/dev/null; echo "ret=$?"; done
It should show
ret=0
, but it doen't.
- If you see
inflate: data: invalid code lengths set
your archive is corrupted and - very likely - unusable for restore!- If you see
tar: Unexpected EOF in archive
your backup probably is usable (all backups end this way, I do not know why).- Even if you see just
ret=0
there might be undiscovered errors which still prevent a restore.- There is definitively missing an
adb verify
command, to verify correctness of a backup!
FYI
I post this update, as all other answers were helpful, but not exact to the last detail. (When used with full quotes, a backup was done, but called backup.ab
)
Here is my environment:
- OS: Ubuntu 16.04
- Phone: Android 7.0
- ADB: 1.0.32
The full procedure was (just in case somebody stumbles upon this not knowing what is needed):
- Zeroth: Install
adb
(on Ubuntu:sudo apt-get install android-tools-adb
) - First: Enable USB debugging mode on the phone.
- Second: Attach phone to USB of the computer with an USB data cable (a charge only cable is not enough)
- Note that the Ubuntu Phone Manager might show up and ask you for the phone's PIN. You do not need that, close this if it happens.
- Third: run
adb devices
- you should see something likeXXXXXXXXXXXX unauthorized
- After some time on your phone a message shows up which asks for USB debugging permission
- Allow this once. For security reasons, you should not automatically trust the computer, as the fingerprint can be easily faked.
- Note that if something is obstructing a single pixel of this confirmation window (like some accessibility feature button) you cannot tap on the
OK
. First move the obstructing window.
- Forth: Now again run
adb devices
- you should see something likeXXXXXXXXXXXX device
- If more than one line shows up, you attached more than one phone to the computer. The easy way is to unplug all those you do not want to backup. (The complex way is to set the environment variable
ANDROID_SERIAL=XXXXXXXXXXXX
.)
- If more than one line shows up, you attached more than one phone to the computer. The easy way is to unplug all those you do not want to backup. (The complex way is to set the environment variable
Now run adb backup
as shown above. Change the file to your needs.
- This brings up a window which asks for backup permission.
- Do not close the backup window while the backup is taken. When I tried this, the backup stopped and the resulting archive was broken.
- You can give a password to encrypt your backup. I do not have any information on how secure the password is. But it is very likely, that you cannot restore the backup taken in case you ever forget this password.
- I have no idea on how to restore such a backup to other phones. I even never tried the restore, so I cannot help here, too.
Notes:
-
adb help
shows all possible options toadb backup
- Close all open applications on your phone before the backup. I do not know if this is needed, but it certainly cannot hurt.
- Leave the phone alone while the backup runs. I do not know if this is needed, but it certainly cannot hurt.
- Do not be impatient. Leave the backup plenty of time. At my side I see a progress of about 100 MB/Minute (YMMV). So the backup takes about half an hour for my phone (2.5 GB).
Apparently adb backup
does not completely backup everything!
I had a look into the backup (cd X && dd if=../XXXX.adb bs=24 skip=1 | zlib-flate -uncompress | tar xf -
) and did not find all installed applications.
What I was able to find was (note that this list is incomplete):
- Internal emulated SD-Card:
shared/0
- External SD-Card:
shared/1
- Apps:
apps/
- many apps (like Google Authenticator) were missing - Calendar:
apps/com.android.providers.calendar/db/calendar.db
(probably)
What I was not able to find (note that this list is incomplete):
- Alarms. (I was probably not able to detect the right app)
- Full external SD-card (there is more on this card than what is shown below
share/1
. For example the apps, which are moved-to-SD.)
Conclusions:
- Sometimes
adb backup
might create corrupt backups, which can go unnoticed. So either check your backup or do frequent backups and pretend to be lucky enough such that not all backups go corrupt. - With
adb backup
you get a backup of most of your precious data, like camera images and so on. It might be a bit difficult to unpack it, though. -
adb backup
is not enough to do a complete backup of your phone. -
adb backup
is not enough to backup your SD-card such, that if it breaks, you are able to replace it by a new one with the contents restored. This is very sad!
PS: The typo "Forth" is not an accidental one.
PPS: zlib-flate
can be found in package qpdf
on Ubuntu 18.04
Solution 3
This just worked using Ubuntu 15.10 ("wily") to backup a Galaxy SM-G900V running Android version 6.0.1.
Installed using:
sudo apt-get install android-tools-adb
Then I ran the following from the command line (without 'sudo'):
adb backup -apk -shared -all -f backup.adb
Result:
user@hostname:~/droid$ ls -lah
total 1.2GB
drwxrwxr-x 2 user user 4.0BK Mar 6 18:43 .
drwxr-xr-x 52 user user 4.0KB Mar 6 17:40 ..
-rw-r----- 1 user user 1.2GB Mar 6 18:29 backup.ab
Thank you "NG". I was beginning to think my phone was borked.
Forgot to add: Running adb version: Android Debug Bridge version 1.0.31
Solution 4
The problem is the adb version of your PC. Using adb version 1.0.31 the backup/restore will be sucessfull.
More info on: https://android.stackexchange.com/questions/83080/adb-backup-creates-0-byte-file-prompts-for-current-backup-password-even-though and How to downgrade my SDK Version?
If your device has an adb version prior to 1.0.31, then you must use an adb version of 1.0.31 on PC. Versions of adb 1.0.32+ broken the backwards compatibility. Source: Issue 208337
Solution 5
Seem not all apps can be backed up. Android apparently allow apps to disable backup :(
https://developer.android.com/guide/topics/manifest/application-element.html (search for allowbackup)
Admin
Updated on June 12, 2021Comments
-
Admin almost 3 years
I need help from you guys, because I don't know what I did wrong with adb backup.
I want to backup my Samsung Galaxy S3 LTE (GT-I9305) without root. I googled it and found Full Android Backup with SDK Manager. I installed all i need for this like Java Development Kit 8 version 66 (JDK 8u66 x64) and Android Studio which contains SDK Manager. Then they sad i should download the Google USB Driver. I downloaded it but nothing happened. I thought it should work now and then I went to C:\Users\MYNAME\AppData\Local\Android\sdk\platform-tools and left-clicked adb whilst holding Shift. Then I clicked "Open command window here". After this I typed in "adb devices" and it said:
List of devices attached
3204cfaaf8611199 device
Then I typed in:
adb backup -apk -shared -all -f C:\Users\NAME\backup.ab
It said
Now unlock your device and confirm the backup operation.
I did this and my Smartphone opened "Full Backup" and then I was able to set a password for the backup. I don`t need a password and I just clicked "Back up my data" Then it went back to my homescreen and said "Starting backup..." as a toast message and immediately after this it said "Backup finished" and created a backup file with 40 bytes. I don't know what I should do now.
-
Anwar over 7 yearsI'm using 1.0.32 and the problem still here
-
Charles Roberto Canato over 7 yearsImpressive, right on spot! However, I must add that, contrary to the OP's problem, my smartphone never showed the Full Backup app, but ADB always gave the same result.
-
Admin over 7 yearsyou need to use double quotes
adb backup "-apk -shared -all -f C:\Users\NAME\backup.ab"
-
NG. over 7 years@JMRouet Thanks - single quotes work fine on a Mac. Sounds like you need double quotes on Windows.
-
Alan CN about 7 yearsLet me explain better. If your device has an adb version prior to 1.0.31, then you must use an adb version of 1.0.31 on PC. Versions of adb 1.0.32+ broken the backwards compatibility. Source: Issue 208337
-
James Nelson almost 7 yearsThis is the correct answer, why is it not first? Thanks @NG. works with single quotes on Ubuntu.
-
Paul almost 7 yearsThis advice doesn't work in May 2017 with ADB v 1.0.39
-
kaicarno over 6 yearsElaborating on the Linux answer. 'sudo apt-get install adb' works. The -f flag above needs to be present (-f <filename>.adb). As well as minimium one flag for specifying what to back up. If not you'll see error: Segmentation fault.
-
Tom Russell almost 6 yearsI just entered your command and backup finally started after hours of trying other things!
-
Tom Russell almost 6 yearsThe
tar -xf <backup.tar>
reports "this doesn't look like a valid archive". Now how could the extraction succeed and yet produce an invalid tarfile? Isn't that weird? -
Tom Russell almost 6 yearskaicarno: missing only the -f flag "succeeds" with a resulting 0-byte backup. So, in essence fails silently while even producing an output file with the default name "backup.ab", which is a bit confusing to say the least.
-
Tino almost 6 years@TomRussell try
dd if=backup.tar bs=24 skip=1 | zlib-flate -uncompress | tar xf -
You can findzlib-flate
in packageqpdf
(Ubuntu 18.04). Edited my answer accordingly -
Tom Russell almost 6 yearsThanks. I wouldn't have found
flate
for openSuse without knowing to installqpdf
. I get the following when I run your command: "flate: inflate: data: incorrect header check. tar: This does not look like a tar archive. Exiting..." -
Tom Russell almost 6 yearsBTW, I just gave
adb-sync
a whirl. It also doesn't work in the most beautifully-incomprehensible way I think I've ever seen! -
MagTun over 5 yearsUpdating to the latest version of adb worked for me. No need for the quotes
-
Jeinzi over 5 yearsI tried to backup several apps and was facing the same problem, getting only 40 Byte files on my Arch Linux machine. Version 1.0.31 did it for me, see docs.j7k6.org/android-adb-backup-41-bytes-549-bytes-bug-fix
-
Ender about 5 yearsAll I need is this answer, it tells me a reason why the normal does not work. tks
-
Gert van den Berg about 5 yearsThis works for me, but contains no explanation why... (Is it a bug? Is so why does this workaround work?)
-
binki over 3 yearsI found I had to put the
-f
option outside of the quotes to get it to work. Upvoting the different answer which specifies this. -
Michael Tolsma over 3 yearsDoesn't work for me. Still creates a 40b file. I'm on an older version of android though.