diff --git a/roles/svc-bkp-local-2-device/README.md b/roles/svc-bkp-local-2-device/README.md index 3484e724ff..e9f6a85aec 100644 --- a/roles/svc-bkp-local-2-device/README.md +++ b/roles/svc-bkp-local-2-device/README.md @@ -41,4 +41,4 @@ Run `files/python/recover.py` on the host with the backup device attached: recover.py /dev/sdX1 /mnt/usb-recover /var/lib/infinito/backup [--snapshot ] ``` -The script opens the LUKS device (interactive passphrase prompt; `--passphrase-stdin` for automation), mounts it, picks the newest device snapshot across every machine hash (a fresh host after total loss has a new machine id), mirrors it into the target (`rsync -a --delete`) and unmounts/closes the device again. No pre-recover service backup runs: the device itself is the backup this role maintains. Afterwards restore individual applications from the backup root with the matching role's `recover.py` (`svc-bkp-volume-2-local` for docker volumes, `svc-bkp-nfs-2-local` for NFS exports). +The script opens the LUKS device (interactive passphrase prompt; `--passphrase-stdin` for automation), mounts it, picks the newest device snapshot across every machine hash (a fresh host after total loss has a new machine id), mirrors it into the target (`rsync -aHAX --delete`) and unmounts/closes the device again. No pre-recover service backup runs: the device itself is the backup this role maintains. Afterwards restore individual applications from the backup root with the matching role's `recover.py` (`svc-bkp-volume-2-local` for docker volumes, `svc-bkp-nfs-2-local` for NFS exports). diff --git a/roles/svc-bkp-local-2-device/files/python/recover.py b/roles/svc-bkp-local-2-device/files/python/recover.py index beaff5b0b6..f7c21954df 100755 --- a/roles/svc-bkp-local-2-device/files/python/recover.py +++ b/roles/svc-bkp-local-2-device/files/python/recover.py @@ -8,7 +8,7 @@ Opens the LUKS device (interactive passphrase prompt, or stdin with ``--passphrase-stdin``), mounts it, picks the newest device snapshot (any machine hash: a fresh host after total loss has a new /etc/machine-id) and mirrors it into the target -(``rsync -a --delete``), then unmounts and closes the device again. +(``rsync -aHAX --delete``), then unmounts and closes the device again. No pre-recover service backup runs: the device itself is the backup this role maintains. diff --git a/roles/svc-bkp-nfs-2-local/README.md b/roles/svc-bkp-nfs-2-local/README.md index 59d2cdc056..9a50ea768b 100644 --- a/roles/svc-bkp-nfs-2-local/README.md +++ b/roles/svc-bkp-nfs-2-local/README.md @@ -20,7 +20,7 @@ flowchart TD UNIT["svc-bkp-nfs-2-local.<version>.<domain>.service"] --> LOCK["ExecStartPre: sys-lock against the manipulation group"] LOCK --> SCRIPT["ExecStart: script.sh <export_base> <backups_dir>
backup-nfs-to-local <state>/backup"] SCRIPT -->|export_base missing| ALARM["ERROR exit 1
OnFailure alarm"] - SCRIPT --> RSYNC["rsync -a --delete
--exclude /<state>/backup (no backups-in-backups)
--link-dest previous generation (hard links)"] + SCRIPT --> RSYNC["rsync -aHAX --delete
--exclude /<state>/backup (no backups-in-backups)
--link-dest previous generation (hard links)"] RSYNC -->|exit 24: live export churn| WARN["WARN, snapshot kept"] RSYNC -->|any other failure| CLEAN["generation removed, exit != 0"] RSYNC --> TREE["<backups_dir>/<sha256(machine-id)>/
backup-nfs-to-local/<YYYYmmddHHMMSS>/files/..."] @@ -42,7 +42,7 @@ recover.py //backup-nfs-to-local//files/`. -2. Run the script; it first starts the role's deployed backup unit (a fresh differential `backup-nfs-to-local` generation of the live export), then mirrors the snapshot into the target (`rsync -a --delete`, with the shared `/backup` root protected from deletion and never copied in). `--no-safety-backup` skips the unit run when the target holds nothing worth saving. +2. Run the script; it first starts the role's deployed backup unit (a fresh differential `backup-nfs-to-local` generation of the live export), then mirrors the snapshot into the target (`rsync -aHAX --delete`, with the shared `/backup` root protected from deletion and never copied in). `--no-safety-backup` skips the unit run when the target holds nothing worth saving. 3. Redeploy the stack; the NFS clients re-mount and pick up the restored state. The target subtree must already exist; the script refuses to create export subtrees implicitly. diff --git a/roles/svc-bkp-nfs-2-local/files/python/recover.py b/roles/svc-bkp-nfs-2-local/files/python/recover.py index ef159bed13..a2b0f7ebfe 100755 --- a/roles/svc-bkp-nfs-2-local/files/python/recover.py +++ b/roles/svc-bkp-nfs-2-local/files/python/recover.py @@ -6,7 +6,7 @@ Runs the role's deployed backup unit first (the usual differential ``backup-nfs-to-local`` generation of the live export), then mirrors the -snapshot into the target (``rsync -a --delete``). Run on the host +snapshot into the target (``rsync -aHAX --delete``). Run on the host serving the export with every consuming stack stopped; NFS clients re-mount on redeploy. diff --git a/roles/svc-bkp-nfs-2-local/files/shell/script.sh b/roles/svc-bkp-nfs-2-local/files/shell/script.sh index b353e816a3..415a7e893e 100644 --- a/roles/svc-bkp-nfs-2-local/files/shell/script.sh +++ b/roles/svc-bkp-nfs-2-local/files/shell/script.sh @@ -45,7 +45,7 @@ trap cleanup_failed_generation ERR mkdir -p "${DEST_DIR}" -rsync_args=(-a --numeric-ids --delete) +rsync_args=(-aHAX --numeric-ids --delete) if [[ -n "${EXCLUDE_REL}" ]]; then rsync_args+=(--exclude "/${EXCLUDE_REL#/}") fi diff --git a/roles/svc-bkp-secrets-2-local/README.md b/roles/svc-bkp-secrets-2-local/README.md index 656312d62b..9fdc61ea07 100644 --- a/roles/svc-bkp-secrets-2-local/README.md +++ b/roles/svc-bkp-secrets-2-local/README.md @@ -57,7 +57,7 @@ recover.py //backup-secrets-to-local//files [ The script first starts the role's deployed backup unit (a fresh differential generation of the live material), then mirrors each present -subtree back to its fixed system path (`rsync -a --delete`): `secrets` +subtree back to its fixed system path (`rsync -aHAX --delete`): `secrets` into `/var/lib/infinito/secrets`, `ca` into `/etc//ca`, `acme` into `/etc/letsencrypt`, `certbot` into `/etc/certbot`. `--no-safety-backup` skips the pre-recover unit run. The `node` subtree (ssh host keys + diff --git a/roles/svc-bkp-secrets-2-local/files/python/recover.py b/roles/svc-bkp-secrets-2-local/files/python/recover.py index d8fe157cb1..fbb624b888 100755 --- a/roles/svc-bkp-secrets-2-local/files/python/recover.py +++ b/roles/svc-bkp-secrets-2-local/files/python/recover.py @@ -7,7 +7,7 @@ Runs the role's deployed backup unit first (a fresh differential ``backup-secrets-to-local`` generation of the live material), then mirrors each present subtree of the snapshot back to its fixed system -path (``rsync -a --delete``): secrets, the self-signed CA, the Let's +path (``rsync -aHAX --delete``): secrets, the self-signed CA, the Let's Encrypt tree and the ACME DNS credentials. The ``node`` subtree (ssh host keys + machine-id) is restored only with ``--restore-node-identity`` because overwriting the running machine-id / ssh host keys changes the diff --git a/roles/svc-bkp-volume-2-local/README.md b/roles/svc-bkp-volume-2-local/README.md index 9179add82e..1703a09e03 100644 --- a/roles/svc-bkp-volume-2-local/README.md +++ b/roles/svc-bkp-volume-2-local/README.md @@ -29,7 +29,7 @@ flowchart TD TREE --> RECOVER["files/python/recover.py volume
resolves Mountpoint + Options"] RECOVER -->|"Options set"| PROBE{"mountpoint -q
(ssh for --docker-host)"} PROBE -->|unmounted| REFUSE["SystemExit: a restore would land
on the node disk and be shadowed
on the next mount"] - PROBE -->|mounted| RSYNC["rsync -a --delete through the
mounted export onto the server"] + PROBE -->|mounted| RSYNC["rsync -aHAX --delete through the
mounted export onto the server"] DRILL["DR drill [9/9]
mounts the export at the volume
mountpoint with the volume's own opts"] --> RECOVER RSYNC --> VERIFY["marker asserted on the
NFS server's disk"] ``` @@ -216,5 +216,5 @@ recover.py //backup-docker-to-local// ``` 1. Stop the consuming project (`docker compose down` / `docker stack rm `). -2. Run the script; it first starts the role's deployed backup unit (a fresh differential baudolo generation of every volume and database), resolves the volume's mountpoint and mirrors the snapshot into it (`rsync -a --delete`). `--no-safety-backup` skips the unit run when the target holds nothing worth saving. +2. Run the script; it first starts the role's deployed backup unit (a fresh differential baudolo generation of every volume and database), resolves the volume's mountpoint and mirrors the snapshot into it (`rsync -aHAX --delete`). `--no-safety-backup` skips the unit run when the target holds nothing worth saving. 3. Restore the databases with the `--databases` mode above **while the project is still down**, then start it again; on swarm, NFS-backed volumes are restored via `svc-bkp-nfs-2-local`'s `recover.py` instead (see below). diff --git a/roles/svc-bkp-volume-2-local/files/python/recover.py b/roles/svc-bkp-volume-2-local/files/python/recover.py index b1ecdc5873..5d4d0829bf 100755 --- a/roles/svc-bkp-volume-2-local/files/python/recover.py +++ b/roles/svc-bkp-volume-2-local/files/python/recover.py @@ -9,7 +9,7 @@ Both modes run the role's deployed backup unit first, unless ``--no-safety-backup`` says the target holds nothing worth saving. Volume mode mirrors the snapshot into the volume's mountpoint -(``rsync -a --delete``); stop the consuming project first. With +(``rsync -aHAX --delete``); stop the consuming project first. With ``--docker-host ssh://user@host`` it works on a remote host. Database mode (``--databases``) replays every dump with diff --git a/tests/unit/python/utils/recovery/test_base.py b/tests/unit/python/utils/recovery/test_base.py index b084fba0f6..31955330de 100644 --- a/tests/unit/python/utils/recovery/test_base.py +++ b/tests/unit/python/utils/recovery/test_base.py @@ -55,6 +55,20 @@ class TestDirectoryRecovery(unittest.TestCase): self.assertEqual(text, "from-snapshot") self.assertFalse((target / "live.txt").exists()) + def test_restore_carries_extended_attributes(self) -> None: + with tempfile.TemporaryDirectory() as td: + source, target = self._mk(td) + recovery = _Recovery(str(source), str(target)) + with mock.patch("utils.recovery.base.subprocess.run") as run: + recovery.restore() + self.assertEqual( + run.call_args.args[0][:2], + ["rsync", "-aHAX"], + "a restore without -X returns the payload byte-identical while " + "every xattr-backed application (OpenCloud posixfs) reads the " + "tree as unknown", + ) + def test_missing_unit_refuses(self) -> None: with tempfile.TemporaryDirectory() as td: source, target = self._mk(td) diff --git a/utils/recovery/base.py b/utils/recovery/base.py index 3d7087c31e..6ca5a51ad1 100644 --- a/utils/recovery/base.py +++ b/utils/recovery/base.py @@ -1,7 +1,7 @@ """Abstract recover flow shared by every ``svc-bkp-*`` role. A recover mirrors a snapshot into a live target directory -(``rsync -a --delete``), so the target's current state would be lost +(``rsync -aHAX --delete``), so the target's current state would be lost without a net. The flow therefore first runs the role's deployed backup service (``systemctl start`` on the role's unit), which applies the usual differential backup logic to the live data before anything is @@ -87,7 +87,7 @@ class DirectoryRecovery(ABC): subprocess.run( [ "rsync", - "-a", + "-aHAX", "--numeric-ids", "--delete", *self.rsync_extra_args,