nixos/modules/restic-server-mysql-client/default.nix

60 lines
1.5 KiB
Nix
Raw Normal View History

2022-11-04 19:35:57 +01:00
{ custom
2022-11-04 16:49:46 +01:00
, path
, tag ? "home-dir"
, time
2022-11-04 16:49:46 +01:00
}: { config, pkgs, ... }:
{
imports = [
2022-11-04 19:35:57 +01:00
(import "${custom.inputs.self}/modules/telegram-notifications" { inherit custom; })
];
2022-11-04 16:49:46 +01:00
2022-11-04 19:35:57 +01:00
age.secrets.resticKey.file = "${custom.inputs.self}/scrts/restic.key.age";
2022-11-04 16:49:46 +01:00
systemd.timers."restic-backups" = {
wantedBy = [ "timers.target" ];
2022-11-04 16:49:46 +01:00
partOf = [ "restic-backups.service" ];
timerConfig = {
OnCalendar = time;
};
};
2022-11-04 16:49:46 +01:00
systemd.services."restic-backups" = {
serviceConfig = {
User = "root";
Type = "oneshot";
};
environment = {
2022-11-04 16:49:46 +01:00
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 \
2022-11-04 19:35:57 +01:00
--exclude-file=${custom.inputs.self}/modules/restic/excludes.txt \
--tag ${tag} ${path}
${pkgs.mariadb}/bin/mysqldump --single-transaction --all-databases | \
${pkgs.restic}/bin/restic backup \
2022-08-23 21:29:45 +02:00
--tag mariadb \
--stdin \
--stdin-filename all_databases.sql
${pkgs.restic}/bin/restic forget \
2022-08-23 21:29:45 +02:00
--tag home-dir \
2022-11-04 16:49:46 +01:00
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
${pkgs.restic}/bin/restic forget \
2022-08-23 21:29:45 +02:00
--tag mariadb \
2022-11-04 16:49:46 +01:00
--host ${config.networking.hostName} \
--keep-daily 7 \
--keep-weekly 5 \
--keep-monthly 12 \
--keep-yearly 75
'';
};
}