From: Bernie Innocenti Date: Mon, 25 Jul 2011 20:04:16 +0000 (-0400) Subject: Split out init and prune stages from do_link() X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=94ba89bdb76cb598d62bcb555197a1dfdbb134fd;p=wizbackup.git Split out init and prune stages from do_link() --- diff --git a/wizbackup b/wizbackup index e2c7729..f47d7f8 100755 --- a/wizbackup +++ b/wizbackup @@ -81,7 +81,8 @@ do_backup() set +o pipefail } -do_link() + +do_init() { # Safety net (4 slashes just in case) case "$DEST" in @@ -93,15 +94,20 @@ do_link() mkdir -p "$DEST" || exit 667 fi - pushd "$DEST" >/dev/null || exit 668 + cd "$DEST" || exit 668 +} - # Remove old backups +do_prune() +{ local old="`ls | head -n -$N_SNAPSHOT`" if [ ! -z "$old" ]; then echo "$(date): Removing oldest snapshot(s): $old..." rm -rf "$old" || exit 669 fi +} +do_link() +{ local newest=`ls | tail -n 1` if [ -z "$newest" ]; then echo "$(date): No previous snapshot found, performing a full backup!" @@ -113,8 +119,6 @@ do_link() # Perhaps we could save time by recycling the oldest snapshot cp -lR "$DEST/$newest" "$DEST/tmp" || exit 670 fi - - popd >/dev/null } do_test() @@ -138,6 +142,8 @@ do_test() if (( `id -u` != 0 )); then { echo "Sorry, must be root. Exiting..."; exit; } fi echo "$(date): START backup: $SRC -> $DEST" +do_init +do_prune do_test do_link do_backup