Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(profiles/entropia-cluster-vm): actually backup postgres db #15

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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://borgbackup@zweitwohnsitz.entropia.de/./${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
'';
xanderio marked this conversation as resolved.
Show resolved Hide resolved
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 - - -"
];
}
Loading