Skip to main content
Back to Category

Game Server Backup and Restore

Game server automatic backup, cron configuration, remote backup with rsync, and world file management guide.

Read time: 12 dk Game Server Setup
backuprestorecronrsyncworld filegame server

Table of Contents

Introduction

Game server backup is the most critical step in preventing data loss. World files, player data, configuration files, and mod/plugin settings should be backed up regularly. This guide covers automatic backup scripts, cron configuration, remote backup with rsync, and world file management for different game servers.

Backup Strategy

3-2-1 Rule

  • 3 copies: Original + 2 backups
  • 2 different media: Local disk + remote server
  • 1 offsite: Backup at a different location

Backup Types

TypeDescriptionAdvantageDisadvantage
FullBacks up all filesEasy restoreLarge size
IncrementalOnly changed filesSmall sizeComplex restore
DifferentialChanges since last fullMedium sizeMedium complexity

Automatic Backup Script

General Purpose Backup

hljs bash
nano ~/backup_gameserver.sh
hljs bash
#!/bin/bash
GAME_NAME=${1:-"gameserver"}
BACKUP_BASE="/home/steam/backups"
DATE=$(date +%Y%m%d_%H%M%S)
RETENTION_DAYS=7
LOG="/home/steam/backup.log"

declare -A SAVE_DIRS
SAVE_DIRS[minecraft]="/home/steam/minecraft/world /home/steam/minecraft/plugins"
SAVE_DIRS[rust]="/home/steam/rustserver/server/rust /home/steam/rustserver/oxide"
SAVE_DIRS[fivem]="/home/steam/fxserver/resources /home/steam/fxserver/server-data"
SAVE_DIRS[vrising]="/home/steam/vrising/save-data"
SAVE_DIRS[satisfactory]="/home/steam/satisfactory/.config/Epic/FactoryServer/Saved/SaveGames"
SAVE_DIRS[pz]="/home/steam/Zomboid/Saves /home/steam/Zomboid/Server"
SAVE_DIRS[enshrouded]="/home/steam/enshrouded/savegame"

BACKUP_DIR="$BACKUP_BASE/$GAME_NAME"
mkdir -p "$BACKUP_DIR"

echo "$(date): Starting $GAME_NAME backup..." >> $LOG

if [ -n "${SAVE_DIRS[$GAME_NAME]}" ]; then
    tar -czf "$BACKUP_DIR/${GAME_NAME}_${DATE}.tar.gz" ${SAVE_DIRS[$GAME_NAME]} 2>/dev/null
    if [ $? -eq 0 ]; then
        SIZE=$(du -h "$BACKUP_DIR/${GAME_NAME}_${DATE}.tar.gz" | cut -f1)
        echo "$(date): Backup successful - $SIZE" >> $LOG
    else
        echo "$(date): ERROR - Backup failed!" >> $LOG
    fi
else
    echo "$(date): ERROR - Unknown game: $GAME_NAME" >> $LOG
    exit 1
fi

find "$BACKUP_DIR" -name "*.tar.gz" -mtime +$RETENTION_DAYS -delete
COUNT=$(find "$BACKUP_DIR" -name "*.tar.gz" | wc -l)
echo "$(date): Cleanup done. Current backup count: $COUNT" >> $LOG
hljs bash
chmod +x ~/backup_gameserver.sh

Cron Automatic Backup

Crontab Configuration

hljs bash
crontab -e
hljs cron
# Backup Minecraft every 4 hours
0 */4 * * * /home/steam/backup_gameserver.sh minecraft

# Backup Rust every 6 hours
0 */6 * * * /home/steam/backup_gameserver.sh rust

# Daily FiveM backup
0 3 * * * /home/steam/backup_gameserver.sh fivem

# Daily V Rising backup
0 4 * * * /home/steam/backup_gameserver.sh vrising

# Weekly full backup (Sunday 02:00)
0 2 * * 0 /home/steam/backup_full.sh

Cron Expression Guide

# minute (0-59) | hour (0-23) | day (1-31) | month (1-12) | weekday (0-7)
# * * * * * command

Remote Backup with rsync

rsync Installation

hljs bash
sudo apt install rsync -y

Backup to Remote Server

hljs bash
nano ~/remote_backup.sh
hljs bash
#!/bin/bash
REMOTE_HOST="backup.example.com"
REMOTE_USER="backup"
REMOTE_DIR="/backups/gameserver"
LOCAL_DIR="/home/steam/backups"
LOG="/home/steam/remote_backup.log"

echo "$(date): Starting remote backup..." >> $LOG

rsync -avz --delete \
  -e "ssh -p 22 -i /home/steam/.ssh/backup_key" \
  "$LOCAL_DIR/" \
  "$REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR/"

if [ $? -eq 0 ]; then
    echo "$(date): Remote backup successful." >> $LOG
else
    echo "$(date): ERROR - Remote backup failed!" >> $LOG
fi
hljs bash
chmod +x ~/remote_backup.sh
crontab -e
0 5 * * * /home/steam/remote_backup.sh

rsync Parameters

ParameterDescription
-aArchive mode (preserves permissions, dates)
-vVerbose output
-zCompression
--deleteDelete files not in source from destination
-eSSH connection parameters

World File Management

Minecraft World Files

hljs bash
# World directories
~/minecraft/world/
~/minecraft/world_nether/
~/minecraft/world_the_end/

# Save before backup
screen -S minecraft -p 0 -X stuff "save-all\n"
sleep 5
screen -S minecraft -p 0 -X stuff "save-off\n"
tar -czf ~/backups/minecraft/world_$(date +%Y%m%d).tar.gz ~/minecraft/world*
screen -S minecraft -p 0 -X stuff "save-on\n"

Rust World Files

hljs bash
~/rustserver/server/rust/
~/rustserver/server/rust/player.blueprints.5.db
~/rustserver/server/rust/proceduralmap.*.sav

Restoration

General Restoration Steps

hljs bash
# 1. Stop server
sudo systemctl stop gameserver

# 2. Backup current files (safety)
mv ~/gameserver/save ~/gameserver/save_old

# 3. Restore backup
tar -xzf ~/backups/gameserver/gameserver_20250101_120000.tar.gz -C /

# 4. Start server
sudo systemctl start gameserver

# 5. Check logs
sudo journalctl -u gameserver -f

Restoring Specific Files

hljs bash
# List backup contents
tar -tzf ~/backups/gameserver/gameserver_20250101_120000.tar.gz

# Extract specific file
tar -xzf ~/backups/gameserver/gameserver_20250101_120000.tar.gz home/steam/gameserver/config.ini

Backup Monitoring

hljs bash
# Check backup sizes
du -sh ~/backups/*/

# List recent backups
ls -lht ~/backups/minecraft/ | head -10

# Check disk usage
df -h

Conclusion

Regular backup is an essential part of game server management. Using automatic backup scripts, cron scheduling, and rsync remote backup, you can keep your data safe. REXE VDS NVMe SSD infrastructure provides fast backup and restore operations.