]> gitweb.fluxo.info Git - scripts.git/commitdiff
Fix and style android-backup
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 26 Nov 2018 15:26:43 +0000 (13:26 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 26 Nov 2018 15:26:43 +0000 (13:26 -0200)
android-backup

index 70c50069a8a510f7c014b326c0dd3e23eca45053..882abc2dce223334d7145bcb617a8f032e76c573 100755 (executable)
@@ -3,33 +3,35 @@
 # Android backup
 #
 
-# Parameters
-basename="`basename $0`"
-name="$1"
-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`"
+# Basic parameters
+BASENAME="`basename $0`"
+NAME="$1"
 
 # Check
-if [ -z "$name" ]; then
-  echo "$basename: missing phone name"
+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
+mkdir -p $DATE && cd $DATE
 
 # Check
-if [ -d "$storage/$date" ]; then
-  echo "backup for $date already exists"
+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
+if [ -e "$STORAGE/$PREVIOUS/files" ]; then
+  sudo cp -alf $STORAGE/$PREVIOUS/files files
 fi
 
 # Ensure we have a files folder
@@ -43,20 +45,20 @@ adb shell content query --uri content://com.android.contacts/contacts > contacts
 adb backup -all
 
 # Files: full copy
-#adb pull $base files/
+#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/
+#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/
+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/
+cd .. && sudo mv $DATE $STORAGE/