diff options
Diffstat (limited to 'systems/backup-2/databases/postgresql_replication.nix')
-rw-r--r-- | systems/backup-2/databases/postgresql_replication.nix | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/systems/backup-2/databases/postgresql_replication.nix b/systems/backup-2/databases/postgresql_replication.nix index 5351a4f..b428533 100644 --- a/systems/backup-2/databases/postgresql_replication.nix +++ b/systems/backup-2/databases/postgresql_replication.nix | |||
@@ -127,19 +127,23 @@ in | |||
127 | set -euo pipefail | 127 | set -euo pipefail |
128 | 128 | ||
129 | resume_replication() { | 129 | resume_replication() { |
130 | ${hcfg.package}/bin/psql -h ${dataDir} -c "SELECT pg_wal_replay_resume();" >/dev/null || echo "impossible to resume replication" | 130 | sudo -u postgres ${hcfg.package}/bin/psql -h ${dataDir} -c "SELECT pg_wal_replay_resume();" >/dev/null || echo "impossible to resume replication" |
131 | } | 131 | } |
132 | 132 | ||
133 | trap resume_replication EXIT | 133 | trap resume_replication EXIT |
134 | 134 | ||
135 | ${hcfg.package}/bin/psql -h ${dataDir} -c "SELECT pg_wal_replay_pause();" >/dev/null || (echo "impossible to pause replication" && false) | 135 | sudo -u postgres ${hcfg.package}/bin/psql -h ${dataDir} -c "SELECT pg_wal_replay_pause();" >/dev/null || (echo "impossible to pause replication" && false) |
136 | 136 | ||
137 | ${hcfg.package}/bin/pg_dumpall -h ${dataDir} -f ${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).sql | 137 | filename=${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).sql |
138 | sudo -u postgres ${hcfg.package}/bin/pg_dumpall -h ${dataDir} -f "$filename" | ||
139 | |||
140 | mkdir -p "${cfg.base}/${name}/databases_latest_backups" | ||
141 | ln -f "$filename" "${cfg.base}/${name}/databases_latest_backups/postgresql.sql" | ||
138 | ''; | 142 | ''; |
139 | u = pkgs.callPackage ./utils.nix {}; | 143 | u = pkgs.callPackage ./utils.nix {}; |
140 | cleanup_script = pkgs.writeScript "cleanup_postgresql_${name}" (u.keepLastNDumps "sql" backupDir 6); | 144 | cleanup_script = pkgs.writeScript "cleanup_postgresql_${name}" (u.keepLastNDumps "sql" backupDir 6); |
141 | in [ | 145 | in [ |
142 | "0 22,4,10,16 * * * postgres ${backup_script}" | 146 | "0 22,4,10,16 * * * root ${backup_script}" |
143 | "0 3 * * * postgres ${cleanup_script}" | 147 | "0 3 * * * postgres ${cleanup_script}" |
144 | ]) cfg.hosts); | 148 | ]) cfg.hosts); |
145 | }; | 149 | }; |