Backup / restore an Android phone's personal folders over adb, no cable-mounted
file manager or cloud sync required.
adbin yourPATH(Android platform-tools)- USB debugging enabled and authorized on the phone
./adb-backup.sh backup [local_dir] [options]
./adb-backup.sh restore [local_dir] [options]
./adb-backup.sh list [remote_path] [options]
./adb-backup.sh help [backup|restore|list]backupcopies/sdcard/<FOLDERS>from the connected phone tolocal_dir(defaults to the current directory).restorecopieslocal_dir/<FOLDERS>back to/sdcard/on the phone. Folders missing locally are skipped; it's an error iflocal_diritself doesn't exist.listlists the contents of a directory on the phone (default/sdcard) — subdirectories (suffixed/) and files — marking the directories included in the default backup list with[backup]. A relativeremote_pathis resolved under/sdcard(list DCIMmeans/sdcard/DCIM); use a leading/for an absolute path elsewhere on the device.
Options:
--folders=A,B,C(or--folders A,B,C) overrides the default folder list (DCIM Download Pictures Backup Documents) for a one-off, targeted backup.--serial=SERIAL/-s SERIALtargets a specific device — required when more than one is plugged in. Runadb devicesto find the serial.--model=MODEL/-m MODELtargets a device by its exact model name (shown asmodel:...inadb devices -l) instead of its serial. Ignored if--serialis also given; errors out if several devices share the model.--dry-runprints theadbcommands that would run without running them.--exclude=PATTERN(backup/restore, repeatable) skips files whose path relative to the folder, or basename, matches the globPATTERN.--archive(backup only) also produces<local_dir>.tar.gzonce the backup completes.--archive-onlydoes the same and then removes the plain folders, keeping only the archive.
Device state is checked up front: a clear error is shown if no device is
authorized, if it's still unauthorized/offline, or if several devices
are connected without --serial. After a plain backup (no --exclude), the
file count on the phone and on disk is compared per folder and a warning is
printed on mismatch.
Run ./adb-backup.sh help <command> or ./adb-backup.sh <command> --help for
details and examples on any subcommand.
# See what's on the phone before backing up
./adb-backup.sh list
# Full backup with the default folders
./adb-backup.sh backup ~/phone-backup
# Targeted backup of a couple of folders
./adb-backup.sh backup ~/phone-backup --folders=DCIM,WhatsApp/Media
# Preview what a backup would do, without copying anything
./adb-backup.sh backup ~/phone-backup --dry-run
# Backup while skipping thumbnails, then compress the result
./adb-backup.sh backup ~/phone-backup --exclude=.thumbnails --archive
# Target one specific device when several are plugged in
./adb-backup.sh backup ~/phone-backup --serial=emulator-5554
./adb-backup.sh backup ~/phone-backup --model=SM_G973F
# Restore everything back to the phone
./adb-backup.sh restore ~/phone-backup# Lint
shellcheck adb-backup.sh
# Tests (bats-core; https://github.com/bats-core/bats-core)
bats tests/adb-backup.bats