Add automated Cosmos PostgreSQL backups #124
No reviewers
Labels
No labels
area:authentication
area:flake-utilities
area:performance
area:tbd
host:chaos
host:cosmos
host:electra
host:fleet
host:lena
host:lyra
host:mass-storage
host:media1
host:nimmog-de
host:nova
host:pangolin
host:pangolin-vps
host:phone
host:router
host:vega
investigation
phase:cutover
phase:deploy
phase:mcp
phase:module
phase:packaging
phase:prep
phase:validation
priority:high
priority:medium
project:attic-postgres-lyra-rollout
project:auto-update-reliability
project:auto-update-remediation
project:declarative-purity-cleanup
project:external-review
project:fleet-boundary-cleanup
project:host-facts-refactor
project:lyra-nixos-deploy
project:lyra-service-stack-migration
project:nebula-mesh-network
project:nix-idioms-hygiene
project:nixos-build-deployment-pipeline
project:security-hardening
project:service-stack-migration
project:vega-sillytavern-cutover
project:wiki-rebuild
repo:numtide/flake-utils
repo:numtide/nix-auth
repo:numtide/nixos-passthru-cache
repo:numtide/nix-relay
service:auto-update
service:gitlab
service:hermes
service:mem0
service:nix
service:sillytavern
service:slskd
service:synthseek
service:tdarr
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
nimmo/nixos-config!124
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/cosmos-postgres-backups"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Related to #123
Summary
Validation
nix flake checknix build --no-link .#nixosConfigurations.cosmos.config.system.build.toplevelRemaining before merge
Automated code review
Reviewed commit:
e0b7133b4b87cfb1bcfd2e146d8c70d95c974fe1Verdict: Requires further work
Resolve the blocking or important findings and investigate failed deterministic checks before merging.
Overall assessment
The PR introduces a NixOS module for daily logical PostgreSQL backups on the Cosmos host, provisioning a systemd service/timer and a shell script that stages, compresses, and atomically commits backup sets to a Backrest-managed directory. The implementation follows NixOS conventions and correctly scopes permissions, but contains minor redundancies and an edge-case failure path that should be addressed.
Blocking findings
None.
Important findings
The script uses
set -Eeuo pipefailand executeschmod 0640 "$staging_dir"/*. If zero databases are found, the glob literal is passed to chmod, causing a non-zero exit that triggersset -eand aborts the backup.Impact: The backup service will fail on hosts or maintenance windows where no connectable, non-template databases exist, leaving the staging directory uncommitted and potentially triggering alerting.
Suggested fix: Enable
shopt -s nullglobbefore the chmod commands, or guard the operation with[ -n "$(ls -A "$staging_dir")" ] || trueto safely handle empty directories.Suggestions
Redundant directory creation in shell script (modules/services/postgresql-backup.nix:38; high confidence)
The script executes
install -d -m 0750 -o root -g users "$backup_root"whilesystemd.tmpfiles.rulesalready provisions${cfg.backupPath}with identical permissions at boot.Impact: Minor redundancy; the explicit directory creation runs unnecessarily on every backup execution and slightly obscures the separation of concerns between NixOS provisioning and runtime logic.
Suggested fix: Remove the
install -dline from the shell script and rely entirely onsystemd.tmpfiles.rulesfor directory provisioning.Globals dump includes role passwords with restoration caveats (modules/services/postgresql-backup.nix:41; medium confidence)
runuser -u postgres -- pg_dumpall --globals-onlydumpspg_authidentries containing role passwords. The README notes restoring roles first, then databases.Impact: Restoring these globals into an existing cluster can overwrite current passwords or cause OID mismatches if the cluster was reinitialized. Safe restoration typically requires a fresh cluster or careful role reconciliation.
Suggested fix: Explicitly document in the restore procedure that
globals.sql.zstshould only be applied to a freshly initialized cluster, or consider adding--no-passwordsto the globals dump if password management is handled separately via SOPS or application configuration.Tests and validation
Questions
serviceFailureMonitorrequire specific alerting configuration to route failures frompostgresql-backup?Review limitations
nix flake checkresults were not executed; findings assume standard NixOS module resolution and shell execution semantics.Diff coverage
README.md: reviewed — included in a context-limited batchhosts/cosmos/default.nix: reviewed — included in a context-limited batchmodules/services/postgresql-backup.nix: reviewed — included in a context-limited batchReview metadata