From 6161592f5a1c4a098ba61145d4cde51ad6e4368d Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 21 Feb 2024 22:01:32 +0100 Subject: [PATCH] feat(dgn-backups): Setup postgres databases backups --- machines/compute01/vaultwarden.nix | 1 + modules/dgn-backups/default.nix | 19 +++++++++++++++---- npins/sources.json | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/machines/compute01/vaultwarden.nix b/machines/compute01/vaultwarden.nix index abc2f47..d5f8e75 100644 --- a/machines/compute01/vaultwarden.nix +++ b/machines/compute01/vaultwarden.nix @@ -73,4 +73,5 @@ in }; dgn-backups.jobs.vaultwarden.settings.paths = [ "/var/lib/bitwarden_rs" ]; + dgn-backups.postgresDatabases = [ "vaultwarden" ]; } diff --git a/modules/dgn-backups/default.nix b/modules/dgn-backups/default.nix index b306bf8..1894d28 100644 --- a/modules/dgn-backups/default.nix +++ b/modules/dgn-backups/default.nix @@ -41,15 +41,13 @@ let } // settings ); - - mkPgJobs = lib.extra.mapFuse (db: { "pg-${db}" = { }; }); in { options.dgn-backups = { enable = mkEnableOption "DGNum backup service."; - pgDumps = mkOption { + postgresDatabases = mkOption { type = listOf str; default = [ ]; description = '' @@ -86,6 +84,19 @@ in }; config = { + dgn-backups.jobs = + lib.extra.mapFuse + (db: { + "${db}-db".settings = { + user = "postgres"; + command = [ + "${lib.getExe' config.services.postgresql.package "pg_dump"}" + db + ]; + }; + }) + cfg.postgresDatabases; + services.bupstash = { repositories = { inherit (cfg) enable; @@ -109,7 +120,7 @@ in ]; }; - jobs = (mkPgJobs cfg.pgDumps) // (mkJobs cfg.jobs); + jobs = mkJobs cfg.jobs; }; programs.ssh.knownHosts = diff --git a/npins/sources.json b/npins/sources.json index 8dc5bd3..5654356 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -95,9 +95,9 @@ "url": "https://git.hubrecht.ovh/hubrecht/nix-modules.git" }, "branch": "main", - "revision": "0e6d7e13b50a37d2f5e95ff06529292357a11c9d", + "revision": "654a8a5cd185860aa2c77fc97e3630cb75fedeae", "url": null, - "hash": "1366l4qhf1drzr0ccvbdf3w4aa8jwq1pw9909r7wgrpjmqfgm16p" + "hash": "0h0kxs2fg4413yj2fh5l6319vwq1xmfkqd8q179014qvc9fimrvx" }, "nix-patches": { "type": "GitRelease",