What does "adb backup" actually do? - Android Software/Hacking General [Developers Only]

Hey everyone,
I was asking myself what the "adb backup" command will actually perform on the device and more important: is it possible to run those same commands on a device shell directly (from Terminal Emulator for example).
Goddchen

adb help
From the "adb help":
Code:
adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]
- write an archive of the device's data to <file>.
If no -f option is supplied then the data is written
to "backup.ab" in the current directory.
(-apk|-noapk enable/disable backup of the .apks themselves
in the archive; the default is noapk.)
(-shared|-noshared enable/disable backup of the device's
shared storage / SD card contents; the default is noshared.)
(-all means to back up all installed applications)
(-system|-nosystem toggles whether -all automatically includes
system applications; the default is to include system apps)
(<packages...> is the list of applications to be backed up. If
the -all or -shared flags are passed, then the package
list is optional. Applications explicitly given on the
command line will be included even if -nosystem would
ordinarily cause them to be omitted.)
Intuition would lead me to believe that this backs up your application directories (the installed directory). You can include the application packages, system packages with the system/nosystem flags, and possibly your data in your /sdcard/ directory as well.

hm okay, let me rephrase my question:
Was commands does the adb backup command execute the create the backup and what commands does the adb restore command execute to restore the backup?
Is it possible to execute those commands on a device's shell without the use of adb...
And maybe: Is it possible in any way to make a adb connection to the local device?

I get the impression that you're looking for the inner workings of adb backup to see if you can integrate it into some scripts.
That being said, I came across something that might help you out. I skimmed over it and it seems to give a low level overview of the adb backup process. I hope that helps.
android.stackexchange.com/questions/23357/is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file
Sent from my Nexus 4 using xda premium

qdev said:
I get the impression that you're looking for the inner workings of adb backup to see if you can integrate it into some scripts.
That being said, I came across something that might help you out. I skimmed over it and it seems to give a low level overview of the adb backup process. I hope that helps.
android.stackexchange.com/questions/23357/is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file
Sent from my Nexus 4 using xda premium
Click to expand...
Click to collapse
that is some awesome background info
Unfortunately it doesn't take me closer to my goal. I don't think that one can launch a backup from a shell (or app), right? The backup only seems to be able to be triggered by adb (the adb backup command). I don't see any other way of starting a backup
Is there any possible way to create a adb connection to the local device?

Related

[SCRIPT] Android-Linux Tools v0.2 for Linux [[Suggestions Needed]]

