blob: 2d88f9d37c52300bbd75f4eaf88daa2c48694f42 (
plain) (
tree)
|
|
#!/bin/sh
set -e
LIFEBOAT_ROOT=${LIFEBOAT_ROOT:-"/srv/backup/lifeboat"}
err() {
printf "lifeboat: %s\n" "$1" >&2
}
errx() {
err "$1"
exit 1
}
usage() {
printf "usage: lifeboat repo [run|restic-cmd]\n"
exit 1
}
report_backup() {
cd "$LIFEBOAT_ROOT/$repo"
test -r config/recipient || errx "Could not read recipient from config/recipient"
read -r recipient < config/recipient
test -n "$recipient" || errx "No recipient given in config/recipient"
cat <<-EOF | sendmail "$recipient"
From: Lifeboat <lifeboat@$(hostname -f)>
Subject: lifeboat: backup for $repo on $(date)
X-Report: lifeboat
$(run_backup 2>&1)
EOF
}
run_backup() {
cd "$LIFEBOAT_ROOT/$repo"
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 --read-data-subset 10%
restic prune
}
sync_default() {
test -r config/sync || return 0
while read -r target_spec; do
target=$(echo "$target_spec" | cut -f1)
limit=$(echo "$target_spec" | cut -sf2)
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
rclone sync --transfers 20 --fast-list "$RESTIC_REPOSITORY" "$target/$LIFEBOAT_REPO_NAME"
done < config/sync
}
test $# -lt 2 && usage
repo=$1
shift
test -d "$LIFEBOAT_ROOT/$repo" || errx "$repo: no such repository"
export PATH=$HOME/bin:$PATH
export LIFEBOAT_REPO_NAME=$repo
export RESTIC_REPOSITORY=$LIFEBOAT_ROOT/$repo/repo
export RESTIC_PASSWORD_FILE=$LIFEBOAT_ROOT/$repo/credentials/restic
case "$1" in
run) run_backup;;
run-report) report_backup;;
*) restic "$@";;
esac
|