Backup script for Minecraft running by docker
DISCLAIMER: This is mainly a repository with stuff to help me remember how I set it up. This might break your system or whatever setup you are using. Maybe you should search for better alternatives but I started from scratch and this is it. I want to switch to rsnapshot and transfer the backups off the machine. (This note can also be read by future me!)
→ Future me: I've switched to LGSM - Linux Game Server Managers and borgmatic
Currently the setup is too simple:
- 2 Minecraft servers run by docker
- Backups every night to home dir on same server
- Yeah that's it
Check other projects for better usage instead of this one:
- audy/backup-minecraft.rb dockerized minecraft backup
- Lerk's Automagic Minecraft Server Backups With Map Renderings Using GitLab CI and GitLab Pages
Abbreviations in this Readme:
dc
: Dockermc
: Minecraft
Image used by docker:
itzg/minecraft-server:latest
(docker hub)
Servers run by docker with following commands:
S-U-I at Port 2320.
Minecraft data directory mapped by volume to host directory: /var/docker/dc_mc_sui_data
docker run -d -e EULA=TRUE -e VERSION=1.15.2 -p 2320:25565 -v /var/docker/dc_mc_sui_data:/data --name mc_sui itzg/minecraft-server:latest
La-Awesome at Port 25565
Minecraft data directory mapped by volume to host directory: /var/docker/dc_mc_laawesome_data
docker run -d -e EULA=TRUE -e VERSION=1.15.2 -p 25565:25565 -v /var/docker/dc_mc_laawesome_data:/data --name mc_laawesome itzg/minecraft-server:latest
Usage:
> sh backup_dc_mc.sh <container_name> <rcon_password>
Parameters:
container_name
: The human readable name of the docker container. Docker CLI param--name
rcon_password
: The RCON password of the server (Minecraftserver.properties
, linercon.password=xxx
)
The location is currently hardcoded.
The backup filename is generated with date and time: dc_<container_name>_data_yyyyMMdd_HHmmss.tar.gz
Example: dc_mc_laawesome_data_20191030_042115.tar.gz
Cron example (no, these rcon passwords are not used anywhere):
# Backup Minecraft Docker Volume files once a day at 4 in the night
# Param 1: Container name
# Param 2: rcon-cli password
#
5 4 * * * sh /home/plpgtr/backup_dc_mc.sh mc_sui 68xEnjaVJFNDaD > /home/plpgtr/logs/backup_dc_mc_sui.log 2>&1
15 4 * * * sh /home/plpgtr/backup_dc_mc.sh mc_laawesome AD9B4gV3Q3J7pB > /home/plpgtr/logs/backup_dc_mc_laawesome.log 2>&1
Stop both servers and rename the current containers with the version they where running on. Then start the server with the new version.
ATTENTION: Major version strings are 1.16
instead of 1.16.0
.
docker stop mc_laawesome
docker stop mc_sui
docker rename mc_laawesome mc_laawesome_1_15_2
docker rename mc_sui mc_sui_1_15_2
docker run -d -e EULA=TRUE -e VERSION=1.16.1 -p 25565:25565 -v /var/docker/dc_mc_laawesome_data:/data --name mc_laawesome itzg/minecraft-server:latest
docker run -d -e EULA=TRUE -e VERSION=1.16.1 -p 2320:25565 -v /var/docker/dc_mc_sui_data:/data --name mc_sui itzg/minecraft-server:latest