From 8c18ec5341931ef9387ce97ee74e83b4f9b6ad61 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 12 Nov 2022 15:07:39 +0100 Subject: [PATCH] Add a module for utf8mb4 restic db dumps --- .../default.nix | 59 +++++++++++++++++++ systems/nextcloud/default.nix | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 modules/restic-server-mysqlutf8-client/default.nix diff --git a/modules/restic-server-mysqlutf8-client/default.nix b/modules/restic-server-mysqlutf8-client/default.nix new file mode 100644 index 0000000..06f3917 --- /dev/null +++ b/modules/restic-server-mysqlutf8-client/default.nix @@ -0,0 +1,59 @@ +{ custom +, path +, tag ? "home-dir" +, time +}: { config, pkgs, ... }: +{ + imports = [ + (import "${custom.inputs.self}/modules/telegram-notifications" { inherit custom; }) + ]; + + age.secrets.resticKey.file = "${custom.inputs.self}/scrts/restic.key.age"; + + systemd.timers."restic-backups" = { + wantedBy = [ "timers.target" ]; + partOf = [ "restic-backups.service" ]; + timerConfig = { + OnCalendar = time; + }; + }; + + 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=${custom.inputs.self}/modules/restic/excludes.txt \ + --tag ${tag} ${path} + + ${pkgs.mariadb}/bin/mysqldump --default-character-set=utf8mb4 --single-transaction --all-databases | \ + ${pkgs.restic}/bin/restic backup \ + --tag mariadb \ + --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 mariadb \ + --host ${config.networking.hostName} \ + --keep-daily 7 \ + --keep-weekly 5 \ + --keep-monthly 12 \ + --keep-yearly 75 + ''; + }; +} diff --git a/systems/nextcloud/default.nix b/systems/nextcloud/default.nix index 4bf7370..8abd85a 100644 --- a/systems/nextcloud/default.nix +++ b/systems/nextcloud/default.nix @@ -8,7 +8,7 @@ in ip = "10.7.89.103"; inherit custom hostname; }) - (import "${custom.inputs.self}/modules/restic-server-mysql-client" { + (import "${custom.inputs.self}/modules/restic-server-mysqlutf8-client" { path = "/home/andreas"; time = "01:30"; inherit custom; })