I managed to do an adb backup of my phone based on @sameer's answer. However, as noted in the comments there, you need to confirm the backup using the screen after running the adb backup
command.
So first, you need to have adb
installed. Make sure your device shows up and is authorized:
# adb devices
List of devices attached
EP732284Z8 device
Then run adb shell input
to make sure the commands we're going to be using are there. You should see something like that:
# adb shell input
Usage: input [<source>] <command> [<arg>...]
The sources are:
mouse
keyboard
joystick
touchnavigation
touchpad
trackball
stylus
dpad
touchscreen
gamepad
The commands and default sources are:
text <string> (Default: touchscreen)
keyevent [--longpress] <key code number or name> ... (Default: keyboard)
tap <x> <y> (Default: touchscreen)
swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen)
press (Default: trackball)
roll <dx> <dy> (Default: trackball)
Next, we'll install TouchControl to be able to see what is happening on screen. This won't work if your device is not already in USB debugging mode and authorized already (i.e. if you see "unauthorized" or "offline" after running the first command). I installed the Linux version. I had to install boost to make it work. It should work on Windows too.
We need to unlock the device. For that, we will use "adb shell input swipe [x1] [y1] [x2] [y2] [duration]" with (x1, y1, x2, y2) depending on your device and duration could be 250 (in ms). For reference, you can look at the numbers in this file (look for "shell input swipe"). In my case the resolution of my device is "1920x1080" so I looked at the part that said " if (i.toStdString() == "1080x1920") {
. That code does a swipe from left to right. I need to unlock my device by swiping from bottom to top, so I used (300, 1100, 300, 950) with a duration 300, i.e. "adb shell input swipe 300 1100 300 950 300". You'll need to experiment with the values and see what changes on the "virtual" screen to get it right. In my case (0, 0) was the top left and (300, 1100) was towards the bottom middle.
If you have a password or PIN you can input it using adb shell input text "<yourpasswordhere>"
. If you have a pattern, then you'll have to figure out the coordinates of every dot and make your pattern using adb shell swipe
commands. (Good luck with that, it'll take some time). Otherwise, you could try some screenlock bypass apps and install them via adb install
. I didn't have any of that, so I'm not sure what will work for you.
Now run the adb backup
command:
# adb backup -apk -shared -obb -all -system -f ./android-backup.ab
Now unlock your device and confirm the backup operation.
Next, you'll have a screen like that one (click image for full size):
So now, we will press "TAB" twice to get to the "BACKUP MY DATA" button, then press "ENTER" to confirm. Basically, based on the numbers in that answer:
adb shell input keyevent 61
adb shell input keyevent 61
adb shell input keyevent 66
Now your backup has started. Yey!
P.S. To see the progress of your update, you can watch the file size grow. On linux, you can run a command like that one: watch -n 5 "du -h ./*.ab"
or watch -n 5 "du --time -m ./*.ab"
P.P.S. You can use a command like adb shell input swipe 300 0 300 950 300
to open your notification drawer and abd shell input tap [x1] [y1]
to press on notifications then adb shell text [sometext]
to write. And you can use adb shell input keyevent [61|66]
to press on practically anything without knowing their coordinates.
P.P.P.S. I'm on an Xpreria ZR running "10.7.A.0.222" android version 5.1.1. Your exact commands may vary depending on your screen resolution and android version (e.g. different way to unlock, different number of times to press TAB, etc.).
Hope this helps!