Skip to content

About

Backup/restore an Android phone's personal folders over adb

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

adb-backup

Backup / restore an Android phone's personal folders over adb, no cable-mounted file manager or cloud sync required.

Requirements

  • adb in your PATH (Android platform-tools)
  • USB debugging enabled and authorized on the phone

Usage

./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]
  • backup copies /sdcard/<FOLDERS> from the connected phone to local_dir (defaults to the current directory).
  • restore copies local_dir/<FOLDERS> back to /sdcard/ on the phone. Folders missing locally are skipped; it's an error if local_dir itself doesn't exist.
  • list lists 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 relative remote_path is resolved under /sdcard (list DCIM means /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 SERIAL targets a specific device — required when more than one is plugged in. Run adb devices to find the serial.
  • --model=MODEL / -m MODEL targets a device by its exact model name (shown as model:... in adb devices -l) instead of its serial. Ignored if --serial is also given; errors out if several devices share the model.
  • --dry-run prints the adb commands that would run without running them.
  • --exclude=PATTERN (backup/restore, repeatable) skips files whose path relative to the folder, or basename, matches the glob PATTERN.
  • --archive (backup only) also produces <local_dir>.tar.gz once the backup completes. --archive-only does 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.

Examples

# 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

Development

# Lint
shellcheck adb-backup.sh

# Tests (bats-core; https://github.com/bats-core/bats-core)
bats tests/adb-backup.bats

About

Backup/restore an Android phone's personal folders over adb

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages