Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Terraria server shutdown and restart (optional, customize these variables)
- TMODLOADER_SESSION="tmodloader"
- SERVER_START_SCRIPT="/home/terraria/DedicatedServerUtils/manage-tModLoaderServer.sh start"
- # Configuration (Customize these variables for backup)
- WORLD_DIR="/home/terraria/DedicatedServerUtils/Worlds"
- RCLONE_REMOTE="tmodworldbakup"
- BACKUP_DIR="serverbak/tmodworldbackup"
- LOG_FILE="/home/terraria/rclone_tmod_backup.log"
- # Create timestamped archive directory for deleted files
- ARCHIVE_DIR="$RCLONE_REMOTE:serverbak/old_backups/$(date +%Y%m%d_%H%M%S)"
- # Check if the world directory exists
- if [ ! -d "$WORLD_DIR" ]; then
- echo "Error: World directory '$WORLD_DIR' not found."
- exit 1
- fi
- # Stop the Terraria server (optional)
- if [ ! -z "$TMODLOADER_SESSION" ] && [ ! -z "$SERVER_START_SCRIPT" ]; then
- echo "Stopping Terraria server..."
- screen -X -S "$TMODLOADER_SESSION" stuff "exit\n"
- sleep 120
- # Check if the session is still running (optional)
- screen -list | grep -q "$TMODLOADER_SESSION"
- if [[ $? -eq 0 ]]; then
- echo " Server shutdown timed out, forcefully terminating..."
- screen -X -S "$TMODLOADER_SESSION" kill
- fi
- sleep 20
- fi
- # Perform the rclone sync
- echo "Backing up Terraria worlds..."
- rclone sync "$WORLD_DIR" "$RCLONE_REMOTE:$BACKUP_DIR" \
- --progress \
- --transfers 32 \
- --checkers 16 \
- --exclude "*.bak" \
- --log-file "$LOG_FILE" \
- --backup-dir "$ARCHIVE_DIR"
- # Check the exit code of rclone
- if [ $? -eq 0 ]; then
- echo "Terraria world backup completed successfully. Log: $LOG_FILE"
- if [ ! -z "$SERVER_START_SCRIPT" ]; then
- echo "Restarting Terraria server..."
- screen -dmS "$TMODLOADER_SESSION" "$SERVER_START_SCRIPT"
- fi
- else
- echo "Error: Terraria world backup failed. Check the log: $LOG_FILE"
- exit 1
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement