2022-04-10 11:54:58 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(lib)
|
2022-01-11 16:08:21 +01:00
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
2022-04-10 11:54:58 +02:00
|
|
|
;
|
2022-01-11 16:08:21 +01:00
|
|
|
|
2021-01-30 22:15:33 +01:00
|
|
|
cfg = config.my.services.postgresql-backup;
|
|
|
|
in {
|
|
|
|
options.my.services.postgresql-backup = {
|
|
|
|
enable = mkEnableOption "Backup SQL databases";
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.postgresqlBackup = {
|
|
|
|
enable = true;
|
2021-08-09 20:01:33 +02:00
|
|
|
# Restic backup starts at midnight so create DB dump just before
|
2021-01-30 22:15:33 +01:00
|
|
|
startAt = "*-*-* 23:30:00";
|
|
|
|
};
|
2021-01-31 13:00:04 +01:00
|
|
|
|
2021-08-09 20:01:33 +02:00
|
|
|
my.services.restic-backup = mkIf cfg.enable {
|
2022-04-10 11:54:58 +02:00
|
|
|
paths = ["/var/backup/postgresql"];
|
2021-01-31 13:00:04 +01:00
|
|
|
|
|
|
|
# no need to store previously backed up files, as borg does the snapshoting
|
|
|
|
# for us
|
2022-04-10 11:54:58 +02:00
|
|
|
exclude = ["/var/backup/postgresql/*.prev.sql.gz"];
|
2021-01-31 13:00:04 +01:00
|
|
|
};
|
2021-01-30 22:15:33 +01:00
|
|
|
};
|
|
|
|
}
|