Source:
- http://www.upubuntu.com/2015/08/how-to-backup-and-restore-your-android.html
- https://www.ru10android.com/complete-backup-android-to-linux-ubuntu-redhat-centos-and-all/
- https://forum.xda-developers.com/showthread.php?t=2011811
Note:
- Some apps specify in the AndroidManifest.xml android:allowBackup="false" so these apps won't get backed up by this procedure.
- These require Titanium Backup or CWM or TWRP and the device must be rooted.
- http://forum.xda-developers.com/android/software-hacking/guide-how-to-enable-adb-backup-app-t3495117
1. Enable USB Debugging
Enable USB Debugging ( usually by going to the bottom of the 'Developer Options menu 'page' and tapping between 5 & 10 times on:
- the last option or
- the 'build number option'
2. Install
Debian:
sudo apt-get install android-tools-adb
OR
sudo apt-get install adb
Fedora:
sudo yum install android-tools
3. Query Device(s)
adb device
4. Perform Backup
adb backup -apk -shared -all -f ~/Documents/phone/phonebak2019.ab
5. Kill ADB Server
adb kill server
6. Unpack image to tar ( see android-backup-extractor )
java -jar abe.jar ~/Documents/phone/phonebak.ab phonebak.tar
Note: make life easier by creating a symlink to abe in your scripts or ~ folder to avoid the painful hunt for it
ln -s ~/t/git/linuxscripts/adb-tools/android-backup-tookit/android-backup-extractor/android-backup-extractor-20180521-bin/abe.jar ~/scripts/abe.jar
Bash Script
Install ADB Tools
------------- select option: 1 - test-connection 2 - backup-device 3 - install-adbc 4 - adb kill server -------------
selected opt: 3 installing android-tools-adb [sudo] password for silosix: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libzita-alsa-pcmi0 libzita-resampler1 Use 'sudo apt autoremove' to remove them. The following packages will be upgraded: android-tools-adb 1 upgraded, 0 newly installed, 0 to remove and 668 not upgraded. Need to get 13.6 kB of archives. After this operation, 7,168 B of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 android-tools-adb all 1:8.1.0+r23-5~18.04 [13.6 kB] Fetched 13.6 kB in 0s (37.3 kB/s) (Reading database ... 327430 files and directories currently installed.) Preparing to unpack .../android-tools-adb_1%3a8.1.0+r23-5~18.04_all.deb ... Unpacking android-tools-adb (1:8.1.0+r23-5~18.04) over (1:7.0.0+r33-2) ... Setting up android-tools-adb (1:8.1.0+r23-5~18.04) ...
Query Device(s)
select option: 1 - test-connection 2 - backup-device 3 - install-adbc 4 - adb kill server ------------- 1 selected opt: 1 testing device connection.... List of devices attached 534838bd device
Backup Device
------------- select option: 1 - test-connection 2 - backup-device 3 - install-adbc 4 - adb kill server ------------- 2 selected opt: 2 perform FULL BACKUP of device Now unlock your device and confirm the backup operation...
KIll ADB Server
------------- select option: 1 - test-connection 2 - backup-device 3 - install-adbc 4 - adb kill server ------------- 4 selected opt: 4 kill adb server Android Debug Bridge version 1.0.39 Revision 3db08f2c6889-android Installed as /usr/lib/android-sdk/platform-tools/adb global options: -a listen on all network interfaces, not just localhost -d use USB device (error if multiple devices connected)
Extract Image Contents
- Get java utillities: https://sourceforge.net/projects/adbextractor/
- extract from android-backup-tookit-20180521.zip and place in the directory of choice
- abe.jar
- Doc
- perl
java -jar abe.jar phonebak.ab phonebak.tar
Source
#!/bin/bash ############################################################################## # # menu template # # local var1='literal $interpretation that prints $interpretation instead of its value' # local var2="allows substitution with $var1" ############################################################################## function install-adb(){ echo "installing android-tools-adb" sudo apt-get install android-tools-adb read cont menuAdbTools } function test-connection(){ #~$ adb devices #* daemon not running. starting it now on port 5037 * #* daemon started successfully * #List of devices attached #c1607f713b068af device echo "testing device connection...." adb devices read cont menuAdbTools } function backup-device(){ # echo "perform FULL BACKUP of device" adb backup -apk -shared -all -f backup.2019.1124 read cont menuAdbTools } function cont(){ echo "press a key" && read key } function promptkey(){ echo "press a key" && read key && echo "selected option: $key" } function menuAdbTools(){ # clear echo "-------------" echo "select option:" echo "1 - test-connection" echo "2 - backup-device" echo "3 - install-adbc" echo "-------------" read opt echo "selected opt: $opt" case "$opt" in "1") test-connection ;; "2") backup-device ;; "3") install-adb ;; *) echo "option not found..." ;; esac } echo "##############################################################################" # export .env vars & clear screen export "$(grep -v '^#' .env | xargs)" clear # show menu menuAdbTools echo "##############################################################################"
adb help
$ adb --help Android Debug Bridge version 1.0.39 Revision 3db08f2c6889-android Installed as /usr/lib/android-sdk/platform-tools/adb global options: -a listen on all network interfaces, not just localhost -d use USB device (error if multiple devices connected) -e use TCP/IP device (error if multiple TCP/IP devices available) -s SERIAL use device with given serial number (overrides $ANDROID_SERIAL) -p PRODUCT name or path ('angler'/'out/target/product/angler'); default $ANDROID_PRODUCT_OUT -H name of adb server host [default=localhost] -P port of adb server [default=5037] -L SOCKET listen on given socket for adb server [default=tcp:localhost:5037] general commands: devices [-l] list connected devices (-l for long output) help show this help message version show version num networking: connect HOST[:PORT] connect to a device via TCP/IP [default port=5555] disconnect [HOST[:PORT]] disconnect from given TCP/IP device [default port=5555], or all forward --list list all forward socket connections forward [--no-rebind] LOCAL REMOTE forward socket connection using: tcp:<port> (<local> may be "tcp:0" to pick any open port) localabstract:<unix domain socket name> localreserved:<unix domain socket name> localfilesystem:<unix domain socket name> dev:<character device name> jdwp:<process pid> (remote only) forward --remove LOCAL remove specific forward socket connection forward --remove-all remove all forward socket connections ppp TTY [PARAMETER...] run PPP over USB reverse --list list all reverse socket connections from device reverse [--no-rebind] REMOTE LOCAL reverse socket connection using: tcp:<port> (<remote> may be "tcp:0" to pick any open port) localabstract:<unix domain socket name> localreserved:<unix domain socket name> localfilesystem:<unix domain socket name> reverse --remove REMOTE remove specific reverse socket connection reverse --remove-all remove all reverse socket connections from device file transfer: push LOCAL... REMOTE copy local files/directories to device pull [-a] REMOTE... LOCAL copy files/dirs from device -a: preserve file timestamp and mode sync [DIR] copy all changed files to device; if DIR is "system", "vendor", "oem", or "data", only sync that partition (default all) -l: list but don't copy shell: shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...] run remote shell command (interactive shell if no command given) -e: choose escape character, or "none"; default '~' -n: don't read from stdin -T: disable PTY allocation -t: force PTY allocation -x: disable remote exit codes and stdout/stderr separation emu COMMAND run emulator console command app installation: install [-lrtsdg] PACKAGE install-multiple [-lrtsdpg] PACKAGE... push package(s) to the device and install them -l: forward lock application -r: replace existing application -t: allow test packages -s: install application on sdcard -d: allow version code downgrade (debuggable packages only) -p: partial application install (install-multiple only) -g: grant all runtime permissions uninstall [-k] PACKAGE remove this app package from the device '-k': keep the data and cache directories backup/restore: backup [-f FILE] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [PACKAGE...] write an archive of the device's data to FILE [default=backup.adb] package list optional if -all/-shared are supplied -apk/-noapk: do/don't back up .apk files (default -noapk) -obb/-noobb: do/don't back up .obb files (default -noobb) -shared|-noshared: do/don't back up shared storage (default -noshared) -all: back up all installed applications -system|-nosystem: include system apps in -all (default -system) restore FILE restore device contents from FILE debugging: bugreport [PATH] write bugreport to given PATH [default=bugreport.zip]; if PATH is a directory, the bug report is saved in that directory. devices that don't support zipped bug reports output to stdout. jdwp list pids of processes hosting a JDWP transport logcat show device log (logcat --help for more) security: disable-verity disable dm-verity checking on userdebug builds enable-verity re-enable dm-verity checking on userdebug builds keygen FILE generate adb public/private key; private key stored in FILE, public key stored in FILE.pub (existing files overwritten) scripting: wait-for[-TRANSPORT]-STATE wait for device to be in the given state State: device, recovery, sideload, or bootloader Transport: usb, local, or any [default=any] get-state print offline | bootloader | device get-serialno print <serial-number> get-devpath print <device-path> remount remount /system, /vendor, and /oem partitions read-write reboot [bootloader|recovery|sideload|sideload-auto-reboot] reboot the device; defaults to booting system image but supports bootloader and recovery too. sideload reboots into recovery and automatically starts sideload mode, sideload-auto-reboot is the same but reboots after sideloading. sideload OTAPACKAGE sideload the given full OTA package root restart adbd with root permissions unroot restart adbd without root permissions usb restart adb server listening on USB tcpip PORT restart adb server listening on TCP on PORT internal debugging: start-server ensure that there is a server running kill-server kill the server if it is running reconnect kick connection from host side to force reconnect reconnect device kick connection from device side to force reconnect environment variables: $ADB_TRACE comma-separated list of debug info to log: all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp $ADB_VENDOR_KEYS colon-separated list of keys (files or directories) $ANDROID_SERIAL serial number to connect to (see -s) $ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
- Log in to post comments