forked from clan/clan-core
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
9ea61adb45 | |||
eea276d643 |
17
checks/postgres/default.nix
Normal file
17
checks/postgres/default.nix
Normal file
@ -0,0 +1,17 @@
|
||||
(import ../lib/container-test.nix) (
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
name = "secrets";
|
||||
|
||||
nodes.machine =
|
||||
{ self, ... }:
|
||||
{
|
||||
imports = [ self.clanModules.postgres ];
|
||||
};
|
||||
testScript = ''
|
||||
start_all()
|
||||
machine.wait_for_unit("postgres")
|
||||
machine.succeed("${pkgs.netcat}/bin/nc -z -v ::1 5432")
|
||||
'';
|
||||
}
|
||||
)
|
@ -94,7 +94,7 @@ in
|
||||
(pkgs.writeShellScriptBin "borgbackup-create" ''
|
||||
set -efu -o pipefail
|
||||
${lib.concatMapStringsSep "\n" (dest: ''
|
||||
systemctl start borgbackup-job-${dest.name}
|
||||
systemctl start --wait borgbackup-job-${dest.name}
|
||||
'') (lib.attrValues cfg.destinations)}
|
||||
'')
|
||||
(pkgs.writeShellScriptBin "borgbackup-list" ''
|
||||
|
40
clanModules/postgresql.nix
Normal file
40
clanModules/postgresql.nix
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
services.postgresql.enable = true;
|
||||
services.postgresqlBackup = {
|
||||
enable = lib.mkDefault true;
|
||||
startAt = lib.mkDefault [ ]; # we will start this as part of the backup
|
||||
compression = "zstd";
|
||||
};
|
||||
clanCore.state.postgres.folders = [ "/var/backup/postgresql" ];
|
||||
|
||||
assertions = [
|
||||
({
|
||||
assertion = config.postgresqlBackup.databases == [ ];
|
||||
message = "We currently do not support backing up specific databases. Please set postgresqlBackup.databases to an empty list. Or disable services.postgresqlBackup.enable";
|
||||
})
|
||||
];
|
||||
|
||||
clanCore.state.postgres.postRestoreScript = ''
|
||||
for dump in /var/backup/postgresql/all*; do
|
||||
case "$dump" in
|
||||
*.gz) decompressionCmd="${pkgs.gzip}/bin/gzip -d -${toString config.services.postgresqlBackup.compressionLevel}" ;;
|
||||
*.zst) decompressionCmd="${pkgs.zstd}/bin/zstd -d -${toString config.services.postgresqlBackup.compressionLevel}" ;;
|
||||
*) decompressionCmd="cat" ;;
|
||||
esac
|
||||
$decompressionCmd $dump | psql template1
|
||||
break
|
||||
done
|
||||
'';
|
||||
|
||||
services.borgbackup.jobs.${config.networking.hostName} = {
|
||||
preHook = ''
|
||||
${pkgs.systemd}/bin/systemctl start postgresqlBackup
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user