Okay. If this is not where the MODs want this post, please move it.
[UPDATE] - Jump over to Post #12 for some of my recent ideas and changes for this application.
I have been using mods for the G1 and the myTouch 3G for a little while now. I have used Backup for Root, and I use Nandroid. I created just a little simple script to backup your device to your linux-based machine and restore from there too. The concept behind this is having your backup on your computer, not your sd-card. Please, feel free to contribute. (If this is not your cup of tea, please do not leave a comment). I am limited on time, and wanted to contribute a little to the community. All this script is a compilation of adb commands. Anyone could compile these commands, I just wanted it organized and in one place.
README
After using all of the backup tools for root, I have ran into random FCs and bugs. This script uses Android SDK's adb tool and was designed to be simple. This script goes through and backs up your applications, bookmarks, sms, alarm clocks, settings, launcher settings and dictionary. There are plans for this script to be interactive in the future. As for now, it is a very basic script that will backup your device then restore your device.
Notes. As for now this script requires sudo. On every other linux pc tested, sudo was required (maybe because user did not install adb correctly?). This will change in future versions.
= Details =
REQUIREMENTS
1. Android SDK Toolkit 1.5 or higher
2. Bash v4.0.33
3. Root access to your device
4. Root access to your pc
HOWTO
Backing-Up
1. Plug your device in
2. Open command-line (On PC)
3. Run ./abrtool -b
4. Done.
Restoring
1. Reboot from flash of rom (Enter credentials and let phone setup first)
2. Open command-line (on PC)
3. Run ./abrtool -r
4. Restart device
5. Done
Changelog
Version 0.1.5
- Merged into Android-Linux-Tools (alt)
- Changed zenity commands (shows restore progress)
- Option to restart device after restore
- Can install abrtool via command-line (./abrtool --install)
Version 0.1.4
- Added Icons
- Runs Fix Permissions after restoration of applications
Version 0.1.3
- Fixed Restore (Again) - Sets $BACKUPDIR as $PATH
Version 0.1.2
- Restore applications now uses adb install instead of push
Version 0.1.1
- Fixed Restore arugement (-r restores now)
Version 0.1
- Created initial script
- Creates backups for Apps, Sms, Bookmarks, Alarms, Settings, User Dictionary, and Launcher
- Restores device
Download
Project Page for Android-Linux-Tools (ALT) http://code.google.com/p/android-linux-tools
Project Page for abrtool http://code.google.com/p/abrtool
Download abrtool ConvertVideoToAndroid
Download InstallOnAndroid Nautilus Script
InstallOnAndroid
Disclaimer
I am not responsible for anything. Anything at all. I'm just not. Blame someone else if something goes horribly wrong.
[Reserved]
[Reserved for future post]
Nice script but bart.sh can accomplish a full backup of your Android environment for restoration at a later date. While it does it to the SD card initially, these "barts" can easily be copied to any computer. I can, however, see a use for this as it serves a slightly different purpose. Thanks.
I wasn't sure what response I would get to this post. I have had to flash, partition, format, wipe.. enough times that I just wanted to plugin into my computer, backup, wipe-flash then restore. Thanks!
nice. I don't use linux myself, but i see the point of having the backup else where (not an SD card attached to the phone itself).
will this, in theory be made to work on windows? Cause that will be awesome.
@str4vag It would be really simple to just use a .bat file for Windows. I don't have any plans on making a windows script anytime soon. Sorry. Same commands especially though.
This is exactly what I've been looking for, now I just need to mod it to sync apps/bookmarks/etc automatically whenever I plug in my phone, and to only sync the new items to keep it speedy, great work dev!
@ggolemg I can play around with some "real" features soon. I plan on having it archive your backups and allow you to select which backup (default is most recent) you would like to use. I am sure I can play around with your idea too. Thanks.
subscribing to the thread, idea is very interesting. i've been looking for a foolproof way to backup and restore bookmarks, sms messages, and different alarms, without all the issues of backup for root users. gonna check out the script tonight.
Update coming by the end of the week.
- Will only backup apps not already backed up.
- Possibly apply the Python interface I have developed.
- More goodies.
How about switchrom?
Android-Linux-Tools
Okay, so this week has been crazy for me. (Mind you I am a restaurant manager first and a developer (primary web) second). I think I am going to gear this project in a different direction. First off, I have created GTK2 Dialogs and a settings panel for this application. I would like to gear towards general linux tools on the pc side. So over the next two weeks you can expect,
- Graphical Interface for abrtool (Android-Backup-Restore)
- Configuration for each application.
- Nautilus Scripts for all applications.
- Right-Click to Encode Video (With GTK2 Dialog progress)
- Right-Click to Install APK (With GTK2 Dialog progress)
- Right-Click to Sign APK (With GTK2 Dialog progress)
- Right-Click to Copy Files to SD Card
- abrtool will backup to Ubuntu One Cloud (Simple adb pull ~/Ubuntu\ One/? or maybe play with the API?)
Ideas and Possibilities
- User.conf editor
- Select with applications to backup
- Switchrom features?
Any other thoughts or suggestions are welcome. I want to start simple, keep working on the abrtool and then make my way out to some other useful tools for us linux (Ubuntu) users. Let me know what you think and what would be helpful.
i had to make a bynch of edits so this dosent run as root, id recomend everyone do the same, only run root when you must. Also changed ,.adb to adb so i dont have to run it in my android sdk dir
@ahronzombi Can you post those changes?
I am a firm believer of only running root when needed, Like I mentioned before I don't really have a huge amount of time, and when I tested this on a friends notebook adb required root to atleast kill-server then you could perform shell/push/pull.
AFAIK, adb server only requires root if ou haven't set the proper udev rules for the device.
Exactly. If we want this script to run universally we cannot rely on all users to have added the udev rules. If they don't they have to run sudo. Maybe a quick check for the udev file then sudo if not?
boulderjams said:
Exactly. If we want this script to run universally we cannot rely on all users to have added the udev rules. If they don't they have to run sudo. Maybe a quick check for the udev file then sudo if not?
Click to expand...
Click to collapse
no i think it would be wise to have people understand there udev permissions rather than run root so its universal. that kind of thinking leads to very big security problems. with root in the script most of the simplest linux users could exploit anyone
I fully understand that. Do you mind posting your changes to the script?
this is the secure version of the script that dosent run as root
keep in mind i set my own adb and home directorys so you'll have to change those
Code:
#! /bin/bash
# abrtool version 0.1
# Last Updated Wednesday, November 18, 2009
# Android Backup Data and Restore Data Script
#TODO
# 1- See if config file exists
# 2- If not, create config file (for now, select directory to backup to)
# 3- See if arguments are specified
# 4- If not, return an error via dialog
# 5- If argument -b exists, run backup
# 6- If argument -r exsists, run restore
export PATH=${PATH}:/home/ahron/android/android-sdk-linux/tools:/home/ahron/android/abr
BACKUPDIR=/home/ahron/android/backups
USER=${username-`whoami`}
backupscript() {
export PATH=$PATH:$BACKUPDIR
adb kill-server
adb pull /system/sd/app $BACKUPDIR/apps
adb pull /system/app $BACKUPDIR/apps/device
echo "---------- Backed Applications"
adb pull /data/data/com.android.providers.telephony/databases/mmssms.db $BACKUPDIR/msgs/mmssms.db
echo "---------- Backed Text Messages"
adb pull /data/data/com.android.browser/databases/browser.db $BACKUPDIR/bookmarks/browser.db
echo "---------- Backed Bookmarks"
adb pull /data/data/com.android.alarmclock/databases/alarms.db $BACKUPDIR/other/alarms.db
adb pull /data/data/com.google.android.providers.settings/databases/googlesettings.db $BACKUPDIR/other/googlesettings.db
adb pull /data/data/com.android.launcher/databases/launcher.db $BACKUPDIR/other/launcher.db
adb pull /data/data/com.android.providers.userdictionary/databases/user_dict.db $BACKUPDIR/other/user_dict.db
echo "---------- Backed Other Settings"
chown -R $USER $BACKUPDIR
zenity --info --text "Successfully Backed-up to $BACKUPDIR"
}
restorescript() {
export PATH=$PATH:$BACKUPDIR
adb kill-server
#sudo adb push $BACKUPDIR/apps /system/sd/app
echo "----------- Installing Applications"
cd $BACKUPDIR/apps
for searchfile in ./*.apk
do
echo "------------ Processing $searchfile"
sudo adb install "$searchfile"
done
echo "---------- Restored Applications"
adb shell su
adb shell fix_permissions
echo "---------- Fixed Application Permissions"
adb push $BACKUPDIR/msgs/mmssms.db /data/data/com.android.providers.telephony/databases/mmssms.db
echo "---------- Restored Messages"
adb push $BACKUPDIR/bookmarks/browser.db /data/data/com.android.browser/databases/browser.db
echo "---------- Restored Bookmarks"
echo "---------- (Please, make sure to restart your browser)"
adb push $BACKUPDIR/other/alarms.db /data/data/com.android.alarmclock/databases/alarms.db
adb push $BACKUPDIR/other/googlesettings.db /data/data/com.google.android.providers.settings/databases/googlesettings.db
adb push $BACKUPDIR/other/launcher.db adb pull /data/data/com.android.launcher/databases/launcher.db
adb push $BACKUPDIR/other/user_dict.db /data/data/com.android.providers.userdictionary/databases/user_dict.db
echo "---------- Restored Other Settings"
zenity --info --text "Successfully Restored Android device from $BACKUPDIR"
}
if [ "$#" -eq 0 ]
then
echo "Usage $0"
echo " -b Backup"
echo " -r Restore"
exit $E_OPTERR
fi
set -- `getopt "br:" "[email protected]"`
while [ ! -z "$1" ]
do
case "$1" in
-b) backupscript;;
-r) restorescript;;
esac
shift
done

Alternative method: Removing bloatware

Requirements:
- ClockworkMod Recovery on your device
- Know how to reboot into recovery
- Have Android SDK (adb) installed - and familiar with the concept of what it does, and know how to access it via command line - if not look around, it's everywhere on how to do this.
Disclaimer:
- What you do is your fault
Optional:
- Ability to discern what, and what not to remove
Synopsis:
This is a good technique if you're receiving 'read only' errors while trying to remove apps - namely located in /system/app
[size=+3]Method:[/size]
- Reboot into recovery - it's been said in other threads it's best to DISCONNECT USB, power down, boot into recovery and THEN replug the USB connector.
- Using the clockwork menu - navigate down to 'partitions menu' using your volume down button - then hit the power button
- From the partitions menu, select 'mount /system' and hit the power button
- From your Android SDK tools directory - check 'adb devices' - this should indicate your phone is connected and in 'recovery' mode.
e.g.:
Code:
$ adb devices
List of devices attached
HT06BR007742 recovery
- Type 'adb shell' - this will put you into a command line for your phone
- From the command shell: 'cd /system/app'
- To get a list of what you can remove, type 'ls'
- To remove an .apk - type 'rm FileName.apk'
- When you're done, it's suggested you use the clockwork menu to reboot the phone ('back to the main clockwork menu, and 'reboot device')
Further example / note:
Once logged in via 'adb shell' and the system dir is mounted via clockwork:
Code:
/system/app # ls |grep "ATT"
ATT_Maps.apk
ATT_Navigator.apk
/system/app # rm ATT_Navigator.apk
Also, a side note, you can see all available commands for this shell by typing:
Code:
ls /sbin
The list is quite comprehensive.
I hope this helps someone
thanks thinice !
Added to the sticky roll-up.
I'm not 100% on this but I was able to uninstall whatever I wanted through Titanium Backup, including the ATT bloatware once I was rooted.
I am not sure about the Titanium Backup method. I restored to stock rom with root and used Titanium backup to remove some apps. They showed as removed, however when I reboot the phone the apps are back and not removed. I could not get Titanium backup to remove the apps with root alone.
removing AT&T Radio
I have searched the forum and have not yet found the answer to this question...I have removed all of the AT&T apps that I want to remove, except, which apk is AT&T radio?
You talking about fm radio on a sense rom?
Sent from my HTC Liberty using XDA App
Ah, no I'm using my HTC Aria with the stock image. I've rooted it though, and I'm just getting rid of the included AT&T apps I do not want. This one shows up as "AT&T Radio". Just trying to figure out which apk to remove in order to remove this app.
what apps are SAFE to remove without effecting HTC Sense or Aria? we need to make a list of files/apps safe to remove. i heard one user saying removing HTC stocks caused error issues when it tried to sync.
Hello also any luck with change the radio to activate for 1700 mhz UMTS ?
wdlamb said:
Ah, no I'm using my HTC Aria with the stock image. I've rooted it though, and I'm just getting rid of the included AT&T apps I do not want. This one shows up as "AT&T Radio". Just trying to figure out which apk to remove in order to remove this app.
Click to expand...
Click to collapse
AndroidMusic.apk
Thanks, that was exactly what I was looking for.
I've worked on this a few hrs now. I got Clockwork Recovery to work. Figured out HTC Sync was reverting the phone to stock recovery somehow. Removed that though...
Have rerun Unrevoked, and I can get into clockwork. I'm not interested in changing to different ROM now, just removing ATT crap.
When I try sideloading instructions/alternate method for removing ATT stuff, I get an error in cmd:
C:\android\tools>adb remount
remount failed: Operation not permitted
adb devices returns:
List of devices attached:
<myserial#> device
Any ideas? Have I not completed the root access procedure? I thought it was part of the Unrevoked process.
ahren37 said:
I've worked on this a few hrs now. I got Clockwork Recovery to work. Figured out HTC Sync was reverting the phone to stock recovery somehow. Removed that though...
Have rerun Unrevoked, and I can get into clockwork. I'm not interested in changing to different ROM now, just removing ATT crap.
When I try sideloading instructions/alternate method for removing ATT stuff, I get an error in cmd:
C:\android\tools>adb remount
remount failed: Operation not permitted
adb devices returns:
List of devices attached:
<myserial#> device
Any ideas? Have I not completed the root access procedure? I thought it was part of the Unrevoked process.
Click to expand...
Click to collapse
Yes, I think I was getting the same problem so I did a sequence of steps in some weird sequence to actually change it. It went something like this:
1. Make sure your PATH variable is set to Tools folder of Android SDK
2. Boot your phone into Clockwork and connect to PC
3. On your phone go to Partitions Menu and mount /system, then mount USB storage
3. Go to command prompt on your PC change your drive to phone/SD card drive (whatever that is, F:\ in my case)
4. adb remount
5. unmount /system
6. mount /data, mount USB storage
7. adb pull /data/data/com.android.providers.settings/databases/settings.db C:\settings.db
where C:\ is the main PC drive
8. change to C:\
9. echo update secure set value = 1 where name = 'install_non_market_apps';|sqlite3 settings.db
10. change to F:\
11. adb push C:\settings.db /data/data/com.android.providers.settings/databases/settings.db
12. Unmount everything, reboot and sideloading should work
sorting and backup
To see which files take the most space, use du with sort:
Code:
du * | sort -n
If concerned about deleting an important app, try moving it to the sd card instead. First mount the sdcard with the recovery menu, then:
Code:
mkdir -p /sdcard/backup/system/app
mv /system/app/something.apk /sdcard/backup/system/app
Thanks for the guide!
Great I'll try this tonight. Thanks
Sent from my HTC Aria using XDA App
I'm getting errors when attempting to remove the ATT_Navigator and ATT_Maps.
/system/app # rm ATT_Navigator.apk
rm ATT_Navigator.apk
rm: can't remove 'ATT_Navigator.apk': Directory not empty
Same error for both. Any suggestions?
I'm running Liberated 2.1 and ClockworkMod 2.5.0.1.
asiancuta said:
what apps are SAFE to remove without effecting HTC Sense or Aria? we need to make a list of files/apps safe to remove. i heard one user saying removing HTC stocks caused error issues when it tried to sync.
Click to expand...
Click to collapse
Yeah, I think it'll be nice to have a master list so future people won't have to mess with backups.
some I'm curious about is Mobi TV, Mobile banking, Mobile Video, Peep, and mostly if it'll be okay to remove the htc twitter widget.
the only program i ran into any issues with removing was the defalut mms app. i decided to see what would happen if i got rid of that app and replaced it with handcent or chompsms. those programs could still send messages, but i couldn't receive any.
the easiest way to compile a list like that is browse the forums for any preexisting knowledge, then just start testing things for yourself. make a nandroid backup of your rom as it sits, start removing programs, boot normally and see what happens! if theres no errors after you've removed the desired apk, make a new backup, reboot into recovery and keep going at it.

CRAFT_BACKUP, a script for application and data backup

I already opened a thread in "sapphire development" forum, maybe It's better to continue here, as the script works on every device.
***0.6.5***
-Full compatibility with froyo, now it backup application moved to sd (froyo way)
***0.6.4***
-Fixed some issue with froyo
***0.6.3***
-Fixed wifi broke bug
***0.6.2***
-Fixed apn restore bug
***0.6.1***
-Added possibility to restore the call history
-Both script can be launched from phone terminal without any problem.
***0.6***
-rewritten script , is now more stable
-It does backup of applications installed on sd, both "new" and "old" method.
-If there are applications on sd saved in the backup, it asks the location where to install them.
******
In the market there are good applications for android backup.
I made my own script, craft_backup, that allow to backup both applications(apk) and data, saving them in "craft_backup" folder on sdcard.
The restore script (craft_restore), allow to interactively restore this data.
The restore script is divided into phases:
1)Application reinstall( by Wes Garner) : It automatically reinstall all the application in the backup
2)Restore applications data
3)Restore system data that does not cause incompatibility issue: sms,Apn, bookmarks, wifi, user dictionary, call history.
4)fix permissions (by [email protected]).
Prerequisites:
1) Root permissions
Script installation
Download last version from this link and flash it from recovery
Script execution
Not from recovery!
To backup:
Code:
adb shell
craft_backup #You must execute this command on the new shell
To restore (in case of wipe, we have to the repeat the script install operation)
Code:
adb remount
adb shell
craft_restore #You must execute this command on the new shell
Sometimes the restore process may seems to be frozen, simply let it work
After the restore, It's possible to have some force close, no fear. If some applications doesn't work(rare), reinstall it.
Sorry for bad english!
Very nice and clean script
Thanks a lot!!
thanks!
Now I'm working on an "Craft Backup" application to publish on market!!

[Script] [4.x+] Easy backup through ADB, no root

You may know of the unofficially implemented ADB commands "adb backup" and "adb restore."
These commands present a great and easy way to back up your entire system, and method that lets you keep your data when you root.
The parameters for this command are:
Code:
adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|nosystem] [<packages...>]
This is quite a bit to type, and it's a pain if you misspell something, so I wrote a set of batch scripts to ease the process. Simply unzip the files from the attached download into the folder with adb.exe in it (platform-tools).
Then from platform-tools type "backup" with no quotes and press enter. The script will walk you through the process of backing up.
To restore type "adb restore -f <location>.
I hope this is helpful for you all. It has definitely saved me a lot of time so far.
Don't forget to thank me if you appreciate it and please report any bugs or request any features (though I'm not sure what all there is to add).
Rapidshare url if you prefer
----------------------
Download
----------------------

ADB backup incomplete

In the aim of disabling encryption on my stock Nexus 5 I had to wipe the device. To not lose my data I researched backups and I came across the ADB method. I did several updates using different commands as I was never sure if the backup completed. The command did return however (i.e. the cursor appeared on CMD).
I ran the following:
Code:
adb backup -apk -shared -all -f C:\backup\backup.ab
Code:
adb backup -apk -shared -all -nosystem -f C:\backup\backup.ab
The end result is me having 4 backup files in the 2.8GB to 2.9GB range.
After trying ADB restore on two of them, most of my applications are not restored. I can live with that, but I would prefer if there is a way to restore my whatsapp data.
To try and diagnose the problem ibought Titanium Backup Pro to use their Extract from ADB backup option. That way I could tell what applications made it through. I unpacked then repacked the .ab file to remove the encryption by following this guide. Once I put the .ab on my phone, Titanium Backup said the backup file isn't supported.
Any thoughts ? I'm working on Windows 10 but I also dual boot with Ubuntu.
Hi
Try using the <packages...> tag
http://forum.xda-developers.com/google-nexus-5/general/guide-backup-data-root-t2824790

Categories

Resources