Repository navigation
Description
modules/backups.nix includes the BTCPay and NBXplorer databases through services.postgresqlBackup and then has duplicity pick up the dump files, but two details make that silently incomplete.
1. A failed dump doesn't stop the backup
systemd.services.duplicity = {
wants = postgresqlBackupServices;
after = postgresqlBackupServices ++ [ "nix-bitcoin-secrets.target" ];
};wants plus after only orders duplicity behind the dump units, so it runs whether they succeeded or not. The NixOS postgresqlBackup module rotates before it dumps: it removes the old .prev files, moves the current <db>.sql.gz to <db>.prev.sql.gz, then writes a new in-progress file and renames it into place at the end. If pg_dump fails because PostgreSQL is down, the disk is full or there's a schema it can't read, there's no <db>.sql.gz at all, only the .prev file. backups.nix lists <db>.sql.gz and excludes everything else with the final - /, so that run's archive has no database, duplicity exits 0 and nothing tells the operator.
Fix: requires = postgresqlBackupServices; next to after, so a failed dump fails the duplicity unit, which is visible in the journal and in systemctl --failed. Including the .prev file as a fallback would be worse, because it would back up yesterday's state as if it were today's.
2. The dump suffix is hardcoded to .sql.gz
postgresqlBackupPaths = map (db: "${postgresqlBackupDir}/${db}.sql.gz") cfg.postgresqlDatabases;services.postgresqlBackup.compression accepts none, gzip and zstd, and the module names the files <db>.sql, <db>.sql.gz or <db>.sql.zstd accordingly, so an operator who sets zstd (smaller, faster) gets dump files that the include list doesn't name and the final - / rule excludes. Every backup after that has no database, with no error.
Fix: derive the suffix from the option, for example
suffix = { none = ""; gzip = ".gz"; zstd = ".zstd"; }.${config.services.postgresqlBackup.compression};
postgresqlBackupPaths = map (db: "${postgresqlBackupDir}/${db}.sql${suffix}") cfg.postgresqlDatabases;or assert compression == "gzip" with a message.
What's at stake: the BTCPay database holds stores, invoices, API keys and the wallet descriptors BTCPay watches. Losing it doesn't lose keys, but a restore that silently lacks it leaves a merchant with no record of what was paid. The backups VM test checks that the dump exists and is included, and a test that stops PostgreSQL first, runs the duplicity unit and expects it to fail would cover point 1.
I can send that PR with the default scenario run if you want it.
Found by GPT-6 Astra, run at xhigh reasoning, while grading the review of #73's tree. I checked it against master 4452d89 and the pinned NixOS postgresql-backup.nix.
Activity
backups: fail the backup when a database dump fails
backups: fail on a failed database dump and follow the dump compressi…