nixos/postgresqlBackup: Use PATH for readability

(cherry picked from commit c586e42763e0f093d16b4b655759cb340171ad42)
This commit is contained in:
Robert Hensing 2021-06-04 17:28:20 +02:00 committed by github-actions[bot]
parent c06613c25d
commit 44c232bbeb

View File

@ -14,15 +14,17 @@ let
requires = [ "postgresql.service" ]; requires = [ "postgresql.service" ];
path = [ pkgs.coreutils pkgs.gzip config.services.postgresql.package ];
script = '' script = ''
umask 0077 # ensure backup is only readable by postgres user umask 0077 # ensure backup is only readable by postgres user
if [ -e ${cfg.location}/${db}.sql.gz ]; then if [ -e ${cfg.location}/${db}.sql.gz ]; then
${pkgs.coreutils}/bin/mv ${cfg.location}/${db}.sql.gz ${cfg.location}/${db}.prev.sql.gz mv ${cfg.location}/${db}.sql.gz ${cfg.location}/${db}.prev.sql.gz
fi fi
${dumpCmd} | \ ${dumpCmd} | \
${pkgs.gzip}/bin/gzip -c > ${cfg.location}/${db}.sql.gz gzip -c > ${cfg.location}/${db}.sql.gz
''; '';
serviceConfig = { serviceConfig = {
@ -113,12 +115,12 @@ in {
}) })
(mkIf (cfg.enable && cfg.backupAll) { (mkIf (cfg.enable && cfg.backupAll) {
systemd.services.postgresqlBackup = systemd.services.postgresqlBackup =
postgresqlBackupService "all" "${config.services.postgresql.package}/bin/pg_dumpall"; postgresqlBackupService "all" "pg_dumpall";
}) })
(mkIf (cfg.enable && !cfg.backupAll) { (mkIf (cfg.enable && !cfg.backupAll) {
systemd.services = listToAttrs (map (db: systemd.services = listToAttrs (map (db:
let let
cmd = "${config.services.postgresql.package}/bin/pg_dump ${cfg.pgdumpOptions} ${db}"; cmd = "pg_dump ${cfg.pgdumpOptions} ${db}";
in { in {
name = "postgresqlBackup-${db}"; name = "postgresqlBackup-${db}";
value = postgresqlBackupService db cmd; value = postgresqlBackupService db cmd;