-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from entropia/entropia-cluster-vm-postgres-backup
feat(profiles/entropia-cluster-vm): actually backup postgres db
- Loading branch information
Showing
1 changed file
with
14 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | ||
|
@@ -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 - - -" | ||
]; | ||
} |