Reuse verified Nextcloud bundles within 20h before Borg/USB backups

This commit is contained in:
2026-11-15 22:12:50 +01:00
parent 7b85314cca
commit ffa9960c64
6 changed files with 76 additions and 8 deletions

View File

@@ -230,6 +230,19 @@ The dotfile vars follow the same split: `desktop_common_dotfiles` carries mode-i
injecting the private token for JSON-RPC POST clients; keep this route injecting the private token for JSON-RPC POST clients; keep this route
authenticated and never expose the gateway directly. See `docs/atlas-aria2.md`. authenticated and never expose the gateway directly. See `docs/atlas-aria2.md`.
- Atlas Nextcloud backup preparation (`atlas-nextcloud-backup.service`) is an ordered
requirement of the nightly `atlas-borg-backup.service` and the operator-started
`atlas-usb-backup.service`. A structurally complete bundle younger than
`atlas_nextcloud_backup_reuse_max_seconds` (20 h, asserted below 24 h so the nightly
Borg cycle always refreshes it) is reused without pausing the applications: a manual
USB run therefore reaches its LUKS prompt within seconds, while preparation failure
still blocks the dependent job. Force one fresh preparation with
`systemctl set-environment ATLAS_NEXTCLOUD_BACKUP_FORCE=1` before the start and unset
the variable afterwards. Deployed and validated on 2026-11-15: a dependency start reused
a verified bundle 14 h old and skipped preparation in 14 ms, and an operator-started
USB run reached its LUKS prompt in under a second; the FORCE path has not been exercised
in production yet. See `docs/atlas-nextcloud.md`.
## Atlas NAS TODO ## Atlas NAS TODO
Completed validation: the existing RAIDZ2 pool and datasets, SELinux, LAN firewall, SSH, Cockpit with Completed validation: the existing RAIDZ2 pool and datasets, SELinux, LAN firewall, SSH, Cockpit with
the selected 45Drives plugins, encrypted SMB3 `Archive`, the Aegis-only NFSv4 `photobook` export, and the the selected 45Drives plugins, encrypted SMB3 `Archive`, the Aegis-only NFSv4 `photobook` export, and the

View File

@@ -18,6 +18,11 @@ atlas_nextcloud_redis_image: ""
atlas_onlyoffice_image: "" atlas_onlyoffice_image: ""
atlas_nextcloud_backup_root: "{{ atlas_mount_root }}/backup/nextcloud" atlas_nextcloud_backup_root: "{{ atlas_mount_root }}/backup/nextcloud"
atlas_nextcloud_backup_keep: 2 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_admin: admin
atlas_nextcloud_users: [] atlas_nextcloud_users: []
atlas_nextcloud_apps: [] atlas_nextcloud_apps: []

View File

@@ -3,11 +3,14 @@
tags: [atlas, nextcloud_backup] tags: [atlas, nextcloud_backup]
when: atlas_manage_nextcloud | bool when: atlas_manage_nextcloud | bool
block: block:
- name: Validate private backup scope and local bundle retention - name: Validate private backup scope, retention, and bundle reuse window
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- atlas_nextcloud_backup_root == atlas_mount_root ~ '/backup/nextcloud' - atlas_nextcloud_backup_root == atlas_mount_root ~ '/backup/nextcloud'
- atlas_nextcloud_backup_keep | int >= 2 - 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_borg_backup | bool
- atlas_manage_usb_backup | bool - atlas_manage_usb_backup | bool

View File

@@ -14,6 +14,9 @@ StateDirectory=atlas-nextcloud-backup
StateDirectoryMode=0700 StateDirectoryMode=0700
ExecStart=/usr/local/sbin/atlas-nextcloud-backup ExecStart=/usr/local/sbin/atlas-nextcloud-backup
ExecStopPost=/usr/local/sbin/atlas-nextcloud-backup --recover 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 TimeoutStartSec=3h
TimeoutStopSec=5min TimeoutStopSec=5min
Nice=10 Nice=10

View File

