#!/bin/bash # # Android backup # # Basic parameters BASENAME="`basename $0`" NAME="$1" # Check if [ -z "$NAME" ]; then echo "$BASENAME: missing phone name" exit 1 fi # Additional parameters DATE="`date +%Y%m%d`" BASE="/storage/emulated/0" STORAGE="/var/backups/remote/$NAME.`facter domain`/" PREVIOUS="`sudo ls -1 $STORAGE | tac | head -n 1`" # Work folder cd ~/load || exit 1 mkdir -p $DATE && cd $DATE # Check if [ -d "$STORAGE/$DATE" ]; then echo "backup for $DATE already exists" exit 1 fi # If you have a previous backup you might want to use it with hardlinks if [ -e "$STORAGE/$PREVIOUS/files" ]; then sudo cp -alf $STORAGE/$PREVIOUS/files files fi # Ensure we have a files folder mkdir -p files # Contacts. Export also to a .vcf directly from the contact app adb-export.sh -e content://com.android.contacts/contacts adb shell content query --uri content://com.android.contacts/contacts > contacts.rows # Configurations adb backup -all # Files: full copy #adb pull $BASE files/ # Remove multimedia cache from backup #rm -rf files/Music # Files: full basic copy #adb shell ls -1 $BASE | grep -v ^Music | while read file; do # adb pull $BASE/$file files/ #done # Files: incremental basic copy for file in `adb shell ls -1 $BASE | grep -v '^Music'`; do adb-sync --delete --reverse $BASE/$file files/ done # Move backup to storage cd .. && sudo mv $DATE $STORAGE/