added retention to podman-postgresql backup
This commit is contained in:
parent
7593d9efc8
commit
529656f317
1 changed files with 12 additions and 1 deletions
|
|
@ -61,6 +61,13 @@ in
|
|||
example = "daily";
|
||||
};
|
||||
|
||||
backupRetention = mkOption {
|
||||
description = "The amount of backups to keep.";
|
||||
type = types.int;
|
||||
default = 28;
|
||||
example = "2";
|
||||
};
|
||||
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
|
@ -101,7 +108,11 @@ in
|
|||
description = "Backup of ${cfg.database} database";
|
||||
requisite = [ "podman-postgresql-${cfg.database}.service" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.bash}/bin/bash -c '${pkgs.podman}/bin/podman exec postgresql-${cfg.database} pg_dumpall -c -U ${cfg.user} | ${pkgs.zstd}/bin/zstd -o ${cfg.backupPath}/${cfg.database}/\$(${pkgs.coreutils}/bin/date +%%F_%%R).sql.zst'" ;
|
||||
ExecStart =
|
||||
let
|
||||
retention = (toString cfg.backupRetention);
|
||||
in
|
||||
"${pkgs.bash}/bin/bash -c '${pkgs.podman}/bin/podman exec postgresql-${cfg.database} pg_dumpall -c -U ${cfg.user} | ${pkgs.zstd}/bin/zstd -o ${cfg.backupPath}/${cfg.database}/\$(${pkgs.coreutils}/bin/date +%%F_%%R).sql.zst && find ${cfg.backupPath}/${cfg.database} -type f | sort | head -n -${retention} | xargs rm -v'" ;
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue