1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-31 12:07:48 +00:00

Back up postgresql

This commit is contained in:
RGBCube 2024-04-30 12:56:07 +03:00
parent ccf0c5fee5
commit 2959c04419
No known key found for this signature in database

View file

@ -1,14 +1,28 @@
{ config, lib, ... }: with lib; { config, lib, pkgs, ... }: with lib;
systemConfiguration { systemConfiguration {
secrets.resticPassword.file = ./password.age; secrets.resticPassword.file = ./password.age;
services.restic.backups.general = { services.restic.backups = let
defaultConfig = name: {
repository = "sftp:backup@disk:${config.networking.hostName}-${name}";
passwordFile = config.secrets.resticPassword.path; passwordFile = config.secrets.resticPassword.path;
initialize = true; initialize = true;
repository = "sftp:backup@disk:${config.networking.hostName}-varlib"; pruneOpts = [
"--keep-daily 3"
"--keep-weekly 5"
"--keep-monthly 12"
"--keep-yearly 75"
];
timerConfig = {
OnCalendar = "daily";
Persistent = true;
};
};
in {
general = (defaultConfig "general") // {
paths = map (dir: "/var/lib/${dir}") [ paths = map (dir: "/var/lib/${dir}") [
"dkim" "dkim"
"forgejo" "forgejo"
@ -20,10 +34,20 @@ systemConfiguration {
"nextcloud" "nextcloud"
"postfix" "postfix"
]; ];
};
timerConfig = { postgresql = (defaultConfig "postgresql") // {
OnCalendar = "daily"; paths = [ "/tmp/postgresql-dump.sql.gz" ];
Persistent = true;
backupPrepareCommand = ''
${config.services.postgresql.package}/bin/pg_dumpall --clean \
| ${lib.getExe pkgs.gzip} --rsyncable \
> /tmp/postgresql-dump.sql.gz
'';
backupCleanupCommand = ''
rm /tmp/postgresql-dump.sql.gz
'';
}; };
}; };
} }