Move restic-client-server-postgres to options

This commit is contained in:
Andreas Zweili 2023-06-06 22:23:20 +02:00
parent cd5eb75830
commit 9913ab5e4e
3 changed files with 76 additions and 53 deletions

View File

@ -41,6 +41,7 @@
./services/restic-client-desktop
./services/restic-client-server
./services/restic-client-server-mysql
./restic-client-server-postgres
./services/syslog
./services/telegram-notifications
./services/tlp

View File

@ -1,56 +1,77 @@
{ path
, tag ? "home-dir"
, time
}: { config, inputs, pkgs, ... }:
{ config, inputs, lib, pkgs, ... }:
let
cfg = config.services.az-restic-client-server-postgres;
in
{
services.az-telegram-notifications.enable = true;
age.secrets.resticKey.file = "${inputs.self}/scrts/restic.key.age";
systemd.timers."restic-backups" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups.service" ];
timerConfig = {
OnCalendar = time;
options = {
services.az-restic-client-server-postgres = {
enable = lib.mkEnableOption "Enable restic backups for PostgreSQL.";
path = lib.mkOption {
type = lib.types.path;
description = "The directory to backup.";
};
tag = lib.mkOption {
type = lib.types.str;
description = "The tag to attach to the backups.";
default = "home-dir";
};
time = lib.mkOption {
type = lib.types.str;
description = "The time at which the backup runs.";
};
};
};
systemd.services."restic-backups" = {
serviceConfig = {
User = "root";
Type = "oneshot";
config = lib.mkIf cfg.enable {
services.az-telegram-notifications.enable = true;
age.secrets.resticKey.file = "${inputs.self}/scrts/restic.key.age";
systemd.timers."restic-backups" = {
wantedBy = [ "timers.target" ];
partOf = [ "restic-backups.service" ];
timerConfig = {
OnCalendar = cfg.time;
};
};
environment = {
RESTIC_PASSWORD_FILE = config.age.secrets.resticKey.path;
RESTIC_REPOSITORY = "rest:http://10.7.89.30:8000";
systemd.services."restic-backups" = {
serviceConfig = {
User = "root";
Type = "oneshot";
};
environment = {
RESTIC_PASSWORD_FILE = config.age.secrets.resticKey.path;
RESTIC_REPOSITORY = "rest:http://10.7.89.30:8000";
};
onFailure = [ "unit-status-telegram@%n.service" ];
script = ''
${pkgs.restic}/bin/restic backup \
--exclude-file=${inputs.self}/modules/misc/restic-client/excludes.txt \
--tag ${cfg.tag} ${cfg.path}
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/pg_dumpall | \
${pkgs.restic}/bin/restic backup \
--tag postgres \
--stdin \
--stdin-filename all_databases.sql
${pkgs.restic}/bin/restic forget \
--tag home-dir \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
${pkgs.restic}/bin/restic forget \
--tag postgres \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
'';
};
onFailure = [ "unit-status-telegram@%n.service" ];
script = ''
${pkgs.restic}/bin/restic backup \
--exclude-file=${inputs.self}/modules/misc/restic-client/excludes.txt \
--tag ${tag} ${path}
${pkgs.sudo}/bin/sudo -u postgres ${pkgs.postgresql}/bin/pg_dumpall | \
${pkgs.restic}/bin/restic backup \
--tag postgres \
--stdin \
--stdin-filename all_databases.sql
${pkgs.restic}/bin/restic forget \
--tag home-dir \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
${pkgs.restic}/bin/restic forget \
--tag postgres \
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
'';
};
}

View File

@ -8,11 +8,6 @@ in
ip = "10.7.89.115";
inherit hostname;
})
(import "${inputs.self}/modules/restic-client-server-postgres" {
path = "/var/lib/ttrss";
tag = "tt-rss";
time = "23:00";
})
"${inputs.self}/modules/rss-bridge"
(import "${inputs.self}/modules/ttrss-postgres" { inherit domain; })
];
@ -22,5 +17,11 @@ in
domain = "rss-bridge.2li.ch";
port = 8082;
};
az-restic-client-server-postgres = {
enable = true;
path = "/var/lib/ttrss";
tag = "tt-rss";
time = "23:00";
};
};
}