From 977846991ac0311271b4bc1fef5adde4156b7df1 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Fri, 19 Jan 2024 20:06:23 +0000 Subject: [PATCH] nixos/simpcraft: Disable autosave during backup --- .../colony/vms/whale2/minecraft/default.nix | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/nixos/boxes/colony/vms/whale2/minecraft/default.nix b/nixos/boxes/colony/vms/whale2/minecraft/default.nix index 29d161d..c611f84 100644 --- a/nixos/boxes/colony/vms/whale2/minecraft/default.nix +++ b/nixos/boxes/colony/vms/whale2/minecraft/default.nix @@ -107,7 +107,11 @@ in }; services = { - borgbackup.jobs.simpcraft = { + borgbackup.jobs.simpcraft = + let + rconCommand = cmd: ''${pkgs.mcrcon}/bin/mcrcon -H simpcraft-oci -p "$RCON_PASSWORD" "${cmd}"''; + in + { paths = [ "/var/lib/containers/storage/volumes/minecraft_data/_data/world" ]; repo = "/var/lib/containers/backup/simpcraft"; doInit = true; @@ -116,9 +120,19 @@ in # every ~15 minutes offset from 5 minute intervals (Minecraft seems to save at precise times?) startAt = "*:03,17,33,47"; prune.keep = { - within = "1d"; + within = "12H"; hourly = 48; }; + + # Avoid Minecraft poking the files while we back up + preHook = rconCommand "save-off"; + postHook = rconCommand "save-on"; + }; + }; + + systemd = { + services = { + borgbackup-job-simpcraft.serviceConfig.EnvironmentFile = [ config.age.secrets."whale2/simpcraft.env".path ]; }; };