Adb backup does not work - android

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.

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"

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 like XXXXXXXXXXXX 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 like XXXXXXXXXXXX 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.)
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 to adb 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

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

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)

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

Just incase anyone is still having trouble - In windows, I found putting the quotes around only the directory, for example "C:\Users\NAME\backup.ab" worked.

I found this solution :
adb backup -apk -shared -all -f "<path-where-the-backup-will-be-created>.ab"
And to restore :
adb restore "<path-where-the-backup-is>.ab"

Related

Apk is disappearing after moving to system parition

I'm trying to install my apk on system partition. I've rooted device and here are the steps I'm following,
adb install -d -r <apk_name>
Now apk gets installed in /data/app/<apk_name>/
Move all contents present from /data/app/<apk_name> to /system/priv-app/<apk_name>
Clear the contents within /data/app/<apk_name> and reboot the device
Post reboot not able to find my apk under adb shell pm list packages | grep <apk_name>
I'm trying to read and write value to secure setting which is asking my app to be in system partition. When I'm trying to move I'm facing this issue. I could not find something suspicious from logs while installing the apk.
Tried all possible solutions listed here (Android 5.0/Lollipop: Force rescan of /system/priv-app) but none didn't help.
Any help to debug this issue would be really helpful.

aggressive adware irremovable apk on android

A few days ago I received complaints from several customers who told me that "adware is installed automatically on your device Krono NET K5". I made invesigar and found a few apk on / system / app that had different permissions to the usual "rw-r - r--". I could erase the few simple steps in a shell:
adb shell "su -c 'mount -o rw, remount /'"
adb shell "su -c 'rm /system/app/156.apk'"
adb shell "su -c 'rm /system/app/Launcher0607wxDjbOa.apk'"
adb shell "su -c 'rm /system/app/Sync.apk'"
adb shell "su -c 'rm /system/app/SettingProvider.apk'"
(Note that a suspect name as there is a apk using the system call SettingsProvider.apk with letter s)
So far everything worked properly, however there is a apk which is the main cause of all adware and causing the discharge cone apk other battery savers, system cleaners, among others. This application is:
"/system/app/providerdown.apk" Permits "rwsr-sr-x"
I tried to remove it by the above method, I tried to change the permissions to remove it and it has not worked. I tried to install a recovery to eliminate apk thence Aroma File Manager (CWM, TWRP) MTK but this device does not support any custom recovery for devices MTK.
Any idea? Thanks in advance (sorry for my bad english)
I have same problem. You will have to be rooted for this, but i guess you have root because of that code you wrote, and the fact that app somehow gains root access and installs itself in system. Only thing I did to make things easier is:
Download Avast to your phone.
Download Clean Master to your phone and with Clean master make backup of your avast apk.
Go to your stock recovery. I used an app from google store to boot to recovery but any way is good.
Clean cache and do a factory reset.
Boot the device.
DO NOT CONNECT DEVICE TO ANY NETWORK.
Just skip all the stuff like login to your google account and other settings.
Find your Avast apk in the sd card and install it.
Turn on firewall and block all acces to TimeService-that is the name that apk uses when seen from android system.
Go to android system and disable time service. It is probably version 1.1.6
You will still have malware in your device but it wont make mess anymore.
I would like the permanent solution too.

Android Studio pm install aborted

