Last active
December 17, 2020 21:32
-
-
Save sbruggmann/09f6c80c878fb4106459 to your computer and use it in GitHub Desktop.
ADB - Backup and restore Android folders recursive with OS X
This file contains 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
# add to your .bash_profile, copy android-backup-files.sh & android-restore-files.sh to /Users/YOUR_USERNAME/ and reload the terminal to use the shortcuts.. | |
# important, not all apps and data can backed up | |
alias android-backup-apps='echo "enter sudo password:"; /Applications/Android\ Studio.app/sdk/platform-tools/adb backup -apk -shared -all -f "/Users/YOUR_USERNAME/Documents/privat/backups/android-backup-full-$(date +%Y%m%d).ab"' | |
# to restore call (change the date): | |
# /Applications/Android\ Studio.app/sdk/platform-tools/adb restore /Users/YOUR_USERNAME/Documents/privat/backups/android-backup-full-YYY-MM-DD.ab | |
# important, add the paths to backup in both files | |
alias android-backup-files='echo "enter sudo password:"; ~/android-backup-files.sh;' | |
alias android-restore-files='echo "enter sudo password:"; ~/android-restore-files.sh;' |
This file contains 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 | |
ADB_DIR="/Applications/Android Studio.app/sdk/platform-tools/" | |
ARCHIVE_DIR="/Users/YOUR_USERNAME/Documents/Backups/android-backup-files-$(date +%Y%m%d)/" | |
backup () | |
{ | |
printf "\n\nBackup Folder: $1\n" | |
if [ $(./adb shell ls -l $1 | wc -l) -gt 0 ] | |
then | |
mkdir $ARCHIVE_DIR/$1 2> /dev/null | |
./adb pull $1 $ARCHIVE_DIR/$1 | |
echo " - done.\n" | |
else | |
printf " - empty, doing nothing...\n" | |
exit | |
fi | |
} | |
cd "$ADB_DIR" | |
if [ $(./adb devices | wc -l) -lt 3 ] | |
then | |
./adb devices | |
printf "\n\n------------------------------------\n" | |
echo "uh is your phone plugged in?" | |
else | |
backup "/sdcard/DCIM/" | |
backup "/sdcard/.../" | |
printf "\n\n------------------------------------\n" | |
printf "Finished Backup, see: $ARCHIVE_DIR\n\n" | |
fi | |
cd ~ |
This file contains 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 | |
ADB_DIR="/Applications/Android Studio.app/sdk/platform-tools/" | |
ARCHIVE_BASEDIR="/Users/YOUR_USERNAME/Documents/Backups/" | |
restore () | |
{ | |
printf "\n\nRestore Folder: $1\n" | |
mkdir $1 2> /dev/null | |
./adb push $ARCHIVE_DIR/$1 $1 | |
echo " - done.\n" | |
} | |
printf "\n\nSelect your backup folder to restore:\n" | |
select option in "exit" "$ARCHIVE_BASEDIR"*/ | |
do | |
printf "\nRestore: $option\n\n" | |
ARCHIVE_DIR="$option" | |
cd "$ADB_DIR" | |
if [ $(./adb devices | wc -l) -lt 3 ] | |
then | |
./adb devices | |
printf "\n\n------------------------------------\n" | |
printf "uh is your phone plugged in?\n\n" | |
else | |
backup "/sdcard/DCIM/" | |
backup "/sdcard/.../" | |
printf "\n\n------------------------------------\n" | |
printf "Finished Restore, see: $ARCHIVE_DIR\n\n" | |
fi | |
cd ~ | |
exit 0 | |
done | |
printf "\n\n------------------------------------\n" | |
printf "no folder selected\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment