From 5ad86d90df0d9efd6eef10873d7415b003e0e12b Mon Sep 17 00:00:00 2001 From: Chris Toph Date: Fri, 18 Apr 2025 15:20:55 -0400 Subject: [PATCH] Optimizes backup script for switch emulators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixes parameter error from compression tool command • Implements incremental sleep in periodic backups for faster process exit detection • Increases backup count for emulator configurations from 20 to 30 --- .../toph/common/optional/gaming/scripts/backup.nix | 14 +++++++++++--- home/toph/common/optional/gaming/switch.nix | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/home/toph/common/optional/gaming/scripts/backup.nix b/home/toph/common/optional/gaming/scripts/backup.nix index f9333d4..951db00 100644 --- a/home/toph/common/optional/gaming/scripts/backup.nix +++ b/home/toph/common/optional/gaming/scripts/backup.nix @@ -15,7 +15,7 @@ pkgs.writeScript "backup-wrapper" '' echo "→ Creating backup: $outfile" tar cf - $src | - ${pkgs.zstd}/bin/zstd -- -c -T5 -15 -v > $outfile + ${pkgs.zstd}/bin/zstd -c -T5 -15 -v > $outfile # Rotate: keep only the newest $max_backups set files (ls -1t $dest/backup-*.tar.zst) @@ -28,8 +28,16 @@ pkgs.writeScript "backup-wrapper" '' end function periodic_backups --argument-names pid - while test -d /proc/$pid - sleep $interval + while true + # sleep in 1s increments so we can detect process exit early + for i in (seq 1 $interval) + if not test -d /proc/$pid + return + end + sleep 1 + end + + # If we're still here, do the interval backup echo "Interval backup at "(date) backup end diff --git a/home/toph/common/optional/gaming/switch.nix b/home/toph/common/optional/gaming/switch.nix index 4cb725b..ee33b44 100644 --- a/home/toph/common/optional/gaming/switch.nix +++ b/home/toph/common/optional/gaming/switch.nix @@ -27,7 +27,7 @@ in Ryujinx = { name = "Ryubing w/ Backups"; comment = "Ryubing Emulator with Save Backups"; - exec = ''fish ${backup-wrapper} /home/${user}/.config/Ryujinx/bis/user/save /pool/Backups/Switch/RyubingSaves 960 20 -- ryujinx''; # Should amount to be ~8 hours of playtime in 30 backups + exec = ''fish ${backup-wrapper} /home/${user}/.config/Ryujinx/bis/user/save /pool/Backups/Switch/RyubingSaves 960 30 -- ryujinx''; # Should amount to be ~8 hours of playtime in 30 backups icon = "Ryujinx"; type = "Application"; terminal = false; @@ -52,7 +52,7 @@ in citron-emu = { name = "Citron w/ Backups"; comment = "Citron Emulator with Save Backups"; - exec = ''fish ${backup-wrapper} /home/${user}/.local/share/citron/nand/user/save /pool/Backups/Switch/CitronSaves 960 20 -- citron-emu''; # Should amount to be ~8 hours of playtime in 30 backups + exec = ''fish ${backup-wrapper} /home/${user}/.local/share/citron/nand/user/save /pool/Backups/Switch/CitronSaves 960 30 -- citron-emu''; # Should amount to be ~8 hours of playtime in 30 backups icon = "applications-games"; type = "Application"; terminal = false;