mirror of
https://github.com/fscotto/infra.git
synced 2026-11-26 05:39:52 +00:00
Reuse verified Nextcloud bundles within 20h before Borg/USB backups
This commit is contained in:
@@ -18,6 +18,11 @@ atlas_nextcloud_redis_image: ""
|
||||
atlas_onlyoffice_image: ""
|
||||
atlas_nextcloud_backup_root: "{{ atlas_mount_root }}/backup/nextcloud"
|
||||
atlas_nextcloud_backup_keep: 2
|
||||
# A structurally complete bundle from an earlier verified run younger than
|
||||
# this many seconds is reused instead of re-preparing. Keep it below 24h so
|
||||
# the nightly Borg run, spaced 24h plus its randomized delay, always refreshes
|
||||
# the bundle; 0 disables reuse.
|
||||
atlas_nextcloud_backup_reuse_max_seconds: 72000
|
||||
atlas_nextcloud_admin: admin
|
||||
atlas_nextcloud_users: []
|
||||
atlas_nextcloud_apps: []
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
tags: [atlas, nextcloud_backup]
|
||||
when: atlas_manage_nextcloud | bool
|
||||
block:
|
||||
- name: Validate private backup scope and local bundle retention
|
||||
- name: Validate private backup scope, retention, and bundle reuse window
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- atlas_nextcloud_backup_root == atlas_mount_root ~ '/backup/nextcloud'
|
||||
- atlas_nextcloud_backup_keep | int >= 2
|
||||
- atlas_nextcloud_backup_reuse_max_seconds | int >= 0
|
||||
# Below 24h the nightly Borg run cannot reuse the previous bundle.
|
||||
- atlas_nextcloud_backup_reuse_max_seconds | int < 86400
|
||||
- atlas_manage_borg_backup | bool
|
||||
- atlas_manage_usb_backup | bool
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ StateDirectory=atlas-nextcloud-backup
|
||||
StateDirectoryMode=0700
|
||||
ExecStart=/usr/local/sbin/atlas-nextcloud-backup
|
||||
ExecStopPost=/usr/local/sbin/atlas-nextcloud-backup --recover
|
||||
# systemctl set-environment ATLAS_NEXTCLOUD_BACKUP_FORCE=1 makes the next run
|
||||
# ignore the bundle reuse window; unset the variable afterwards.
|
||||
PassEnvironment=ATLAS_NEXTCLOUD_BACKUP_FORCE
|
||||
TimeoutStartSec=3h
|
||||
TimeoutStopSec=5min
|
||||
Nice=10
|
||||
|
||||
@@ -7,6 +7,7 @@ readonly source_root={{ atlas_nextcloud_root | quote }}
|
||||
readonly backup_root={{ atlas_nextcloud_backup_root | quote }}
|
||||
readonly state=/var/lib/atlas-nextcloud-backup
|
||||
readonly keep={{ atlas_nextcloud_backup_keep | int }}
|
||||
readonly reuse_max={{ atlas_nextcloud_backup_reuse_max_seconds | int }}
|
||||
readonly owner={{ atlas_admin_username | quote }}
|
||||
readonly uid={{ atlas_admin_uid | int }}
|
||||
|
||||
@@ -64,6 +65,36 @@ recover() {
|
||||
}
|
||||
if [[ "${1:-}" == --recover ]]; then recover; exit; fi
|
||||
recover
|
||||
# Fast path: a structurally complete bundle from an earlier verified run is
|
||||
# reused while younger than the reuse window, without pausing the applications.
|
||||
# ATLAS_NEXTCLOUD_BACKUP_FORCE=1 ignores the window and prepares one anyway.
|
||||
if [[ "${ATLAS_NEXTCLOUD_BACKUP_FORCE:-0}" != 1 ]] && [[ "$reuse_max" -gt 0 ]]; then
|
||||
target="$(readlink -f "$backup_root/latest" 2>/dev/null || true)"
|
||||
if [[ -n "$target" && "$target" == "$backup_root/versions/"* ]]; then
|
||||
name="${target##*/}"
|
||||
if [[ "$name" =~ ^[0-9]{8}T[0-9]{6}Z-[0-9]+$ ]]; then
|
||||
bundle_utc="${name:0:4}-${name:4:2}-${name:6:2} ${name:9:2}:${name:11:2}:${name:13:2} UTC"
|
||||
created="$(date -u -d "$bundle_utc" +%s 2>/dev/null || true)"
|
||||
if [[ -n "$created" ]]; then
|
||||
now="$(date -u +%s)"
|
||||
if [[ "$((now - created))" -le "$reuse_max" ]]; then
|
||||
reusable=true
|
||||
for component in manifest.txt SHA256SUMS database.dump \
|
||||
postgres-globals.sql database-toc.txt images.txt; do
|
||||
[[ -s "$target/$component" ]] || { reusable=false; break; }
|
||||
done
|
||||
for component in app files; do
|
||||
[[ -d "$target/$component" ]] || { reusable=false; break; }
|
||||
done
|
||||
if [[ "$reusable" == true ]]; then
|
||||
echo "Reusing verified Nextcloud bundle $name (age $((now - created))s <= ${reuse_max}s); preparation skipped"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
[[ "$(zfs get -H -o value mounted "$dataset")" == yes ]]
|
||||
[[ "$(zfs get -H -o value mountpoint "$dataset")" == "$source_root" ]]
|
||||
[[ "$(zfs get -H -o value mounted {{ (atlas_zfs_pool ~ '/backup') | quote }})" == yes ]]
|
||||
|
||||
Reference in New Issue
Block a user