diff options
-rwxr-xr-x | squashfu | 112 |
1 files changed, 64 insertions, 48 deletions
@@ -107,60 +107,76 @@ usage () { exit } -################################ -# Sanity checks -################################ -# - Are we root? -# - is our BKUP_ROOT valid? (FAIL) -# - Check for pre-existing mounts just in case (and unmount them) -# - do we have a proper (expected) directory structure in place? -# (Use cd to BKUP_ROOT to avoid issues with brace expansion in a quoted path) -[[ $UID -eq 0 ]] || die Must be root! - -[[ -w "${BKUP_ROOT}" ]] || - die "Backup root is not accessible. Please check your setting in /etc/squashfu" - -unmount_all - -cd "$BKUP_ROOT" && mkdir -p {rw,ro,bins/{1,2,3,4,5,6,7}} - - -################################ -# Prep work -################################ -# - does seed exist? (if not, our backup is creating the seed) -# - Prepare union mount with proper bins -[[ -f "$SEED" ]] || { - debug "No seed found -- creating a new one..."; - create_new_seed; -} +# The meat and potatoes of the script. +do-backup () { + ################################ + # Sanity checks + ################################ + # - Are we root? + # - is our BKUP_ROOT valid? (FAIL) + # - Check for pre-existing mounts just in case (and unmount them) + # - do we have a proper (expected) directory structure in place? + # (Use cd to BKUP_ROOT to avoid issues with brace expansion in a quoted path) + [[ $UID -eq 0 ]] || die Must be root! + + [[ -w "${BKUP_ROOT}" ]] || + die "Backup root is not accessible. Please check your setting in /etc/squashfu" -mount_union_ro $(( $(date +%u) + $MODIFIER )) + unmount_all -mount_union_branch_rw $(( $(date +%u) + $MODIFIER )) + cd "$BKUP_ROOT" && mkdir -p {rw,ro,bins/{1,2,3,4,5,6,7}} -################################ -# Ready for backup! -################################ -run_rsync + ################################ + # Prep work + ################################ + # - does seed exist? (if not, our backup is creating the seed) + # - Prepare union mount with proper bins + [[ -f "$SEED" ]] || { + debug "No seed found -- creating a new one..."; + create_new_seed; + } + mount_union_ro $(( $(date +%u) + $MODIFIER )) -################################ -# Cleanup -################################ -# - Is this resquash day? If so, we need a new squash -# - If new squash creation fails, we're in trouble. (by default, keep previous week) -[[ $(date +%u) -eq $RESQUASH_DAY ]] && { - create_new_seed - # Set aside last week's tree if user opted to, else delete it all - if [[ $KEEP_LAST_WEEK -eq 1 ]]; then - move_old_tree - else - find "${BKUP_ROOT}/bins/" -type f -delete - rm $SEED - fi + mount_union_branch_rw $(( $(date +%u) + $MODIFIER )) + + + ################################ + # Ready for backup! + ################################ + run_rsync + + + ################################ + # Cleanup + ################################ + # - Is this resquash day? If so, we need a new squash + # - If new squash creation fails, we're in trouble. (by default, keep previous week) + [[ $(date +%u) -eq $RESQUASH_DAY ]] && { + create_new_seed + # Set aside last week's tree if user opted to, else delete it all + if [[ $KEEP_LAST_WEEK -eq 1 ]]; then + move_old_tree + else + find "${BKUP_ROOT}/bins/" -type f -delete + rm $SEED + fi + } + + finish_routine } -finish_routine +#Option parsing / Decision making +[[ $# -eq 0 ]] && usage + +while [[ $# -gt 0 ]]; do + case $1 in + "-c") ;; + *) usage ;; + esac + shift +done + + |