Last active
January 4, 2016 07:59
-
-
Save startling/8592101 to your computer and use it in GitHub Desktop.
Back up important stuff from an android phone via adb.
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
#!/usr/bin/env sh | |
# USAGE: ./backup [texts] [pictures] [downloads] | |
# You can put other files you'd like to back up in $FILES | |
# Things to remember. | |
TEXTS="/data/data/com.android.providers.telephony/databases/mmssms.db" | |
PICTURES="/mnt/sdcard/DCIM/ /mnt/sdcard/Pictures/" | |
DOWNLOADS="/mnt/sdcard/Download/" | |
# Parse args. | |
for arg; do | |
case $arg in | |
"texts") FILES="$FILES $TEXTS";; | |
"pictures") FILES="$FILES $PICTURES";; | |
"downloads") FILES="$FILES $DOWNLOADS";; | |
*) echo "Unknown argument: $arg" && exit 1;; | |
esac | |
done | |
# More things to remember. | |
TIME=`date "+%Y-%m-%d-%H:%M:%S"` | |
NAME=/mnt/sdcard/backup-$TIME | |
# Copy everything to a directory we can adb pull. | |
adb shell su -c " | |
mkdir $NAME && \ | |
for f in $FILES; do | |
# Make the directory that holds that file. | |
mkdir -p '$NAME'\\\`dirname \\\$f\\\` || exit 1; | |
# Copy the file to that directory. | |
cp -r \\\$f '$NAME'\\\$f || exit 1; | |
done | |
" | |
# Pull it. | |
mkdir -p backups | |
adb pull $NAME backups/$TIME | |
# Delete the temporary directory. | |
adb shell "rm -R $NAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment