#!/bin/bash # # Android backup # # Parameters date="`date +%Y%m%d`" base="/storage/emulated/0" storage="/var/backups/remote/celular.`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/