some cleanup of messy backup/restore facilities

master
phanes 2023-02-27 21:47:25 -05:00
parent c4192e2328
commit 4fbe0c8d81
2 changed files with 26 additions and 5 deletions

View File

@ -30,6 +30,15 @@ logprint() {
logprint "Giving the user the option of backing up before proceeding." 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() { is_mounted() {
findmnt $1 &> /dev/null findmnt $1 &> /dev/null
if [ $? != 0 ]; then if [ $? != 0 ]; then
@ -62,8 +71,8 @@ function disarm_chroot() {
} }
function clear_stage() { function clear_stage() {
pushd ${project_root} rm -Rf ${T_SYSROOT}
make clean assert_zero $?
} }
function fail_easy() { function fail_easy() {
@ -72,7 +81,13 @@ function fail_easy() {
} }
function restore() { function restore() {
disarm_chroot
backup_files=($(ls $project_root | grep "backup.tgz")) 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 # Create an array to store the options for the dialog
options=() options=()
for file in "${backup_files[@]}"; do for file in "${backup_files[@]}"; do
@ -96,7 +111,12 @@ function restore() {
clear_stage clear_stage
sleep 1 sleep 1
logprint "Restoring backup...This will take a long time..." 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 $? assert_zero $?
logprint "Backup restored successfully. Arming chroot." logprint "Backup restored successfully. Arming chroot."

View File

@ -4,7 +4,7 @@
APPNAME="Offer Backup" APPNAME="Offer Backup"
# ISO 8601 variation # 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}" LOG_DIR="${LOGS_ROOT}/${APPNAME}-${TIMESTAMP}"
@ -55,7 +55,8 @@ function perform_backup() {
disarm_chroot disarm_chroot
disarm_chroot disarm_chroot
logprint "Performing backup...This will take a long time..." 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 $? assert_zero $?
logprint "Backup completed successfully. Moving on." logprint "Backup completed successfully. Moving on."
logprint "Entering project root." logprint "Entering project root."