From 9a95d9999343026480b6bf934ac31954a64f93de Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Sat, 14 Oct 2017 18:37:11 -0600 Subject: Rewrote the package setup and compression process Previously, the packaging process created a working directory in which modifications could be made before the final tarball creation. This was problematic because most of the time, the backup destination is on a vfat filesystem, which doesn't support symlinks. Any packages that used symlinks in their data directory would through "Function not implemented" errors during the initial copy of this directory. There were also space concerns with this approach. This updates the package process to construct a tar command. The constructon of this command is where package modifications can be made (eg: --exclude). The usage of tar directly on the source files removes the need to copy files around. This uses much less storage as well as performs much faster as it is now almost entirely done in memory. --- andbackup.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/andbackup.sh b/andbackup.sh index 7f5c239..72b8aac 100755 --- a/andbackup.sh +++ b/andbackup.sh @@ -85,7 +85,10 @@ lfatal() { backup_app() { local app="${1}" - if [ -z "${app}" ]; then + local tar # Tar command for packaging the backup + + # Make sure app is specified + if [[ -z ${app} ]]; then lerror "Application name required." return 1 fi @@ -115,8 +118,6 @@ backup_app() { # Create backup destination if not exist [ ! -d "${backups}" ] && mkdir -p "${backups}" - # Delete data stage directory if it exists so we can start new - [ -d "${backups}/${app}/data" ] && rm -rf "${backups}/${app}/data" # Backup the apk file if it exists if [ ! -z "${apk}" ]; then @@ -150,24 +151,21 @@ backup_app() { linfo "Skipping application force stop while booted to recovery mode." fi - # Copy the user data - cp -rp "${data}" "${backups}/${app}/data" + tar="tar -C ${data} -c " # Delete cache directory if it exists # This will sometimes free up significant amounts of space - if [ ! -d "${backups}/${app}/data/cache" ]; then + if [[ ! -d "${data}/cache" ]]; then linfo "Cache doesn't exist for ${app}" elif ! $preserveCache; then - linfo "Deleting cache for ${app}" - rm -rf "${backups}/${app}/data/cache" + linfo "Excluding cache for ${app}" + tar="${tar} --exclude=cache" else linfo "Preserving cache for ${app}" fi # Compress the backup linfo "Compressing userdata for ${app}" - cd "${backups}/${app}/" - tar -c data | gzip -c > data.tar.gz - rm -rf data + ${tar} . | gzip -c > "${backups}/${app}/data.tar.gz" } -- cgit v1.2.3