2023-09-21 16:59:51 +01:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
secrets = config.services.secrets.secrets;
|
|
|
|
|
|
|
|
backupPrepareCommand = "${
|
|
|
|
(pkgs.writeShellScriptBin "backupPrepareCommand" ''
|
|
|
|
systemctl start postgresqlBackup-piped --wait
|
2023-10-02 03:08:24 +01:00
|
|
|
systemctl start postgresqlBackup-gotosocial --wait
|
|
|
|
systemctl start postgresqlBackup-quassel --wait
|
|
|
|
systemctl start postgresqlBackup-roundcube --wait
|
2023-09-21 16:59:51 +01:00
|
|
|
'')
|
|
|
|
}/bin/backupPrepareCommand";
|
|
|
|
in {
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
restic
|
2023-10-02 03:08:24 +01:00
|
|
|
(pkgs.writeShellScriptBin "restic-postgresql" ''
|
2023-09-21 16:59:51 +01:00
|
|
|
env \
|
|
|
|
RESTIC_PASSWORD_FILE=${secrets.restic_password.path} \
|
|
|
|
$(cat ${secrets.restic_env.path}) \
|
|
|
|
${pkgs.restic}/bin/restic $@
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
|
2023-10-02 03:08:24 +01:00
|
|
|
services.restic.backups.postgresql = {
|
2023-09-21 16:59:51 +01:00
|
|
|
user = "root";
|
|
|
|
paths = [
|
|
|
|
"/var/backup/postgresql"
|
|
|
|
];
|
|
|
|
|
|
|
|
# repository is overrided in environmentFile to contain auth
|
|
|
|
# make sure to keep up to date when changing repository
|
2023-10-02 03:08:24 +01:00
|
|
|
repository = "rest:https://storage-restic.owo.monster/PostgreSQL";
|
2023-09-21 16:59:51 +01:00
|
|
|
passwordFile = "${secrets.restic_password.path}";
|
|
|
|
environmentFile = "${secrets.restic_env.path}";
|
|
|
|
|
|
|
|
pruneOpts = [
|
|
|
|
"--keep-last 5"
|
|
|
|
];
|
|
|
|
|
|
|
|
timerConfig = {
|
|
|
|
OnBootSec = "1m";
|
|
|
|
OnCalendar = "daily";
|
|
|
|
};
|
|
|
|
|
|
|
|
inherit backupPrepareCommand;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresqlBackup = {
|
|
|
|
enable = true;
|
|
|
|
backupAll = false;
|
2023-10-02 03:08:24 +01:00
|
|
|
databases = [
|
|
|
|
"piped"
|
|
|
|
"gotosocial"
|
|
|
|
"quassel"
|
|
|
|
"roundcube"
|
|
|
|
];
|
2023-09-21 16:59:51 +01:00
|
|
|
compression = "zstd";
|
|
|
|
};
|
|
|
|
}
|