@@ -7,6 +7,7 @@ readonly source_root={{ atlas_nextcloud_root | quote }}
readonly backup_root={{ atlas_nextcloud_backup_root | quote }} readonly backup_root={{ atlas_nextcloud_backup_root | quote }}
readonly state=/var/lib/atlas-nextcloud-backup readonly state=/var/lib/atlas-nextcloud-backup
readonly keep={{ atlas_nextcloud_backup_keep | int }} readonly keep={{ atlas_nextcloud_backup_keep | int }}
readonly reuse_max={{ atlas_nextcloud_backup_reuse_max_seconds | int }}
readonly owner={{ atlas_admin_username | quote }} readonly owner={{ atlas_admin_username | quote }}
readonly uid={{ atlas_admin_uid | int }} readonly uid={{ atlas_admin_uid | int }}
@@ -64,6 +65,36 @@ recover() {
} }
if [[ "${1:-}" == --recover ]]; then recover; exit; fi if [[ "${1:-}" == --recover ]]; then recover; exit; fi
recover 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 mounted "$dataset")" == yes ]]
[[ "$(zfs get -H -o value mountpoint "$dataset")" == "$source_root" ]] [[ "$(zfs get -H -o value mountpoint "$dataset")" == "$source_root" ]]
[[ "$(zfs get -H -o value mounted {{ (atlas_zfs_pool ~ '/backup') | quote }})" == yes ]] [[ "$(zfs get -H -o value mounted {{ (atlas_zfs_pool ~ '/backup') | quote }})" == yes ]]

View File

@@ -141,11 +141,22 @@ See `atlas-nextcloud-recovery-test.md` for scope, retained artifact and limitati
## Recurring consistent bundles ## Recurring consistent bundles
`atlas-nextcloud-backup.service` is now an ordered requirement of both `atlas-nextcloud-backup.service` is an ordered requirement of both
`atlas-borg-backup.service` and the operator-started `atlas-usb-backup.service`. `atlas-borg-backup.service` and the operator-started `atlas-usb-backup.service`.
No additional backup timer is needed: the existing Borg schedule prepares a fresh No additional backup timer is needed: the existing Borg schedule prepares a fresh
bundle before its pool snapshot, and a manual USB run does the same. Preparation bundle before its pool snapshot. A structurally complete bundle from an earlier
failure blocks the dependent job rather than silently using an old dump. verified run is reused instead while younger than
`atlas_nextcloud_backup_reuse_max_seconds` (20 h): a manual USB run then skips
the application pause, reaches its LUKS prompt within seconds and captures the
latest Borg-prepared bundle, while the remaining pool snapshot reflects the
moment of the run. Reuse does not re-hash the bundle; it was checksum-verified
at publication. The window is asserted below 24 h so the nightly Borg run,
spaced 24 h plus its randomized delay, never reuses the previous night's bundle.
Preparation failure still blocks the dependent job rather than silently using an
old dump; only a verified, bounded-age bundle may be reused. Set
`ATLAS_NEXTCLOUD_BACKUP_FORCE=1` with `systemctl set-environment` (the unit
passes it through) to ignore the window once and prepare a fresh bundle; unset
the variable afterwards.
The helper checks the mounted datasets and healthy active application state, The helper checks the mounted datasets and healthy active application state,
serializes preparations and briefly pauses cron, Nextcloud and ONLYOFFICE. It serializes preparations and briefly pauses cron, Nextcloud and ONLYOFFICE. It
@@ -171,10 +182,12 @@ sudo systemctl start atlas-nextcloud-backup.service
sudo systemctl show atlas-nextcloud-backup.service -p Result -p ExecMainExitTimestamp sudo systemctl show atlas-nextcloud-backup.service -p Result -p ExecMainExitTimestamp
``` ```
The second command briefly interrupts the applications and is an explicit manual A manual start briefly interrupts the applications only when it prepares a fresh
run of the recurring job, not a normal deployment side effect. The preparation bundle; inside the reuse window it logs `Reusing verified ...` and finishes in
unit is not enabled as a boot backup; only interrupted-job recovery is enabled. seconds without touching them. It remains an explicit manual run of the
Do not stop a Borg/USB job, break its lock or unmount its source snapshot to run a test. recurring job, not a normal deployment side effect. The preparation unit is not
enabled as a boot backup; only interrupted-job recovery is enabled. Do not stop a
Borg/USB job, break its lock or unmount its source snapshot to run a test.
On 2026-10-04, both a new encrypted Borg archive and USB version On 2026-10-04, both a new encrypted Borg archive and USB version
`20261004T101101Z-3420114` were independently extracted and their consistent `20261004T101101Z-3420114` were independently extracted and their consistent