Backup
Create a backup scriptโ
Create the backup script
nano ~/backup.sh
and add the following content, adjust if needed
#!/bin/bash
function datetime() { date "+%Y-%m-%d %H:%M:%S"; }
function status_time() { echo -e "\033[1;33m[$(datetime)] \033[1m$*\033[0m"; }
MINECRAFT_SERVER="$HOME/minecraft-server"
BACKUP_LOG_FILE="logs/backup.log"
BACKUP_TO="backups"
BACKUP_DIRS=(
"${MINECRAFT_SERVER}/plugins"
"${MINECRAFT_SERVER}/world"
"${MINECRAFT_SERVER}/world_nether"
"${MINECRAFT_SERVER}/world_the_end"
)
mkdir -p "$BACKUP_TO" &>/dev/null
mkdir -p "logs" &>/dev/null
for i in "${!BACKUP_DIRS[@]}"; do
status_time "Backing up ${BACKUP_DIRS[$i]}" | tee -a "$BACKUP_LOG_FILE"
rdiff-backup "${BACKUP_DIRS[$i]}" "$BACKUP_TO/$(basename ${BACKUP_DIRS[$i]})" &>> "$BACKUP_LOG_FILE"
done
status_time "Backup finished" | tee -a "$BACKUP_LOG_FILE"
# zip the folders
# put them somewhere safe
# remove archives older than x days on the safe spot: find $BACKUP_DIR -type f -mtime +7 -exec rm {} \;
Make the script executable:
chmod +x ~/backup.sh
Automating the backupโ
Create a cronjob crontab -e
0 3 * * * ~/backup.sh
Test your backupโ
Extract you backup archive
tar -xvzf /path/to/backup/minecraft-backup-YYYY-MM-DD_HH:MM:SS.tar.gz -C /path/to/minecraft-server/