1
0
forked from clan/clan-core

Compare commits

...

2 Commits

Author SHA1 Message Date
9ea61adb45 wip: postgres 2024-03-25 14:22:23 +01:00
eea276d643 borgbackup: block borgjob is finished
We do not want to start multiple borgbackups in parallel
2024-03-25 14:22:23 +01:00
3 changed files with 58 additions and 1 deletions

View 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")
'';
}
)

View File

@ -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" ''

View 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
'';
};
}