Last active
June 4, 2022 22:03
-
-
Save ashafer01/19e9f953c9b174af90f47e650a03d146 to your computer and use it in GitHub Desktop.
Stream adb backup output all the way to tar in one line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Requires linux or macos | |
# | |
# On macos, I used a random open source zlib-uncompress tool that reads stdin and writes stdout only: | |
# brew install go | |
# go install github.com/odeke-em/zlib-cli/cmd/zlib-uncompress@latest | |
# And add $HOME/go/bin to my PATH (or add to the command) | |
# | |
# This will take adb backup output and stream it all the way to tar with verbose output | |
# This lets us see contents of the backup as they come off the phone and gives some indication of progress | |
# | |
# I found a copy of some old adb docs, here http://adbcommand.com/adbshell , the latest version of adb has | |
# deprecated adb backup and does not appear to include docs in the help output anymore (2022-06-04) | |
# I've copied them here as well: | |
# | |
# adb backup [-f file] [-apk | -noapk] [-obb | -noobb] [-shared | -noshared] [-all] [-system | [-nosystem] package_names | |
# | |
# Write an archive of the device's data to file. If you do not specify a file name, the default file is backup.adb. | |
# The package list is optional when you specify the -all and -shared options. The following describes the usages for | |
# the other options: | |
# -apk | -noapk: Back up or do not back up .apk files. The default value is -noapk. | |
# -obb | -noobb: Back up or do not back up .obb files. The default value is -noobb. | |
# -shared | -noshared: Back up or do not back up shared storage. The default value is -noshared. | |
# -all: Back up all installed apps. | |
# -system | -nosystem: Include or do not include system apps when backing up all installed apps (-all). The default value is -system. | |
# | |
# * Replace the string in the command below with your chosen options | |
# Typically you will want to create a new backup directory each time you use this | |
mkdir my-backup-dir | |
./adb backup -f /dev/stdout 'options go here' | tail -c +157 | zlib-uncompress | tar -C my-backup-dir -xvf - | |
# Example with my real options: | |
./adb backup -f /dev/stdout -all -apk -nosystem | tail -c +157 | zlib-uncompress | tar -C backup-2 -xvf - | |
# Notes: | |
# * Part of the offset passed to tail (+25 of it) is sourced here: | |
# https://stackpointer.io/mobile/android-adb-backup-extract-restore-repack/372/ | |
# The remaining 132 is the prompt telling the user to unlock their phone, you may | |
# potentially need to adjust this based on your adb version | |
# * The app manifest has an option to disable backups, which probably includes adb | |
# backup (but since it's deprecated it seems like docs don't specify this anymore) | |
# For me, this seems to mean very few apps get backed up with this :( | |
# https://developer.android.com/about/versions/12/behavior-changes-12#backup-restore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment