aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWynn Wolf Arbor2020-06-04 17:16:46 +0200
committerWynn Wolf Arbor2020-06-04 17:16:46 +0200
commit777add8b775e36d8ebbe057ad84e8b691c7e86c7 (patch)
tree1420f215d4d5f80b01555f20f294252d075b1233
parente58da98d30ba8b739bd4f3d05589899673426ca8 (diff)
downloadlifeboat-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.
Diffstat (limited to '')
-rwxr-xr-xlifeboat29
1 files changed, 13 insertions, 16 deletions
diff --git a/lifeboat b/lifeboat
index 4ce396c..ec13352 100755
--- a/lifeboat
+++ b/lifeboat
@@ -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