From b7149e7449462850de07733be9dae325b17057ef Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Sat, 1 Feb 2020 17:56:32 +0100 Subject: Introduce default fallback jobs When before lifeboat was expecting the user to populate the run, post, and sync scripts, now it includes a sane default for each step of the backup process, making deployments much more simple. The post script was split up into retain and clean. --- lifeboat | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'lifeboat') diff --git a/lifeboat b/lifeboat index d4100d0..9d569f5 100755 --- a/lifeboat +++ b/lifeboat @@ -15,13 +15,55 @@ usage() { run_backup() { ( cd "$rootdir/$repo" - ./run - for i in post sync; do - test -x $i && ./$i + + for i in run retain clean sync; do + if test -x $i; then + ./$i + else + ${i}_default; + fi done ) } +run_default() { + restic-priv backup --files-from config/include --exclude-file config/exclude --exclude-caches +} + +retain_default() { + restic forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 2 +} + +clean_default() { + restic check + restic prune +} + +sync_default() { + if ! test -r config/sync; then + return + fi + + while read -r target_spec; do + target=$(echo "$target_spec" | cut -f1) + limit=$(echo "$target_spec" | cut -sf2) + + if test -n "$limit"; then + if test "$(du -s "$RESTIC_REPOSITORY" | cut -f1)" -gt "$limit"; then + printf "Warning: size threshold exceeded, skipping sync to %s\n" "$target/$LIFEBOAT_REPO_NAME" + else + sync_single "$target" + fi + else + sync_single "$target" + fi + done < config/sync +} + +sync_single() { + rclone sync --transfers 20 --fast-list "$RESTIC_REPOSITORY" "$1/$LIFEBOAT_REPO_NAME" +} + rootdir=${LIFEBOAT_ROOT:-"/srv/backup/lifeboat"} test $# -lt 2 && usage -- cgit v1.2.3-2-gb3c3