From 3773beab412ec68639611689db69a88443b95a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Wed, 29 Jan 2025 22:46:04 -0300 Subject: [PATCH] factorio: auto backup the game saves --- hosts/monolith/factorio-server.nix | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/hosts/monolith/factorio-server.nix b/hosts/monolith/factorio-server.nix index 211e746..8ed0324 100644 --- a/hosts/monolith/factorio-server.nix +++ b/hosts/monolith/factorio-server.nix @@ -1,4 +1,9 @@ -{ config, pkgs, ... }: +{ + config, + pkgs, + lib, + ... +}: { services.factorio = { enable = true; @@ -15,6 +20,28 @@ wants = [ "network-online.target" ]; }; + systemd.services.factorio-backup-save = { + description = "Backup factorio saves"; + script = '' + ${lib.getExe pkgs.rsync} \ + -av \ + --chown=lelgenio \ + /var/lib/factorio/saves/default.zip \ + ~lelgenio/Documentos/GameSaves/factorio_saves/space-age-$(date --iso=seconds).zip + ''; + serviceConfig.Type = "oneshot"; + wantedBy = [ "multi-user.target" ]; + }; + + systemd.timers.factorio-backup-save = { + timerConfig = { + OnCalendar = "*-*-* 18:00:00"; + Persistent = true; + Unit = "factorio-backup-save.service"; + }; + wantedBy = [ "timers.target" ]; + }; + age.secrets.factorio-settings = { file = ../../secrets/factorio-settings.age; mode = "777";