diff --git a/start_server_managed.sh b/start_server_managed.sh index 38e126a..e542a15 100644 --- a/start_server_managed.sh +++ b/start_server_managed.sh @@ -2,11 +2,41 @@ cat > "${VALHEIMDIR}/start_server_managed.sh" << 'EOF' #!/usr/bin/env bash set -euo pipefail +# ------------------------- +# BACKUP FUNCTION + LOOP +# ------------------------- + +backup_world() { + echo "[backup] backing up world directory..." + ts=$(date +"%Y-%m-%d_%H-%M-%S") + + world_dir="/root/.config/unity3d/IronGate/Valheim/worlds_local/${WORLD_NAME}" + + if [ -d "${world_dir}" ]; then + mkdir -p "/mnt/backups" + zip -r "/mnt/backups/${WORLD_NAME}_${ts}.zip" "${world_dir}" + echo "[backup] created /mnt/backups/${WORLD_NAME}_${ts}.zip" + else + echo "[backup] WARNING: world directory not found: ${world_dir}" + fi +} + +# Run backups every hour in background +while true; do + sleep 3600 + backup_world +done & + +# ------------------------- +# START SERVER +# ------------------------- + # Forward environment variables into the BepInEx launcher exec ./start_server_bepinex.sh \ -name "${SERVER_NAME}" \ -port 2456 \ -world "${WORLD_NAME}" \ + -savedir "/root/.config/unity3d/IronGate/Valheim/worlds_local" \ -password "${SERVER_PASSWORD}" \ -public "${PUBLIC}" EOF