summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-12-24 15:42:08 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2018-12-24 15:42:08 -0500
commit080e1c1062a30e27012cf7b0c0d8786aa4af2f57 (patch)
tree9a3d14b3be138edc0ddaff6f64d9f0432048a1ae
parentae3da7d908ae3573bfd027b9fa30358c6def81dd (diff)
mgmt-backup: Sync changes from winston
-rw-r--r--config-parabola-mgmt-backup.PKGBUILD86
1 files changed, 82 insertions, 4 deletions
diff --git a/config-parabola-mgmt-backup.PKGBUILD b/config-parabola-mgmt-backup.PKGBUILD
index 3293fce..7c4f23a 100644
--- a/config-parabola-mgmt-backup.PKGBUILD
+++ b/config-parabola-mgmt-backup.PKGBUILD
@@ -52,7 +52,6 @@ add-file -m755 etc/systemd/system/backup <<'EOF'
--exclude-other-filesystems
#--progress # seems broken?
- --full-if-older-than=1M # full backup every month
)
prune_args=(
remove-all-inc-of-but-n-full 2 --force
@@ -79,14 +78,93 @@ add-file -m755 etc/systemd/system/backup <<'EOF'
--name="$backup"
)
printf '======================> %s <======================\n' "$backup"
- "${duplicity[@]}" "${backup_args[@]}" ${backups[$backup]} "file:///var/lib/backup/public/$backup" || r=$?
- chmod 644 "/var/lib/backup/public/$backup"/*.gpg || r=$?
- "${duplicity[@]}" "${prune_args[@]}" "file:///var/lib/backup/public/$backup" || r=$?
+ primary_chain_size=$("$(dirname -- "${BASH_SOURCE[0]}")/duplicity-primary-chain-size" "$backup") || { r=$?; continue; }
+ IFS=+ read -r full inc <<<"$primary_chain_size"
+ if (( inc >= full )); then
+ action=full
+ else
+ action=inc
+ fi
+ "${duplicity[@]}" "$action" "${backup_args[@]}" ${backups[$backup]} "file:///var/lib/backup/public/$backup" || r=$?
+ chmod 644 "/var/lib/backup/public/$backup"/*.gpg || r=$?
+ "${duplicity[@]}" "${prune_args[@]}" "file:///var/lib/backup/public/$backup" || r=$?
done
exit $r
}
EOF
+add-file -m755 etc/systemd/system/duplicity-primary-chain-size <<'EOF'
+#!/usr/bin/env bash
+shopt -s extglob nullglob
+glob_date='[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]Z'
+glob_n='+([0-9])'
+
+die() {
+ printf '%s: ' "$0" >&2
+ printf "$@" >&2
+ exit 1
+}
+
+{
+ name=$1
+ dir="/var/lib/backup/public/$name"
+
+ declare -A snap_parent
+ declare -A snap_files
+ for file in "$dir"/*; do
+ if [[ ! -f $file ]] || [[ -L $file ]]; then
+ die "unexpected non-file: %q" "$file"
+ fi
+ case "${file##*/}" in
+ duplicity-full-signatures.${glob_date}.sigtar.gpg) type=full;;
+ duplicity-full.${glob_date}.manifest.gpg) type=full;;
+ duplicity-full.${glob_date}.vol${glob_n}.difftar.gpg) type=full;;
+ duplicity-inc.${glob_date}.to.${glob_date}.manifest.gpg) type=inc;;
+ duplicity-inc.${glob_date}.to.${glob_date}.vol${glob_n}.difftar.gpg) type=inc;;
+ duplicity-new-signatures.${glob_date}.to.${glob_date}.sigtar.gpg) type=inc;;
+ *) die "unexpected file name: %q" "$file";;
+ esac
+ declare date= parent=
+ case "$type" in
+ full)
+ IFS=. read -r _ date _ <<<"${file##*/}"
+ parent=full
+ ;;
+ inc)
+ IFS=. read -r _ parent _ date _<<<"${file##*/}"
+ ;;
+ esac
+ if [[ -n ${snap_parent[$date]} && ${snap_parent[$date]} != "$parent" ]]; then
+ die "multiple parents for %q: %s %q" "$date" "${snap_parent[$date]}" "$parent"
+ fi
+ snap_parent[$date]="$parent"
+ snap_files[$date]+="${file@Q} "
+ done
+ if (( ${#snap_parent[@]} == 0 )); then
+ echo "0+0"
+ exit 0
+ fi
+
+ last=$(printf '%s\0' "${!snap_parent[@]}" | LC_COLLATE=C sort -z | tail -z -n1 | xargs -0)
+ declare -i inc_size=0
+ declare -i full_size=0
+ while [[ $last != full ]]; do
+ declare -i size=0
+ eval "files=(${snap_files[$last]})"
+ for file in "${files[@]}"; do
+ size+=$(stat -c '%s' -- "$file")
+ done
+ if [[ ${snap_parent[$last]} != full ]]; then
+ inc_size+=$size
+ else
+ full_size=$size
+ fi
+ last=${snap_parent[$last]}
+ done
+ printf '%s+%s\n' "$full_size" "$inc_size"
+}
+EOF
+
mkdir -p var/lib/backup
add-file -m644 etc/systemd/system/backup.service <<EOF