From ec8b34a136c71dc6acd86f401cc703772404836c Mon Sep 17 00:00:00 2001 From: Luke Pahler Date: Sat, 18 Mar 2017 23:33:14 -0600 Subject: Starting to implement preservation of cache on a per app basis. --- README | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ andbackup.sh | 23 +++++++++++++++++++++-- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..4db802d --- /dev/null +++ b/README @@ -0,0 +1,55 @@ +CYGWIN +WINDOWS SHELL +BASH + + + +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 . 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?) +- +"sh" doesn't work: +--- +1|root@htc_himaul:/sdcard2/bk/andbackup # sh andbackup.sh +127|root@htc_himaul:/sdcard2/bk/andbackup # +--- + + +BASH even has a bug: +--- +shell-init: error retrieving current directory: getcwd: cannot access parent directories: Success +--- +but it appears to run fine + + +TODO BUGS +--- +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 # +--- +Looks like andbackup can't handle symlinks diff --git a/andbackup.sh b/andbackup.sh index 40ab224..77624ce 100755 --- a/andbackup.sh +++ b/andbackup.sh @@ -19,7 +19,8 @@ # set -u -backups=/sdcard/andbackup +#backups=/sdcard/andbackup +backups=/storage/ext_sd/bk/andbackup/andbackupBK usage() { @@ -86,6 +87,20 @@ backup_app() { return 1 fi + #If app has "-" that means options are passed in + local preserveCache=false + if [[ 0 = $(echo ${app} | grep --quiet [-]; echo $?) ]]; then + linfo "This app $app has passed in options" + if [[ 0 = $(echo ${app} | grep --quiet "preserveCache"; echo $?) ]]; then + preserveCache=true + fi + #Need to get app back to std naming (without params) + app=`echo ${app} | grep --only-matching ^.*- | sed s/-//g | cat -` + fi + + #DEBUGGING don't want to actaully install + #return 1 + # Make sure app is installed if [[ $(dumpsys package ${app} | wc -l) -eq 0 ]]; then lerror "Package ${app} appears to not be installed." @@ -100,6 +115,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} @@ -116,8 +132,11 @@ backup_app() { 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 + if [[ -d "${backups}/${app}/data/cache" ]] && ! $preserveCache; then + linfo "Deleting cache for ${app}" rm -rf "${backups}/${app}/data/cache" + else + linfo "Preserving cache for ${app}" fi # Compress the backup -- cgit v1.2.3 From 66bfa923ec693b96b3bbbae9504ada8d01bd4af5 Mon Sep 17 00:00:00 2001 From: Luke Pahler Date: Fri, 24 Mar 2017 19:44:04 -0600 Subject: Updated README with more details on the "sh" major-bug. --- README | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README b/README index 4db802d..54d6e6f 100644 --- a/README +++ b/README @@ -30,6 +30,14 @@ WINDOWS SHELL doesn't have this problem, so autocomplete and last command are cl 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 +127|root@htc_himaul:/storage/ext_sd/bk/andbackup # sh -x andbackup.sh listback> +127|root@htc_himaul:/storage/ext_sd/bk/andbackup # +--- BASH even has a bug: @@ -52,4 +60,5 @@ 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 # --- -Looks like andbackup can't handle symlinks +The error output above might be because andbackup can't handle symlinks + -- cgit v1.2.3 From 2c68eab918485700a3597226ac6e80f0d1ea7483 Mon Sep 17 00:00:00 2001 From: Luke Pahler Date: Fri, 24 Mar 2017 20:11:56 -0600 Subject: How to install bash plus other README cleanup. --- README | 69 +++++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/README b/README index 54d6e6f..e2418f3 100644 --- a/README +++ b/README @@ -1,8 +1,8 @@ -CYGWIN -WINDOWS SHELL -BASH - - +-=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 . autocomplete also doesn't render but still executes. @@ -24,30 +24,26 @@ andbackup.sh: line 269: @: unbound variable 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?) -- -"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 -127|root@htc_himaul:/storage/ext_sd/bk/andbackup # sh -x andbackup.sh listback> -127|root@htc_himaul:/storage/ext_sd/bk/andbackup # ---- - -BASH even has a bug: ---- -shell-init: error retrieving current directory: getcwd: cannot access parent directories: Success ---- -but it appears to run fine +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 @@ -60,5 +56,26 @@ 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 error output above might be because andbackup can't handle symlinks +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 # +--- -- cgit v1.2.3 From fcdca78a14e43c2d375ce164366373cfa6aaca7e Mon Sep 17 00:00:00 2001 From: Luke Pahler Date: Mon, 3 Apr 2017 18:36:26 -0600 Subject: Ability to restore from a list that has flags. Plus more precise logging and added a new global variable. --- andbackup.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/andbackup.sh b/andbackup.sh index 77624ce..0426b68 100755 --- a/andbackup.sh +++ b/andbackup.sh @@ -21,7 +21,7 @@ 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 @@ -89,7 +89,7 @@ backup_app() { #If app has "-" that means options are passed in local preserveCache=false - if [[ 0 = $(echo ${app} | grep --quiet [-]; echo $?) ]]; then + if [[ 0 = $(echo ${app} | grep --quiet [${flag_delimiter}]; echo $?) ]]; then linfo "This app $app has passed in options" if [[ 0 = $(echo ${app} | grep --quiet "preserveCache"; echo $?) ]]; then preserveCache=true @@ -98,9 +98,6 @@ backup_app() { app=`echo ${app} | grep --only-matching ^.*- | sed s/-//g | cat -` fi - #DEBUGGING don't want to actaully install - #return 1 - # Make sure app is installed if [[ $(dumpsys package ${app} | wc -l) -eq 0 ]]; then lerror "Package ${app} appears to not be installed." @@ -131,8 +128,10 @@ 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" ]] && ! $preserveCache; 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 @@ -161,6 +160,14 @@ restore_app() { return 1 fi + # When restoring something with flags need to restore app alone + if [[ 0 = $(echo ${app} | grep --quiet [${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 --only-matching ^.*- | 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." -- cgit v1.2.3 From 6235dc7da2126b89d7b86051e35ae5a11101706b Mon Sep 17 00:00:00 2001 From: Luke Pahler Date: Tue, 18 Apr 2017 21:08:56 -0600 Subject: Putting "backups" back to Aaron's --- andbackup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/andbackup.sh b/andbackup.sh index 0426b68..646c0ce 100755 --- a/andbackup.sh +++ b/andbackup.sh @@ -19,8 +19,8 @@ # set -u -#backups=/sdcard/andbackup -backups=/storage/ext_sd/bk/andbackup/andbackupBK +backups=/sdcard/andbackup +#backups=/storage/ext_sd/bk/andbackup/andbackupBK flag_delimiter="-" usage() { @@ -87,7 +87,7 @@ backup_app() { return 1 fi - #If app has "-" that means options are passed in + #If app has the flag_delimiter that means options are passed in local preserveCache=false if [[ 0 = $(echo ${app} | grep --quiet [${flag_delimiter}]; echo $?) ]]; then linfo "This app $app has passed in options" -- cgit v1.2.3 From 4e1667fa29c13359241eef6aeb9f38fe3668ad6c Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Thu, 18 May 2017 21:04:53 -0600 Subject: Fixed grep switches Stock grep on android does not support long switches (like --only-matching vs -o, or --quiet vs -q, etc). This replaces all long grep arguments with their short equivelants. --- andbackup.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/andbackup.sh b/andbackup.sh index 646c0ce..70e3552 100755 --- a/andbackup.sh +++ b/andbackup.sh @@ -89,13 +89,13 @@ backup_app() { #If app has the flag_delimiter that means options are passed in local preserveCache=false - if [[ 0 = $(echo ${app} | grep --quiet [${flag_delimiter}]; echo $?) ]]; then + if [[ 0 = $(echo ${app} | grep -q [${flag_delimiter}]; echo $?) ]]; then linfo "This app $app has passed in options" - if [[ 0 = $(echo ${app} | grep --quiet "preserveCache"; echo $?) ]]; then + 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 --only-matching ^.*- | sed s/-//g | cat -` + app=`echo ${app} | grep -o ^.*- | sed s/-//g | cat -` fi # Make sure app is installed @@ -161,10 +161,10 @@ restore_app() { fi # When restoring something with flags need to restore app alone - if [[ 0 = $(echo ${app} | grep --quiet [${flag_delimiter}]; echo $?) ]]; then + 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 --only-matching ^.*- | sed s/-//g | cat -` + app=`echo ${app} | grep -o ^.*- | sed s/-//g | cat -` linfo "Restoring to std name \"${app}\" while we restore" fi -- cgit v1.2.3