fix: make backing up robust and lengthen discord ping

This commit is contained in:
Jet 2026-03-16 14:36:28 -07:00
parent 298d2f10a4
commit 853e6e18a9
No known key found for this signature in database
2 changed files with 18 additions and 9 deletions

View file

@ -27,16 +27,16 @@ in
sleep 2
docker exec minecraft rcon-cli save-off
# Compress world data (re-enable saving even if tar fails)
if ! ${pkgs.gnutar}/bin/tar czf "$TEMP_BACKUP" \
-C ${mcDataDir} world; then
echo "tar failed, re-enabling saving"
docker exec minecraft rcon-cli save-on
exit 1
fi
# Ensure save-on runs no matter how the script exits from here
trap 'docker exec minecraft rcon-cli save-on' EXIT
# Re-enable saving immediately
# Compress world data
${pkgs.gnutar}/bin/tar czf "$TEMP_BACKUP" \
-C ${mcDataDir} world
# Re-enable saving immediately (trap will also fire, but save-on is idempotent)
docker exec minecraft rcon-cli save-on
trap - EXIT
# Upload to B2 (overwrites the single backup file)
B2_ACCOUNT=$(cat ${config.age.secrets.b2-account-id.path})
@ -47,8 +47,17 @@ in
":b2:${b2Bucket}/world-latest.tar.gz" \
--b2-account "$B2_ACCOUNT" \
--b2-key "$B2_KEY" \
--b2-hard-delete \
--config /dev/null \
--no-check-dest
# Purge old file versions to stay under storage cap
${pkgs.rclone}/bin/rclone cleanup \
":b2:${b2Bucket}" \
--b2-account "$B2_ACCOUNT" \
--b2-key "$B2_KEY" \
--config /dev/null
# Clean up local temp file
rm -f "$TEMP_BACKUP"