Restic: made modular backup declerations.

Required tree-wide re-wiring of the host option.
Now, rather than each host having a monolithic restic.nix file,
the hosts restic.nix file just specifies the password and url of the
restic repository. Eatch module then definies specific paths to backup
and any pre and post commands that need to be performed.
Each backed up service gets an independent systemd backup service and
timer.
This commit is contained in:
Gabe Venberg 2025-04-13 15:27:25 +02:00
parent cf33c036dd
commit 48c60629ab
36 changed files with 307 additions and 1476 deletions

View file

@ -4,7 +4,23 @@
pkgs,
lib,
...
}: {
}: let
preBackup = pkgs.writeShellScriptBin "mc-docker-pre-backup" ''
set -euxo pipefail
docker exec minecraft rcon-cli "say server backing up, expect minor lag"
sleep 10
docker exec minecraft rcon-cli "save-all flush"
docker exec minecraft rcon-cli "save-off"
sleep 10
'';
postBackup = pkgs.writeShellScriptBin "mc-docker-post-backup" ''
set -euxo pipefail
docker exec minecraft rcon-cli "save-on"
docker exec minecraft rcon-cli "say server backup succsessful!"
'';
in {
virtualisation.oci-containers = {
backend = "docker";
containers.minecraft = {
@ -31,7 +47,7 @@
# SETUP_ONLY = "true";
MOTD = "Welcome!";
DIFFICULTY = "normal";
OPS ="TheToric";
OPS = "TheToric";
ENFORCE_WHITELIST = "true";
ENABLE_WHITELIST = "true";
ANNOUNCE_PLAYER_ACHIEVEMENTS = "true";
@ -42,6 +58,13 @@
extraOptions = ["--stop-timeout=60"];
};
};
host.restic.backups.minecraft = {
preBackupCommands = "${preBackup}/bin/mc-docker-pre-backup";
postBackupCommands = "${postBackup}/bin/mc-docker-post-backup";
paths = ["/storage/minecraft"];
};
imports = [
./docker.nix
];