2023-09-21 16:59:51 +01:00
|
|
|
{
|
2024-03-09 22:18:26 +00:00
|
|
|
self,
|
2023-09-21 16:59:51 +01:00
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
2024-03-10 17:26:18 +00:00
|
|
|
inherit (config.services.secrets) secrets;
|
2024-03-09 22:18:26 +00:00
|
|
|
backupSchedules = import "${self}/data/backupSchedules.nix";
|
2023-09-21 16:59:51 +01:00
|
|
|
|
|
|
|
backupPrepareCommand = "${
|
|
|
|
(pkgs.writeShellScriptBin "backupPrepareCommand" ''
|
2023-10-16 20:02:47 +01:00
|
|
|
systemctl start remotePostgreSQLBackup-gotosocial --wait
|
|
|
|
systemctl start remotePostgreSQLBackup-quassel --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}";
|
|
|
|
|
2024-03-09 22:18:26 +00:00
|
|
|
pruneOpts = ["--keep-last 10"];
|
|
|
|
timerConfig = backupSchedules.restic.high;
|
2023-09-21 16:59:51 +01:00
|
|
|
|
|
|
|
inherit backupPrepareCommand;
|
|
|
|
};
|
|
|
|
|
2023-10-10 22:22:54 +01:00
|
|
|
services.postgreSQLRemoteBackup = {
|
2023-09-21 16:59:51 +01:00
|
|
|
enable = true;
|
2023-10-10 22:22:54 +01:00
|
|
|
backupUser = "postgres";
|
2023-10-02 03:08:24 +01:00
|
|
|
databases = [
|
|
|
|
"gotosocial"
|
|
|
|
"quassel"
|
|
|
|
];
|
2023-09-21 16:59:51 +01:00
|
|
|
};
|
|
|
|
}
|