set +o pipefail
}
-do_link()
+
+do_init()
{
# Safety net (4 slashes just in case)
case "$DEST" in
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!"
# Perhaps we could save time by recycling the oldest snapshot
cp -lR "$DEST/$newest" "$DEST/tmp" || exit 670
fi
-
- popd >/dev/null
}
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