2022-12-04 13:45:43 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
2023-08-09 15:11:04 +01:00
|
|
|
config,
|
2023-09-18 03:56:58 +01:00
|
|
|
hostSecrets,
|
2022-12-04 13:45:43 +00:00
|
|
|
...
|
|
|
|
}: let
|
2023-09-18 03:56:58 +01:00
|
|
|
secrets = hostSecrets;
|
|
|
|
mailConfig = config.services.mailserver;
|
2022-08-12 17:06:50 +01:00
|
|
|
backupPrepareCommand = "${
|
2022-12-04 13:45:43 +00:00
|
|
|
(pkgs.writeShellScriptBin "backupPrepareCommand" ''
|
2023-08-09 15:11:04 +01:00
|
|
|
systemctl start postgresqlBackup-roundcube --wait
|
2022-12-04 13:45:43 +00:00
|
|
|
'')
|
|
|
|
}/bin/backupPrepareCommand";
|
2022-11-02 11:32:03 +00:00
|
|
|
in {
|
2023-08-01 19:48:37 +01:00
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
restic
|
2023-08-09 15:11:04 +01:00
|
|
|
(pkgs.writeShellScriptBin "restic-mail" ''
|
2022-11-02 11:32:03 +00:00
|
|
|
env \
|
2023-08-09 15:11:04 +01:00
|
|
|
RESTIC_PASSWORD_FILE=${secrets.mail_restic_password.path} \
|
|
|
|
$(cat ${secrets.mail_restic_env.path}) \
|
2022-11-02 11:32:03 +00:00
|
|
|
${pkgs.restic}/bin/restic $@
|
|
|
|
'')
|
|
|
|
];
|
2022-08-04 21:53:51 +01:00
|
|
|
|
2023-08-09 15:11:04 +01:00
|
|
|
services.restic.backups.mail = {
|
2022-11-02 11:32:03 +00:00
|
|
|
user = "root";
|
|
|
|
paths = [
|
|
|
|
"/var/backup/postgresql"
|
2022-08-04 16:58:49 +01:00
|
|
|
|
2023-09-18 03:56:58 +01:00
|
|
|
mailConfig.vmail.directory
|
|
|
|
mailConfig.sieveDirectory
|
|
|
|
mailConfig.dkim.directory
|
2022-11-02 11:32:03 +00:00
|
|
|
"/var/lib/redis-rspamd"
|
|
|
|
];
|
|
|
|
|
|
|
|
# repository is overrided in environmentFile to contain auth
|
|
|
|
# make sure to keep up to date when changing repository
|
2023-08-09 15:11:04 +01:00
|
|
|
repository = "rest:https://storage-restic.owo.monster/Mail";
|
|
|
|
passwordFile = "${secrets.mail_restic_password.path}";
|
|
|
|
environmentFile = "${secrets.mail_restic_env.path}";
|
2022-11-02 11:32:03 +00:00
|
|
|
|
2023-07-29 16:41:20 +01:00
|
|
|
pruneOpts = [
|
2023-08-09 15:11:04 +01:00
|
|
|
"--keep-last 5"
|
2023-07-29 16:41:20 +01:00
|
|
|
];
|
|
|
|
|
2022-11-02 11:32:03 +00:00
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "1m";
|
|
|
|
OnCalendar = "daily";
|
|
|
|
};
|
|
|
|
|
|
|
|
inherit backupPrepareCommand;
|
|
|
|
};
|
2022-08-04 21:53:51 +01:00
|
|
|
|
2023-08-09 15:11:04 +01:00
|
|
|
services.postgresql.enable = true;
|
2022-08-04 21:53:51 +01:00
|
|
|
services.postgresqlBackup = {
|
|
|
|
enable = true;
|
2022-11-23 15:58:12 +00:00
|
|
|
backupAll = false;
|
2023-08-09 15:11:04 +01:00
|
|
|
databases = ["roundcube"];
|
2022-08-04 21:53:51 +01:00
|
|
|
compression = "zstd";
|
|
|
|
};
|
2021-12-29 13:17:01 +00:00
|
|
|
}
|