A Minecraft Server Backup Script You Can Actually Set Up Today

ZCraft Studios

The cron job, the tar command, and the offsite copy step most backup guides skip entirely.

A Minecraft Server Backup Script You Can Actually Set Up Today

Not the argument for why backups matter — the actual script and cron entry.

What Actually Needs Backing Up

A backup that only grabs the world folder misses most of what it takes to actually recover a server:

  • World folders (world, world_nether, world_the_end)
  • plugins/ — every plugin's config lives here, not just the jars
  • playerdata/ and any economy/permissions database files
  • server.properties and any proxy config if running Velocity

A Basic Backup Script

#!/bin/bash
SERVER_DIR="/home/mc/myserver"
BACKUP_DIR="/home/mc/backups"
DATE=$(date +%Y-%m-%d_%H-%M)

mkdir -p "$BACKUP_DIR"

tar -czf "$BACKUP_DIR/backup_$DATE.tar.gz" \
  -C "$SERVER_DIR" world world_nether world_the_end plugins server.properties

find "$BACKUP_DIR" -name "backup_*.tar.gz" -mtime +7 -delete

The last line deletes backups older than 7 days so the backup folder doesn't grow forever — adjust the retention window to whatever's actually needed.

Running It on a Schedule

Add it to cron to run automatically:

crontab -e

Then add a line for a daily 4 AM backup:

0 4 * * * /home/mc/backup.sh >> /home/mc/backup.log 2>&1

Running the backup during low-player hours avoids freezing the world mid-save for active players — tar-ing a live world without pausing saves first can occasionally grab a file mid-write, which is why running it when the server is quiet matters more than almost anything else in this setup.

Pausing Saves During the Copy (Optional, Safer)

For a cleaner backup, send save-off and save-all to the server console before copying, then save-on after:

screen -S mc -p 0 -X stuff "save-off$(printf \\\\r)"
screen -S mc -p 0 -X stuff "save-all$(printf \\\\r)"
sleep 10
# ... run the tar command here ...
screen -S mc -p 0 -X stuff "save-on$(printf \\\\r)"

This assumes the server is running inside a screen session named mc.

Getting a Copy Offsite

A backup stored on the same machine as the server doesn't help if that machine fails entirely. rclone can sync the backup folder to cloud storage (Google Drive, S3, Backblaze, and others) with one more cron line:

rclone sync /home/mc/backups remote:minecraft-backups

Test the Restore, Not Just the Backup

A backup that's never been restored is unverified. Periodically extract one into a throwaway folder and confirm the world actually loads — the first time a restore gets tested shouldn't be during an actual emergency.

Share: