nixfiles/hosts/hetzner-vm/containers/mail/profiles/restic.nix

62 lines
1.4 KiB
Nix

{
pkgs,
config,
host_secrets,
...
}: let
secrets = host_secrets;
mail_config = config.services.mailserver;
backupPrepareCommand = "${
(pkgs.writeShellScriptBin "backupPrepareCommand" ''
systemctl start postgresqlBackup-roundcube --wait
'')
}/bin/backupPrepareCommand";
in {
environment.systemPackages = with pkgs; [
restic
(pkgs.writeShellScriptBin "restic-mail" ''
env \
RESTIC_PASSWORD_FILE=${secrets.mail_restic_password.path} \
$(cat ${secrets.mail_restic_env.path}) \
${pkgs.restic}/bin/restic $@
'')
];
services.restic.backups.mail = {
user = "root";
paths = [
"/var/backup/postgresql"
mail_config.vmail_config.directory
mail_config.sieve_directory
mail_config.dkim_directory
"/var/lib/redis-rspamd"
];
# repository is overrided in environmentFile to contain auth
# make sure to keep up to date when changing repository
repository = "rest:https://storage-restic.owo.monster/Mail";
passwordFile = "${secrets.mail_restic_password.path}";
environmentFile = "${secrets.mail_restic_env.path}";
pruneOpts = [
"--keep-last 5"
];
timerConfig = {
OnBootSec = "1m";
OnCalendar = "daily";
};
inherit backupPrepareCommand;
};
services.postgresql.enable = true;
services.postgresqlBackup = {
enable = true;
backupAll = false;
databases = ["roundcube"];
compression = "zstd";
};
}