From 4fbe0c8d81500e5d8dbffc6504b03af8764f67fd Mon Sep 17 00:00:00 2001 From: phanes Date: Mon, 27 Feb 2023 21:47:25 -0500 Subject: [PATCH] some cleanup of messy backup/restore facilities --- make.project/backup_restore.sh | 26 ++++++++++++++++--- .../components/stage4backup/offer_backup.bash | 5 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/make.project/backup_restore.sh b/make.project/backup_restore.sh index ca3d482..a9e874c 100755 --- a/make.project/backup_restore.sh +++ b/make.project/backup_restore.sh @@ -30,6 +30,15 @@ logprint() { logprint "Giving the user the option of backing up before proceeding." +assert_zero() { + if [[ "$1" -eq 0 ]]; then + return + else + exit $1 + fi +} + + is_mounted() { findmnt $1 &> /dev/null if [ $? != 0 ]; then @@ -62,8 +71,8 @@ function disarm_chroot() { } function clear_stage() { - pushd ${project_root} - make clean + rm -Rf ${T_SYSROOT} + assert_zero $? } function fail_easy() { @@ -72,7 +81,13 @@ function fail_easy() { } function restore() { + disarm_chroot backup_files=($(ls $project_root | grep "backup.tgz")) + if [[ ${#backup_files[@]} -lt 1 ]]; then + logprint "No archives present in '$project_root'. Nothing to restore from. Exiting." + exit 1 + fi + # Create an array to store the options for the dialog options=() for file in "${backup_files[@]}"; do @@ -96,7 +111,12 @@ function restore() { clear_stage sleep 1 logprint "Restoring backup...This will take a long time..." - tar xphf ${project_root}/$selected + echo + logprint "Entering ${dir_artifacts}..." + echo + pushd ${dir_artifacts} + assert_zero $? + tar xvpf ${project_root}/$selected assert_zero $? logprint "Backup restored successfully. Arming chroot." diff --git a/rex.project/x86_64/components/stage4backup/offer_backup.bash b/rex.project/x86_64/components/stage4backup/offer_backup.bash index a440fac..6bbd7b5 100755 --- a/rex.project/x86_64/components/stage4backup/offer_backup.bash +++ b/rex.project/x86_64/components/stage4backup/offer_backup.bash @@ -4,7 +4,7 @@ APPNAME="Offer Backup" # ISO 8601 variation -TIMESTAMP="$(date +%Y-%m-%d_%H:%M:%S)" +TIMESTAMP="$(date +%Y-%m-%d_%H%M%S)" LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}" @@ -55,7 +55,8 @@ function perform_backup() { disarm_chroot disarm_chroot logprint "Performing backup...This will take a long time..." - tar cpzf ${project_root}/${TIMESTAMP}.backup.tgz ${dir_stage} + pushd ${dir_artifacts} + tar cpzf ${project_root}/${TIMESTAMP}.backup.tgz * assert_zero $? logprint "Backup completed successfully. Moving on." logprint "Entering project root."