Skip to content

Commit

Permalink
feat(profiles/entropia-cluster-vm): actually backup postgres db
Browse files Browse the repository at this point in the history
  • Loading branch information
leona-ya committed May 19, 2024
1 parent 280940e commit 5985a3b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions profiles/entropia-cluster-vm/backup.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ config, ... }: {
{ config, lib, pkgs, ... }: {
x.sops.secrets."hosts/${config.networking.hostName}/backup_zweitwohnsitz_password" = {};

services.borgbackup.jobs.zweitwohnsitz = {
paths = [ "/var/lib" "/root" ];
paths = [ "/var/backup" "/var/lib" "/root" ];
exclude = [ "'**/.cache'" ];
doInit = true;
repo = "ssh://[email protected]/./${config.networking.hostName}.${config.networking.domain}";
Expand All @@ -14,7 +14,19 @@
BORG_RSH = "ssh -i /etc/ssh/ssh_host_ed25519_key";
BORG_RELOCATED_REPO_ACCESS_IS_OK = "yes";
};
preHook = lib.mkIf config.services.postgresql.enable ''
${lib.getExe pkgs.sudo} -u postgres ${pkgs.postgresql}/bin/pg_dumpall --globals-only > /var/backup/postgresql/globals
${lib.getExe pkgs.sudo} -u postgres ${pkgs.postgresql}/bin/psql -t -A -c "SELECT datname FROM pg_database WHERE datname <> ALL ('{template0,template1,postgres}')" | ${pkgs.findutils}/bin/xargs -I DBNAME ${lib.getExe pkgs.sudo} -u postgres ${pkgs.postgresql}/bin/pg_dump -F directory -f /var/backup/postgresql/DBNAME DBNAME
'';
postCreate = lib.mkIf config.services.postgresql.enable ''
rm -r /var/backup/postgresql/*
'';
readWritePaths = lib.optionals config.services.postgresql.enable [ "/var/backup/postgresql" ];
compression = "auto,zlib";
startAt = "daily";
};

systemd.tmpfiles.rules = lib.mkIf config.services.postgresql.enable [
"d /var/backup/postgresql 0700 postgres - - -"
];
}

0 comments on commit 5985a3b

Please sign in to comment.