diff options
author | Aaron Ball <nullspoon@oper.io> | 2017-05-18 21:11:51 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2017-05-18 21:11:51 -0600 |
commit | 915e58ab88157887a16fbe397eeea4bde450559c (patch) | |
tree | 841d6d43ead2b381720ff34dc198bfcb0066af68 | |
parent | 423a3afb6e137d5d3b60408d14c30bcccb9f25bb (diff) | |
parent | 4e1667fa29c13359241eef6aeb9f38fe3668ad6c (diff) | |
download | andbackup-915e58ab88157887a16fbe397eeea4bde450559c.tar.gz andbackup-915e58ab88157887a16fbe397eeea4bde450559c.tar.xz |
Merge branch 'preserve-cache-per-app'
-rw-r--r-- | README | 81 | ||||
-rwxr-xr-x | andbackup.sh | 32 |
2 files changed, 110 insertions, 3 deletions
@@ -0,0 +1,81 @@ +-=TOC=- +-CYGWIN +-WINDOWS SHELL +-BASH +-TODO BUGS + +CYGWIN doesn't echo things properly. Like when you hit up arrow instead of showing the last command it travels up in the window. But it still will execute the last command upon hitting <enter>. <tab> autocomplete also doesn't render but still executes. + +Here's sample output of how bad it is on cygwin: +--- +root@htc_himaul:/sdcard2/bk/andbackup # ./and . +./and +andbackup.sh andbackup/ +/andbackup.sh < +sush: ./andbackup.sh: can't execute: Permission denied +126|root@htc_himaul:/sdcard2/bk/andbackup # bash and . +bash and +andbackup.sh andbackup/ +ash andbackup.sh < +shell-init: error retrieving current directory: getcwd: cannot access parent directories: Success +andbackup.sh: line 269: @: unbound variable +1|root@htc_himaul:/sdcard2/bk/andbackup # +--- + + +WINDOWS SHELL doesn't have this problem, so autocomplete and last command are clean. But the "unbound variable" happens also, this is fixed by passing the correct parameter count. (bash bug?) + + +BASH +To my surprise BASH doesn't come with busybox. To install bash do this: +Go to this site and follow its directions (http://www.blogzamana.com/getting-bash-on-android/) +Or just copy what I did here: +$ wget http://pub.mzet.net/bash +$ adb push bash /sdcard2/Download +- +root@htc_himaul:/ # mount -o remount,rw /system +mount -o remount,rw /system +root@htc_himaul:/ # cd /system/bin +root@htc_himaul:/system/bin # cp /sdcard2/Download/bash . +root@htc_himaul:/system/bin # chmod 0755 bash +root@htc_himaul:/storage/034A-1326/bk/andbackup # mount -o ro,remount,ro /system +- +Thanks (http://android.stackexchange.com/questions/110927/how-to-mount-system-rewritable-or-read-only-rw-ro) for mount tips. + +TODO BUGS +1) +--- +22:30:17 2017-03-18 info Backing up com.nianticlabs.pokemongo +cp: /storage/ext_sd/bk/andbackup/andbackupBK/com.nianticlabs.pokemongo/data//lib: Function not implemented +deleting cache for com.nianticlabs.pokemongo +22:30:49 2017-03-18 info Compressing userdata for com.nianticlabs.pokemongo +chdir: error retrieving current directory: getcwd: cannot access parent directories: Success +This app com.google.android.apps.maps-preserveDignity has passed in options +22:30:51 2017-03-18 info Backing up com.google.android.apps.maps +deleting cache for com.google.android.apps.maps +22:33:19 2017-03-18 info Compressing userdata for com.google.android.apps.maps +root@htc_himaul:/sdcard2/bk/andbackup # +--- +The "Function not implemented" error output above might be because andbackup can't handle symlinks + +2) +Most shells and even BASH has this bug: +--- +shell-init: error retrieving current directory: getcwd: cannot access parent directories: Success +--- +but it appears to run... + +3) +"sh" doesn't work: +--- +1|root@htc_himaul:/sdcard2/bk/andbackup # sh andbackup.sh +127|root@htc_himaul:/sdcard2/bk/andbackup # +--- +sh AKA ash doesn't work (with -x): +--- +1|root@htc_himaul:/storage/ext_sd/bk/andbackup # sh -x andbackup.sh +127|root@htc_himaul:/storage/ext_sd/bk/andbackup # +-even with full correct params you get the same "nothing" output +127|root@htc_himaul:/storage/ext_sd/bk/andbackup # sh -x andbackup.sh listback> +127|root@htc_himaul:/storage/ext_sd/bk/andbackup # +--- diff --git a/andbackup.sh b/andbackup.sh index 40ab224..70e3552 100755 --- a/andbackup.sh +++ b/andbackup.sh @@ -20,7 +20,8 @@ set -u backups=/sdcard/andbackup - +#backups=/storage/ext_sd/bk/andbackup/andbackupBK +flag_delimiter="-" usage() { # NOTE: The maximum width of this text should be 65 chars. This @@ -86,6 +87,17 @@ backup_app() { return 1 fi + #If app has the flag_delimiter that means options are passed in + local preserveCache=false + if [[ 0 = $(echo ${app} | grep -q [${flag_delimiter}]; echo $?) ]]; then + linfo "This app $app has passed in options" + if [[ 0 = $(echo ${app} | grep -q "preserveCache"; echo $?) ]]; then + preserveCache=true + fi + #Need to get app back to std naming (without params) + app=`echo ${app} | grep -o ^.*- | sed s/-//g | cat -` + fi + # Make sure app is installed if [[ $(dumpsys package ${app} | wc -l) -eq 0 ]]; then lerror "Package ${app} appears to not be installed." @@ -100,6 +112,7 @@ backup_app() { # Get pertinent metadata local code=$(dumpsys package ${app} | grep codePath | cut -d'=' -f2 | head -n1) local data=$(dumpsys package ${app} | grep dataDir | cut -d'=' -f2 | head -n1) + #linfo HERE is your data dir: $data # Create backup destination if not exist [[ ! -d ${backups} ]] && mkdir -p ${backups} @@ -115,9 +128,14 @@ backup_app() { # Copy the user data cp -rp ${data}/* ${backups}/${app}/data/ # Delete cache directory if it exists - # This will sometimes significant amounts of space - if [[ -d "${backups}/${app}/data/cache" ]]; then + # This will sometimes free up significant amounts of space + if [[ ! -d "${backups}/${app}/data/cache" ]]; then + linfo "Cache doesn't exist for ${app}" + elif ! $preserveCache; then + linfo "Deleting cache for ${app}" rm -rf "${backups}/${app}/data/cache" + else + linfo "Preserving cache for ${app}" fi # Compress the backup @@ -142,6 +160,14 @@ restore_app() { return 1 fi + # When restoring something with flags need to restore app alone + if [[ 0 = $(echo ${app} | grep -q [${flag_delimiter}]; echo $?) ]]; then + linfo "This app $app had passed in options" + #Need to get app back to std naming (without params) + app=`echo ${app} | grep -o ^.*- | sed s/-//g | cat -` + linfo "Restoring to std name \"${app}\" while we restore" + fi + # Check that backup exists to be restored if [[ ! -d ${backups}/${app} ]]; then lerror "No backup for ${app} exists." |