diff --git a/.sops.yaml b/.sops.yaml index 40f5b3c2..0ac51a18 100644 --- a/.sops.yaml +++ b/.sops.yaml @@ -2,9 +2,10 @@ # SOPS encryption policy. # # Everything under secrets/ matching *.sops.yaml is encrypted with the age -# recipient below, and so is every firewall backup under backups/firewall/. +# recipient below, and so is every firewall backup under backups/firewall/ +# and every switch backup under backups/switch/. # -# Those two live in one rule rather than two so the recipient is written once. +# They live in one rule rather than several so the recipient is written once. # A second rule would be a second copy of the key, and rotating one and not the # other is the kind of drift this repository keeps finding. # @@ -171,7 +172,7 @@ creation_rules: # fenrir a token, so its rule went in, with a placeholder for fenrir's key, # before secrets/sensor.sops.yaml could exist. - - path_regex: (secrets/.*|backups/firewall/.*)\.sops\.ya?ml$ + - path_regex: (secrets/.*|backups/firewall/.*|backups/switch/.*)\.sops\.ya?ml$ age: >- age1yrdu996u5mhdh0qf93l7s8zz8stneqnqxpncrcarrmgxvsy264rqmkcs6x, age19mkg76v0x70wkqwuykxxqpdwrq8mhgklpjw44j6xw73psnhwyvcqa9995j diff --git a/Makefile b/Makefile index 7385d9b6..07a01b25 100644 --- a/Makefile +++ b/Makefile @@ -893,6 +893,14 @@ backup-firewall: ## Pull morpheus's pfSense config, encrypt it to ./backups/, co @# backup-volumes.sh already owns KEEP there. ./scripts/backup-firewall.sh $(ARGS) +.PHONY: backup-switch +backup-switch: ## Pull neo's RouterOS /export, encrypt it to ./backups/switch/, copy it to oracle + @# backup-firewall.sh with BACKUP_DEVICE=switch: the same encrypt, verify, + @# copy and retention, for the switch. Its knobs are SW_* (SW_KEEP, + @# SW_OFFHOST), never FW_*, so an override meant for the firewall in + @# /etc/default/homelab-timers does not move the switch's exports. + BACKUP_DEVICE=switch ./scripts/backup-firewall.sh $(ARGS) + .PHONY: backup backup: ## Quiesce the stack, archive its volumes to ./backups/, verify, copy to oracle @# Thin on purpose. This target used to BE the implementation, and every diff --git a/docs/changelog.md b/docs/changelog.md index 9538fdfd..5550ba73 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -129,6 +129,19 @@ docstring gives: it is a record, not a claim about now. generator was changed. `snmp.yaml` gains the two GETs, and `ups.test.yaml` gives each rule a firing case and a quiet one. The alert rules now number 206: 178 in Prometheus and 28 in Loki. +- **`neo`'s configuration is now backed up nightly.** Until today it lived + only on the switch, which a re-check after the switch audit found; a dead + `neo` meant rebuilding it by hand from `network.md` and the wiki's port + map. `make backup-switch` is `backup-firewall.sh` with + `BACKUP_DEVICE=switch`: it logs in as a new user `backup` (group `read,ssh`, + from `10.7.7.1` only, `prometheus`'s key) through morpheus, takes + `/export`, encrypts it to the firewall export's recipients, verifies it and + copies it to `oracle`, keeping thirty a side. `homelab-backup-switch.timer` + runs it at 09:45. The export carries no password or key, and the restore in + [`swap-the-switch.md`](runbooks/swap-the-switch.md) lists the four things + to put back by hand. It is not carried on the offsite medium; a fire that + takes `prometheus` and `oracle` takes the switch too, and its rebuild is + documented. - **`UpsOnBattery` now pages on a short transfer.** On 2026-11-21 the UPS ran on battery for 82 seconds, for distorted input, and nothing paged. The rule was `upsSecondsOnBattery > 0` for 30 seconds, which needs two scrapes in diff --git a/docs/network.md b/docs/network.md index 10476e71..8650c4e7 100644 --- a/docs/network.md +++ b/docs/network.md @@ -214,6 +214,13 @@ truth for what a box actually does. [ADR-0127](adr/0127-relay-neos-log-through-morpheus.md) records why, and [`ship-firewall-logs.md`](runbooks/ship-firewall-logs.md) §10 is the procedure. + - The configuration leaves the switch too. A user `backup`, in a group + with `read` and `ssh` and nothing else, limited to `10.7.7.1` and + logging in by `prometheus`'s key only, is what `make backup-switch` + runs `/export` as, nightly at 09:45, jumped through morpheus. The + export is encrypted like the firewall's and copied to `oracle`; it + leaves out users, certificates and the SNMPv3 passphrases. + [`swap-the-switch.md`](runbooks/swap-the-switch.md) has the restore. - DHCP disabled. - **`morpheus` pins thirteen reservations in its ARP table, on every segment but Skids and Degens.** Each is a Kea reservation with *Create a @@ -353,7 +360,7 @@ listed under [Hicks](#hicks--vlan-50--trusted), and nothing else. - `oracle` runs the Lemmiwinks wiki and its Postgres — it has since 2025-11-12, and [ADR-0011](adr/0011-keep-the-wiki-internal.md) depends on it — and holds the off-host copies of the firewall export that `make backup-firewall` pushes - to it, of the weekly volume sets that `make backup` pushes + to it, of `neo`'s export that `make backup-switch` pushes, of the weekly volume sets that `make backup` pushes ([#535](https://github.com/Gerrrt/HomeLab/issues/535)), of Jellyfin's state that `make backup-nas` pulls off `smaug` and pushes on ([ADR-0045](adr/0045-pull-jellyfins-state-from-a-snapshot-over-ssh.md)), and diff --git a/docs/runbooks/schedule-maintenance.md b/docs/runbooks/schedule-maintenance.md index 8fb3104b..3bcec985 100644 --- a/docs/runbooks/schedule-maintenance.md +++ b/docs/runbooks/schedule-maintenance.md @@ -45,17 +45,19 @@ there is one copy of record ([ADR-0048](../adr/0048-carry-the-estates-backup-sets-with-the-second-recipient.md), [`copy-the-backups-offsite.md`](copy-the-backups-offsite.md)). -Two jobs' output leaves this host. `backup-firewall` copies every export to +Three jobs' output leaves this host. `backup-firewall` copies every export to `oracle` and **fails if it cannot**, so its `ScheduledJobFailed` also means "the config has stopped leaving `prometheus`" — a file that never left is a failed run, not a partial success. `backup-volumes` does the same with every complete set, weekly, after the stack is back up -([#535](https://github.com/Gerrrt/HomeLab/issues/535)), and `verify-backups` +([#535](https://github.com/Gerrrt/HomeLab/issues/535)). `backup-switch` is +`backup-firewall` for `neo`, the same script with `BACKUP_DEVICE=switch`, and +keeps `SW_KEEP` exports, default thirty. And `verify-backups` asks `oracle` to hash what it holds every morning, so a copy that has stopped -existing is that job's failure within a day. No rule names either job; the -generic pair above carries both. The same runs bound what accumulates on each +existing is that job's failure within a day. No rule names any of the three; +the generic pair above carries them all. The same runs bound what accumulates on each side — `FW_KEEP`, default thirty, for the exports; `KEEP`, default seven, for -the sets, on both sides — so neither job can fill either disk; +the sets, on both sides — so none of them can fill either disk; [`restore-the-firewall.md`](restore-the-firewall.md) §0 and [`restore-the-stack.md`](restore-the-stack.md) §0 have the windows and how to change them. Both copies ride on one key exchange between the two laptops, in @@ -102,6 +104,7 @@ the host. | `backup-wiki` | `make backup-wiki` | daily 04:45 | 2 days | | `verify-backups` | `make verify-backups` | daily 05:30 | 3 days | | `backup-firewall` | `make backup-firewall` | daily 04:30 | 3 days | +| `backup-switch` | `make backup-switch` | daily 09:45 | 3 days | | `snmp-verify` | `make snmp-verify` | Wednesdays 06:30 | 14 days | | `check-versions` | `make check-versions` | Wednesdays 06:45 | 14 days | | `dashboards-drift` | `make dashboards-export ARGS=--check` | daily 07:30 | 2 days | diff --git a/docs/runbooks/swap-the-switch.md b/docs/runbooks/swap-the-switch.md index ac3cdc63..053eb722 100644 --- a/docs/runbooks/swap-the-switch.md +++ b/docs/runbooks/swap-the-switch.md @@ -342,6 +342,69 @@ community. Then close --- +## Restoring neo from its nightly export + +`make backup-switch` takes neo's `/export` every night at 09:45, encrypts it to +the same recipients as the firewall's export, and keeps thirty here and on +`oracle`. To list them, on both sides: + +```bash +make backup-switch ARGS=--list +``` + +If `prometheus` is gone, fetch the newest from `oracle` into a checkout on a +machine that holds an age key: + +```bash +ssh atropos@10.0.99.30 ls -1r backups/switch +mkdir -p backups/switch +scp atropos@10.0.99.30:backups/switch/config-.sops.yaml backups/switch/ +``` + +Decrypt it to RAM, not to disk, readable by you alone: + +```bash +(umask 077; sops --decrypt --input-type yaml --output-type binary backups/switch/config-.sops.yaml > /dev/shm/neo.rsc) +``` + +Bring the switch to the state §1.3 leaves it in: RouterOS 7 long-term and +`reset-configuration no-defaults=yes`. Import the leaf certificate and its +key first, under the name `neo.matrix.elysium`, as §1.4 does: the export's +`www-ssl` and `api-ssl` lines name it, and fail to import without it. Then +upload `neo.rsc` through WinBox's *Files*, and import it: + +```text +/import file-name=neo.rsc +``` + +The import turns VLAN filtering on part-way through, so a WinBox session by MAC +may drop. The import carries on. Reconnect from the switch LAN at `10.7.7.2`, +check the import reported `Script file loaded and executed successfully` +(in `/log/print` if the session dropped), +then delete `/dev/shm/neo.rsc` on the workstation. + +The export leaves out three more things. Put them back by hand: + +- **Users.** The groups come back with the import, the users do not. Add + `gerrrt` with the address list from [`network.md`](../network.md), and + `homeassistant` as + [`connect-the-switch-to-home-assistant.md`](connect-the-switch-to-home-assistant.md) + §3 sets it. Add `backup` with address `10.7.7.1/32` and `prometheus`'s public + key (`/user/ssh-keys/add user=backup key="<~/.ssh/id_ed25519.pub>"`, + which RouterOS 7.24 takes; on a release that refuses it, upload the file and + use `/user/ssh-keys/import`). The reset brings the default `admin` back, + enabled: once `gerrrt` logs in, run `/user/disable admin`. +- **The SNMPv3 passphrases.** The `prometheus` community comes back without + them. Set the values the repository's secrets already hold, the way §1.5 + and [`rotate-snmp-community.md`](rotate-snmp-community.md) §4 set them, not + fresh ones, then run `make snmp-verify`. +- **Device-mode.** It is not configuration, so it is not in the export. If + `/system/device-mode/print` shows the features on, set it again (§1.3). It + needs the reset button. + +Then run `make backup-switch` once by hand, which proves the `backup` login +end to end. + ## Also required - The MokerLink leaves the estate carrying a community that cannot be deleted, diff --git a/scripts/README.md b/scripts/README.md index cc2c274f..3ef23950 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -105,7 +105,7 @@ and only its fixtures run in CI, through `self-tests.sh`. | --- | --- | --- | | `backup-volumes.sh` | `backup` | Quiesces the observability stack, archives, encrypts and verifies its volumes, and copies them to `oracle` | | `restore-volumes.sh` | `restore` | Puts a backup set back | -| `backup-firewall.sh` | `backup-firewall` | `morpheus`'s pfSense config, encrypted at rest and copied off-host | +| `backup-firewall.sh` | `backup-firewall`, `backup-switch` | `morpheus`'s pfSense config, and `neo`'s RouterOS export with `BACKUP_DEVICE=switch`, each encrypted at rest and copied off-host | | `backup-nas.sh` | `backup-nas` | The media tier's state, pulled from `smaug`'s newest snapshot ([ADR-0045](../docs/adr/0045-pull-jellyfins-state-from-a-snapshot-over-ssh.md)) | | `backup-wiki.sh` | `backup-wiki` | A dump of the wiki's database, pulled off `oracle` ([ADR-0065](../docs/adr/0065-pull-the-wikis-database-to-prometheus-as-a-dump.md)) | | `backup-library.sh` | `backup-library` | Immich's library, archived on `trinity` and copied to `oracle` ([ADR-0064](../docs/adr/0064-copy-immichs-library-to-oracle-until-the-off-estate-copy-exists.md)) | diff --git a/scripts/backup-firewall.sh b/scripts/backup-firewall.sh index c4da1d22..160279bf 100755 --- a/scripts/backup-firewall.sh +++ b/scripts/backup-firewall.sh @@ -104,13 +104,54 @@ # the dir relative to that user's home unless absolute. The # nightly unit can override it in /etc/default/homelab-timers. # FW_KEEP default 30 exports to retain, here and there +# +# THE SWITCH, THROUGH THE SAME SCRIPT +# +# BACKUP_DEVICE=switch (`make backup-switch`) takes neo's RouterOS `/export` +# instead, with everything after the pull unchanged: encrypt, verify, copy to +# oracle, retention. The switch's export holds no password or key (RouterOS +# leaves users, certificates and SNMP passphrases out of it), but it does hold +# the rule bodies docs/security.md keeps unpublished, so it is handled exactly +# like config.xml. It goes to backups/switch/ here and on oracle. +# +# Its knobs are SW_*, never FW_*. Both units read /etc/default/homelab-timers, +# and an FW_OFFHOST set there for the firewall must not redirect the switch. +# SW_HOST default 10.7.7.2 +# SW_USER default backup read and ssh policy only, address 10.7.7.1/32 +# SW_JUMP default admin@10.0.99.1 the switch LAN admits SSH from itself +# only, so the login arrives from morpheus's 10.7.7.1 +# SW_OFFHOST default atropos@10.0.99.30:backups/switch +# SW_KEEP default 30 set -euo pipefail -FW_HOST="${FW_HOST:-10.0.99.1}" -FW_USER="${FW_USER:-root}" -FW_PATH="${FW_PATH:-/cf/conf/config.xml}" -FW_OFFHOST="${FW_OFFHOST:-atropos@10.0.99.30:backups/firewall}" -FW_KEEP="${FW_KEEP:-30}" +BACKUP_DEVICE="${BACKUP_DEVICE:-firewall}" +case $BACKUP_DEVICE in + firewall) + FW_HOST="${FW_HOST:-10.0.99.1}" + FW_USER="${FW_USER:-root}" + FW_PATH="${FW_PATH:-/cf/conf/config.xml}" + FW_OFFHOST="${FW_OFFHOST:-atropos@10.0.99.30:backups/firewall}" + FW_KEEP="${FW_KEEP:-30}" + KEEP_VAR=FW_KEEP + PULL_CMD="cat $FW_PATH" + PULL_JUMP=() + RUNBOOK=docs/runbooks/restore-the-firewall.md + ;; + switch) + FW_HOST="${SW_HOST:-10.7.7.2}" + FW_USER="${SW_USER:-backup}" + FW_PATH="/export" + FW_OFFHOST="${SW_OFFHOST:-atropos@10.0.99.30:backups/switch}" + FW_KEEP="${SW_KEEP:-30}" + KEEP_VAR=SW_KEEP + PULL_CMD="/export" + PULL_JUMP=(-J "${SW_JUMP:-admin@10.0.99.1}") + RUNBOOK=docs/runbooks/swap-the-switch.md + ;; + *) + printf '\033[0;31mBACKUP_DEVICE must be firewall or switch, got %s\033[0m\n' "$BACKUP_DEVICE" >&2 + exit 1 ;; +esac # Anchored to the repository, not to the working directory, and that is not # cosmetic (#611). These shipped relative, and agreed with where @@ -121,7 +162,7 @@ FW_KEEP="${FW_KEEP:-30}" # backup-volumes.sh:158 and backup-nas.sh:155 were already absolute; this is # the odd one out being brought into line. REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -OUT_DIR="${REPO_ROOT}/backups/firewall" +OUT_DIR="${REPO_ROOT}/backups/${BACKUP_DEVICE}" SOPS_POLICY="${REPO_ROOT}/.sops.yaml" # Nightly, so 30 is a month of history — long enough to reach back past a bad @@ -132,7 +173,7 @@ SOPS_POLICY="${REPO_ROOT}/.sops.yaml" # Rejected rather than clamped: a mistyped FW_KEEP in an environment file is # not a request to delete every backup of the firewall. if ! [[ $FW_KEEP =~ ^[0-9]+$ ]] || ((FW_KEEP < 1)); then - printf '\033[0;31mFW_KEEP must be a positive integer, got %s\033[0m\n' "$FW_KEEP" >&2 + printf '\033[0;31m%s must be a positive integer, got %s\033[0m\n' "$KEEP_VAR" "$FW_KEEP" >&2 exit 1 fi @@ -178,10 +219,10 @@ need() { command -v "$1" >/dev/null 2>&1 || { red "missing dependency: $1"; exit # The length floor is RLENGTH, not an interval expression: mawk 1.3.4-20240123 # (Debian and Ubuntu's default awk) reads /x{50,}/ as exactly 50 and cut every # key to its first 54 characters (found 2026-09-26, #92). -recipients() { # [policy file, default .sops.yaml] - awk ' +recipients() { # [policy file, default .sops.yaml] [device, default $BACKUP_DEVICE] + awk -v want="backups/${2:-$BACKUP_DEVICE}/" ' /^[[:space:]]*#/ { next } - /path_regex:/ { if (inrule) exit; if ($0 ~ /backups\/firewall/) inrule = 1; next } + /path_regex:/ { if (inrule) exit; if (index($0, want)) inrule = 1; next } inrule { line = $0 while (match(line, /age1[0-9a-z]+/)) { @@ -224,9 +265,26 @@ verify() { # are the config XML. plain="$(env -i "PATH=$PATH" "HOME=$HOME" sops --decrypt --input-type yaml --output-type binary "$f" 2>/dev/null)" \ || { red "FAILED to decrypt $f"; exit 1; } + local rules ver + if [[ $BACKUP_DEVICE == switch ]]; then + # The export's first line names the release, and a switch config without + # a bridge is not this switch's. + ver=$(sed -n '1s/.* by RouterOS \([^[:space:]]*\).*/\1/p' <<<"$plain" | tr -d '\r') + if [[ -z $ver ]] || ! grep -q '^/interface bridge' <<<"$plain"; then + red "decrypted $f but it does not look like a RouterOS export of neo"; exit 1 + fi + # RouterOS skips a menu it cannot read in time and carries on, leaving a + # `#error exporting` line where it was. That is a partial config, and + # accepting it would let retention prune a whole one. + if grep -q '^#error' <<<"$plain"; then + red "decrypted $f but RouterOS left part of it out ($(grep -c '^#error' <<<"$plain") #error line(s))"; exit 1 + fi + rules=$(sed -n '/^\/ip firewall filter/,/^\/[a-z]/p' <<<"$plain" | grep -c '^add ' || true) + green "verified $(basename "$f") — RouterOS ${ver}, ${rules} input filter rules" + return 0 + fi grep -q '' <<<"$plain" \ || { red "decrypted $f but it does not look like a pfSense config"; exit 1; } - local rules ver rules=$(grep -c '' <<<"$plain" || true) ver=$(sed -n 's:.*\(.*\).*:\1:p' <<<"$plain" | head -1) green "verified $(basename "$f") — config version ${ver:-unknown}, ${rules} firewall rules" @@ -508,7 +566,7 @@ case "${1:-}" in L=age1lablablablablablablablablablablablablablablablablablablabl expect() { # printf '%s\n' "$3" > "$t/sops.yaml" - local got; got="$(recipients "$t/sops.yaml")" + local got; got="$(recipients "$t/sops.yaml" firewall)" if [[ $got == "$2" ]]; then printf '\033[0;32m PASS\033[0m %s\n' "$1" else printf '\033[0;31m FAIL\033[0m %s\n got %s\n expected %s\n' "$1" "$got" "$2"; fail=1; fi } @@ -630,13 +688,13 @@ info "pulling $FW_PATH from $FW_USER@$FW_HOST" # shellcheck disable=SC2094 # --filename-override never opens $DEST; it is a # string sops matches creation_rules against. The only reader here is # /dev/stdin and the only writer is the redirect. -if ! "${SSH[@]}" "$FW_USER@$FW_HOST" "cat $FW_PATH" \ +if ! "${SSH[@]}" "${PULL_JUMP[@]}" "$FW_USER@$FW_HOST" "$PULL_CMD" \ | sops --encrypt --age "$AGE_RECIPIENT" --input-type binary --output-type yaml \ --filename-override "$DEST" /dev/stdin \ > "$DEST"; then rm -f "$DEST" red "pull or encrypt failed — nothing written" - red "check: SSH enabled on pfSense, key authorised for $FW_USER, sops on PATH," + red "check: SSH reaches $FW_HOST${PULL_JUMP[1]:+ through ${PULL_JUMP[1]}}, key authorised for $FW_USER, sops on PATH," red "and a .sops.yaml creation rule matching $DEST" exit 1 fi @@ -663,7 +721,7 @@ if ((LOCAL_ONLY)); then printf '\n' info "--local-only: this is on the same host as everything else it protects." info "Retention was applied here; $OFFHOST_TARGET was not touched." - info "Run without the flag, or copy it yourself — see docs/runbooks/restore-the-firewall.md" + info "Run without the flag, or copy it yourself — see $RUNBOOK" exit 0 fi @@ -673,7 +731,7 @@ if ! copy_offhost; then printf '\n' red "wrote $DEST but the off-host copy FAILED — this backup is on the machine it protects" red "check: $OFFHOST_TARGET reachable, its host key in ~/.ssh/known_hosts, and this" - red "host's key authorised there — docs/runbooks/restore-the-firewall.md" + red "host's key authorised there — $RUNBOOK" exit 1 fi diff --git a/scripts/check_sops_rules.py b/scripts/check_sops_rules.py index 65890d09..1db816ec 100755 --- a/scripts/check_sops_rules.py +++ b/scripts/check_sops_rules.py @@ -409,10 +409,11 @@ def main() -> int: problems.append(f"path_regex {raw!r} does not compile — {exc}") # The paths sops is actually asked to encrypt. Stack secrets files, plus one - # firewall export: the stamp is arbitrary, so any well-formed name stands in - # for the whole class. + # firewall export and one switch export: the stamp is arbitrary, so any + # well-formed name stands in for the whole class. paths = [f"secrets/{stack}.sops.yaml" for stack in stacks()] paths.append("backups/firewall/config-20260101T000000Z.sops.yaml") + paths.append("backups/switch/config-20260101T000000Z.sops.yaml") matched_by: dict[str, str] = {} used: set[str] = set() diff --git a/scripts/install-timers.sh b/scripts/install-timers.sh index 57b41d25..fbb5dd16 100755 --- a/scripts/install-timers.sh +++ b/scripts/install-timers.sh @@ -138,6 +138,7 @@ JOBS=( "backup-wiki homelab-backup-wiki 172800 backup-wiki" "verify-backups homelab-verify-backups 259200 verify-backups" "backup-firewall homelab-backup-firewall 259200 backup-firewall" + "backup-switch homelab-backup-switch 259200 backup-switch" "snmp-verify homelab-snmp-verify 1209600 snmp-verify" "check-versions homelab-check-versions 1209600 check-versions" "dashboards-drift homelab-dashboards-drift 172800 dashboards-export" diff --git a/systemd/README.md b/systemd/README.md index d0ccde83..369f2956 100644 --- a/systemd/README.md +++ b/systemd/README.md @@ -44,6 +44,7 @@ editing units, not installing them. | --- | --- | --- | | `homelab-converge` | hourly, at :25 | Fetches `main`, checks its signature and CI, deploys it. Installs report-only; see [`converge-the-host.md`](../docs/runbooks/converge-the-host.md) | | `homelab-backup-firewall` | daily 04:30 | Exports and encrypts `morpheus`'s pfSense config | +| `homelab-backup-switch` | daily 09:45 | Exports and encrypts `neo`'s RouterOS config | | `homelab-backup-wiki` | daily 04:45 | Pulls a dump of the wiki's database off `oracle` | | `homelab-verify-backups` | daily 05:30 | Proves every stored backup set still decrypts | | `homelab-backup-nas` | Saturday 03:30 | Pulls the media tier's state off `smaug`'s newest snapshot | diff --git a/systemd/homelab-backup-switch.service b/systemd/homelab-backup-switch.service new file mode 100644 index 00000000..e224aa16 --- /dev/null +++ b/systemd/homelab-backup-switch.service @@ -0,0 +1,43 @@ +# Daily export of neo's RouterOS configuration. +# +# The same script as homelab-backup-firewall.service, with BACKUP_DEVICE=switch: +# neo's `/export`, encrypted to the same recipients, copied to oracle and kept +# for SW_KEEP days. Until this existed the switch's configuration lived only on +# the switch, and a dead neo meant rebuilding it by hand from network.md. +# +# It logs in as `backup` (read and ssh policy, from 10.7.7.1 only), jumped +# through morpheus as admin, because the switch LAN admits SSH from itself +# alone. Its own lock, not `firewall`: the jump is one short login on morpheus, +# and the firewall export holding it for five minutes is no reason to wait. +# +# See homelab-backup-firewall.service for why each directive below is set. +[Unit] +Description=HomeLab: export and encrypt neo's RouterOS configuration +Documentation=file:///home/robo/code/Gerrrt/HomeLab/docs/runbooks/schedule-maintenance.md +Wants=network-online.target +After=network-online.target + +[Service] +Type=oneshot +User=robo +Group=robo +WorkingDirectory=/home/robo/code/Gerrrt/HomeLab +Environment=STACK=observability +Environment=SOPS_AGE_KEY_FILE=/home/robo/.config/sops/age/keys.txt +EnvironmentFile=-/etc/default/homelab-timers +ExecStart=/home/robo/code/Gerrrt/HomeLab/scripts/run-scheduled.sh --job backup-switch --lock switch --lock-wait 300 -- /usr/bin/make -C /home/robo/code/Gerrrt/HomeLab backup-switch +TimeoutStartSec=600 +Restart=no +Nice=10 +IOSchedulingClass=idle +IOSchedulingPriority=7 +ProtectHome=false +ProtectSystem=false +PrivateTmp=true +NoNewPrivileges=true +RestrictSUIDSGID=true +LockPersonality=true +RestrictRealtime=true +StandardOutput=journal +StandardError=journal +SyslogIdentifier=homelab-backup-switch diff --git a/systemd/homelab-backup-switch.timer b/systemd/homelab-backup-switch.timer new file mode 100644 index 00000000..b9a977ff --- /dev/null +++ b/systemd/homelab-backup-switch.timer @@ -0,0 +1,17 @@ +[Unit] +Description=HomeLab: nightly RouterOS config export from neo +Documentation=file:///home/robo/code/Gerrrt/HomeLab/docs/runbooks/schedule-maintenance.md + +[Timer] +Unit=homelab-backup-switch.service +# 09:45, after the morning run's last slot. It leaves this host (to the switch +# through morpheus, then to oracle), so it sits with the jobs that do, at the +# end. Not in working hours' first minutes by chance: an export is a read and +# disturbs nothing on the switch. +OnCalendar=*-*-* 09:45:00 +RandomizedDelaySec=900 +Persistent=true +AccuracySec=1m + +[Install] +WantedBy=timers.target