Im trying to run an application on my GS5 from android studio and Im getting this:
Waiting for device.
Target device: samsung-sm_g900v-f3af9744
Uploading file
local path: D:\Android\Projects\TestProject\build\outputs\apk\TestProject-debug.apk
remote path: /data/local/tmp/com.brian.testproject
Installing com.datascan.mobilescripts
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.brian.testproject"
Aborted
It seems to be copying the file to the device, I can see it in the /data/local/tmp directory. Its just failing at the "pm install" stage.
On the phone I turned on USB Debugging and authorized the computer. Here is what I get when I run ADB devices:
D:\Android\sdk\platform-tools>adb devices
List of devices attached
f3af9744 device
So that seems to be correct. Im not really sure what the problem is. Google search on the problem didnt give me any relevant results.
Does anyone know how to get more information beyond "Aborted"? Any help is appreciated, Thanks!
EDIT:
As suggested by #AlexP. I ran "adb logcat -d -s PackageManager:*", this was the result:
D:\Android\sdk\platform-tools>adb logcat -d -s PackageManager:*
--------- beginning of main
--------- beginning of system
Not much help, but I did decide to watch the logcat as the pm install was being run and I found this error entry:
Tag=appproc | Text= ERROR: Could not find class 'com.android.commands.pm.Pm'
Tag=art | Text= art.runtime/thread.cc:1105] No pending exeption expected: java.lang.ClassNotFoundException: Didn't find class "com.android.commands.pm.Pm" on path: DexPathList[[zip file "/system/framework/pm.jar"],nativeLibraryDirectories=]/vendor/lib, /system/lib]]
Followed by a whole slew of art error entries.
So it seems as though my phone is missing something, maybe?
The reason that Android Studio fails on Galaxy S5 is because the adbd (ADB service on the phone not your PC), on rooted version of this phone does not run as root, which is a security measure. You can verify this by manually trying to execute the Android Studio apk and execute commands on the device and finding out that they are failing to execute, but retrying them using "su ..." and see that the app installs and starts on the device. There are three options to resolve this and unblock Android Studio:
Options:
Flash a ROM that includes the modification - not desired as from my understanding you would like to stay on the stock image; also a good security measure not to have adbd running as root all the time. Older roms fall in this category as well, but then you are missing Stock Rom updates and security patches.
Create a custom boot.img and flash it to your phone - this is basically a custom kernel and not desired for a similar reasons than above option 1.
Restart adbd on your device with root privileges when doing app development - preferred and achievable fairly easy thru various methods including:
Preferred Solution:
a. Restart adbd with root privileges (insecure mode) by killing the service on the phone and using a terminal app or so to restart it using "su". After you are done with your app development, restart your phone and adbd will be back in secure mode, restoring the security measures.
b. Use Chainfire's ADB insecure app, which is free on XDA (download/link below) or pay for it on Google Play to support his work. You can toggle the mode in the app. In the app, you also have an option to auto re-enable the insecure mode on reboots.
References:
https://android.stackexchange.com/questions/5884/is-there-a-way-for-me-to-run-adb-shell-as-root-without-typing-in-su
http://forum.xda-developers.com/showthread.php?t=1687590 (includes free download link)
https://play.google.com/store/apps/details?id=eu.chainfire.adbd (for supporting Chainfire's work)
Possible Solutions :
1. Check if your app had left any datas :
First if the app is already installed, then clean cache data and uninstall it
Under "System Settings" then "Application Manager"
http://i.stack.imgur.com/b3oys.jpg
Then
Force uninstall by running & adb shell pm uninstall com.brian.testproject
Check "/data/data/com.brian.testproject/" and delete it
Remove any entries of your package on /data/system/packages.xml
Remove any entries of your package on /data/system/packages.list
Also you could install SDMaiD and clean your device, especially with "CorpseFinder" and "AppCleaner"
2. Try to install the app manually and debug the result :
In your case you have an issue with pm over android studio... install it manually to have a more detailed message over command line
$ adb push D:\Android\..\TestProject-debug.apk /sdcard/myapp.apk
$ adb shell pm install /sdcard/myapp.apk
3. Check Android Studio and your app sources
Change the targeted api level :
Right click on your app dir + Open Module Settings + app + check sdk version + change target and minimum under "Flavor"
Sync gradle button
Rebuild project
https://www.youtube.com/watch?v=v4b7C6Q-9dI
Update your android studio if you don't have the last release
If your app use libraries, you have to recompile them.
4. Check System Settings :
Check BOOTCLASSPATH of your init.rc. BOOTCLASSPATH must include /system/framework/ext.jar and /system/framework/framework.jar and so on.
Check DEXPREOPT_BOOT_JARS of build/core/dex_preopt.mk. DEXPREOPT_BOOT_JARS must include ext and framework and so on.
The order of all items on BOOTCLASSPATH must be equal to the order of all items on DEXPREOPT_BOOT_JARS.
5. Try pm command directly on the device :
if pm command does not work try that command with a terminal directly on the phone to see if it's a connection issue between pc and phone
pm install /sdcard/myapp.apk
6. Reinstall your rom once again (just reinstall it) no need to erase.
For anyone having this same issue, unfortunately the only solution that I could find was to downgrade my ROM version (to OA8). Once I did that, adb works perfectly. If anyone finds a better solution I'd be definitely like to know.
Android Studio
step 1: Go to file--> invalidate and restart.
step 2: Clean and rebuild project.
step 3: go to project folder run
gradle clean
step 4: restart phone/Emulator.
Done !!!

