diff options
Diffstat (limited to 'systems/backup-2/databases')
4 files changed, 22 insertions, 8 deletions
diff --git a/systems/backup-2/databases/mariadb_replication.nix b/systems/backup-2/databases/mariadb_replication.nix index f113219..c085682 100644 --- a/systems/backup-2/databases/mariadb_replication.nix +++ b/systems/backup-2/databases/mariadb_replication.nix | |||
@@ -163,6 +163,9 @@ in | |||
163 | --flush-privileges \ | 163 | --flush-privileges \ |
164 | --all-databases > $filename | 164 | --all-databases > $filename |
165 | ${pkgs.gzip}/bin/gzip $filename | 165 | ${pkgs.gzip}/bin/gzip $filename |
166 | |||
167 | mkdir -p "${cfg.base}/${name}/databases_latest_backups" | ||
168 | ln -f "$filename.gz" "${cfg.base}/${name}/databases_latest_backups/mysql.sql.gz" | ||
166 | ''; | 169 | ''; |
167 | u = pkgs.callPackage ./utils.nix {}; | 170 | u = pkgs.callPackage ./utils.nix {}; |
168 | cleanup_script = pkgs.writeScript "cleanup_mysql_${name}" (u.exponentialDumps "sql.gz" backupDir); | 171 | cleanup_script = pkgs.writeScript "cleanup_mysql_${name}" (u.exponentialDumps "sql.gz" backupDir); |
@@ -194,7 +197,7 @@ in | |||
194 | } | 197 | } |
195 | ) cfg.hosts; | 198 | ) cfg.hosts; |
196 | 199 | ||
197 | environment.systemPackages = lib.mapAttrsToList (name: hcfg: | 200 | environment.systemPackages = [ pkgs.mariadb ] ++ lib.mapAttrsToList (name: hcfg: |
198 | pkgs.writeScriptBin "mysql_backup_${name}" '' | 201 | pkgs.writeScriptBin "mysql_backup_${name}" '' |
199 | #!${pkgs.stdenv.shell} | 202 | #!${pkgs.stdenv.shell} |
200 | 203 | ||
diff --git a/systems/backup-2/databases/openldap_replication.nix b/systems/backup-2/databases/openldap_replication.nix index b962224..d3cda1c 100644 --- a/systems/backup-2/databases/openldap_replication.nix +++ b/systems/backup-2/databases/openldap_replication.nix | |||
@@ -121,7 +121,11 @@ in | |||
121 | backup_script = pkgs.writeScript "backup_openldap_${name}" '' | 121 | backup_script = pkgs.writeScript "backup_openldap_${name}" '' |
122 | #!${pkgs.stdenv.shell} | 122 | #!${pkgs.stdenv.shell} |
123 | 123 | ||
124 | ${hcfg.package}/bin/slapcat -b "${hcfg.base}" -f ${ldapConfig hcfg name} -l ${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).ldif | 124 | filename="${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).ldif" |
125 | ${hcfg.package}/bin/slapcat -b "${hcfg.base}" -f ${ldapConfig hcfg name} -l "$filename" | ||
126 | |||
127 | mkdir -p "${cfg.base}/${name}/databases_latest_backups" | ||
128 | ln -f "$filename" "${cfg.base}/${name}/databases_latest_backups/openldap.ldif" | ||
125 | ''; | 129 | ''; |
126 | u = pkgs.callPackage ./utils.nix {}; | 130 | u = pkgs.callPackage ./utils.nix {}; |
127 | cleanup_script = pkgs.writeScript "cleanup_openldap_${name}" (u.exponentialDumps "ldif" backupDir); | 131 | cleanup_script = pkgs.writeScript "cleanup_openldap_${name}" (u.exponentialDumps "ldif" backupDir); |
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 | }; |
diff --git a/systems/backup-2/databases/redis_replication.nix b/systems/backup-2/databases/redis_replication.nix index 53fa904..1088630 100644 --- a/systems/backup-2/databases/redis_replication.nix +++ b/systems/backup-2/databases/redis_replication.nix | |||
@@ -114,8 +114,11 @@ in | |||
114 | backup_script = pkgs.writeScript "backup_redis_${name}" '' | 114 | backup_script = pkgs.writeScript "backup_redis_${name}" '' |
115 | #!${pkgs.stdenv.shell} | 115 | #!${pkgs.stdenv.shell} |
116 | 116 | ||
117 | ${pkgs.coreutils}/bin/cp ${cfg.base}/${name}/redis/dump.rdb \ | 117 | filename="${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).rdb" |
118 | ${backupDir}/$(${pkgs.coreutils}/bin/date -Iminutes).rdb | 118 | ${pkgs.coreutils}/bin/cp ${cfg.base}/${name}/redis/dump.rdb "$filename" |
119 | |||
120 | mkdir -p "${cfg.base}/${name}/databases_latest_backups" | ||
121 | ln -f "$filename" "${cfg.base}/${name}/databases_latest_backups/redis.rdb" | ||
119 | ''; | 122 | ''; |
120 | u = pkgs.callPackage ./utils.nix {}; | 123 | u = pkgs.callPackage ./utils.nix {}; |
121 | cleanup_script = pkgs.writeScript "cleanup_redis_${name}" (u.exponentialDumps "rdb" backupDir); | 124 | cleanup_script = pkgs.writeScript "cleanup_redis_${name}" (u.exponentialDumps "rdb" backupDir); |