]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/databases/postgresql_replication.nix
Reduce number of postgresql backups
[perso/Immae/Config/Nix.git] / modules / private / databases / postgresql_replication.nix
index cc32c2be448ccad28ec97c872baa1b05c8a968e1..b103b8c0e965d10b6d26201cf0fd662f2799adf7 100644 (file)
@@ -11,6 +11,13 @@ in
         Base path to put the replications
         '';
     };
+    mainPackage = lib.mkOption {
+      type = lib.types.package;
+      default = pkgs.postgresql;
+      description = ''
+        Postgresql package available in shell
+      '';
+    };
     hosts = lib.mkOption {
       default = {};
       description = ''
@@ -43,10 +50,6 @@ in
   };
 
   config = lib.mkIf cfg.enable {
-    nixpkgs.overlays = [ (self: super: {
-      postgresql = self.postgresql_11_custom;
-    }) ];
-
     users.users.postgres = {
       name = "postgres";
       uid = config.ids.uids.postgres;
@@ -57,7 +60,7 @@ in
       extraGroups = [ "keys" ];
     };
     users.groups.postgres.gid = config.ids.gids.postgres;
-    environment.systemPackages = [ pkgs.postgresql ];
+    environment.systemPackages = [ cfg.mainPackage ];
 
     secrets.keys = lib.flatten (lib.mapAttrsToList (name: hcfg: [
       {
@@ -113,10 +116,10 @@ in
 
               ${hcfg.package}/bin/psql -h ${dataDir} -c "SELECT pg_wal_replay_pause();" >/dev/null || (echo "impossible to pause replication" && false)
 
-              ${hcfg.package}/bin/pg_dumpall -h ${dataDir} -f ${backupDir}/$(${pkgs.coreutils}/bin/date -Iseconds).sql
+              ${hcfg.package}/bin/pg_dumpall -h ${dataDir} -f ${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).sql
             '';
           u = pkgs.callPackage ./utils.nix {};
-          cleanup_script = pkgs.writeScript "cleanup_postgresql_${name}" (u.keepLastNDumps backupDir 12);
+          cleanup_script = pkgs.writeScript "cleanup_postgresql_${name}" (u.keepLastNDumps "sql" backupDir 6);
         in [
           "0 22,4,10,16 * * * postgres ${backup_script}"
           "0 3 * * * postgres ${cleanup_script}"