How to disable android device usb port

I am trying to search if there is a way to disable android device usb port, software level mainly. So users can still charge android device but cannot communicate with PC anymore.
I got some clues in link1. But it looks there is not an easy way for this.
Android OS is a Linux based OS. So I am wondering if there is a config file in Android OS that allows root users to disable usb port, like files under path /etc in Linux OS.
EDIT: Use this command in android terminal emulator. Root priveleges required, but you can put a password on Superuser so that no one else can undo this or edit the script:
echo 0 > /sys/devices/virtual/android_usb/android0/enable
or...
su -c 'echo 0 > /sys/devices/virtual/android_usb/android0/enable'
To automate this, you need to make a script and put it in /system/etc/init.d, let's say /system/etc/init.d/usb_off:
#!/system/bin/sh
echo 0 > /sys/devices/virtual/android_usb/android0/enable
Then make sure it's executable with:
chmod +x /system/etc/init.d/usb_off
You can also try this, but it's reported not to work. Execute these in the command line via Android Terminal Emulator:
setprop persist.sys.usb.config ''
setprop sys.usb.config ''
You can tell the usb-storage module to ignore a VID/PID combination
Make a file such as /etc/modprobe.d/android.conf having contents of the form
options usb-storage quirks=vid##:pid##:i
Where the vid/pid are given in hex without prefix
A serious limitation of this technique is that some installations will load the usb-storage driver during the initread stage before /etc is present and honored, so it may get loaded without the ignore quirk. To work around that you can modify the inittread archive, or you can unload and reload the usb-storage module (if nothing else in your system is using it).
Another downside is that if you decide you want to mount it, you'd have to reload the driver without the quirk (for example using insmod).

How do I regain DDMS access to Galaxy Tab's /data partition?

Samsung Galaxy Tab 10.1 16BG Wifi-only, retail (not I/O) edition, running 3.1.
Up until a few days ago, I could access /data/data/com.my.app/{databases,...} from the Eclipse DDMS perspective without issues. This helped with development by e.g. letting me pull sqlite files to make sure my DB code was doing what I thought it should be doing, accessing the sqlite files from the Linux command line.
A few days ago I came to my desk and found the tab in a strange state: as if stuck in the boot process, and warm to the touch, suggesting that the CPU was spinning.
I assumed it was a crash, rebooted it and thought nothing more of it until, earlier today, I can no longer get DDMS access to /data. /system and /mnt are accessible.
Is anyone aware of what might have caused that change, and if/how it can be reversed? I had not rooted the tab before, and although I understand rooting it may bring back access to /data (over DDMS?) I'd rather try to understand what happened before proceeding.
Has anyone else seen the same/similar behavior?
Update: Here's what this looks like from an ADB shell:
shell#android:/ $ ls -ld data
drwxrwx--x system system 2011-07-05 15:49 data
shell#android:/ $ cd data
shell#android:/data $ ls
opendir failed, Permission denied
255|shell#android:/data $

Categories

Resources