diff options
Diffstat (limited to 'andbackup.sh')
-rwxr-xr-x | andbackup.sh | 32 |
1 files changed, 29 insertions, 3 deletions
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." |