diff options
author | Wynn Wolf Arbor | 2020-06-04 17:16:46 +0200 |
---|---|---|
committer | Wynn Wolf Arbor | 2020-06-04 17:16:46 +0200 |
commit | 777add8b775e36d8ebbe057ad84e8b691c7e86c7 (patch) | |
tree | 1420f215d4d5f80b01555f20f294252d075b1233 | |
parent | e58da98d30ba8b739bd4f3d05589899673426ca8 (diff) | |
download | lifeboat-777add8b775e36d8ebbe057ad84e8b691c7e86c7.tar.gz |
Simplify and improve sync_default
sync_default() suffers from needlessly complicated logic in its
threshold test. Join the two if clauses together and skip targets
cleanly by using `continue` instead.
Where possible, use OR lists instead of if clauses and also inline the
whole sync_single() function, which was only called from here.
-rwxr-xr-x | lifeboat | 29 |
1 files changed, 13 insertions, 16 deletions
@@ -4,8 +4,12 @@ set -e LIFEBOAT_ROOT=${LIFEBOAT_ROOT:-"/srv/backup/lifeboat"} -errx() { +err() { printf "lifeboat: %s\n" "$1" >&2 +} + +errx() { + err "$1" exit 1 } @@ -42,28 +46,21 @@ clean_default() { } sync_default() { - if ! test -r config/sync; then - return - fi + test -r config/sync || return 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" + test -n "$target" || errx "Empty target in config/sync" + + if test -n "$limit" && test "$(du -s "$RESTIC_REPOSITORY" | cut -f1)" -gt "$limit"; then + err "Warning: size threshold exceeded, skipping sync to $target/$LIFEBOAT_REPO_NAME" + continue fi - done < config/sync -} -sync_single() { - rclone sync --transfers 20 --fast-list "$RESTIC_REPOSITORY" "$1/$LIFEBOAT_REPO_NAME" + rclone sync --transfers 20 --fast-list "$RESTIC_REPOSITORY" "$target/$LIFEBOAT_REPO_NAME" + done < config/sync } test $# -lt 2 && usage |