Split out init and prune stages from do_link()
authorBernie Innocenti <bernie@codewiz.org>
Mon, 25 Jul 2011 20:04:16 +0000 (16:04 -0400)
committerroot <root@monolith.office.fsf.org>
Mon, 25 Jul 2011 20:04:16 +0000 (16:04 -0400)
wizbackup

index e2c772988fd6c7df073892141de6626ed17a8f3f..f47d7f8c98efcdbd5c7a8607add6b7af3cea2880 100755 (executable)
--- 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