update
This commit is contained in:
29
roles/04-backups/templates/backup-weekly.sh.j2
Normal file
29
roles/04-backups/templates/backup-weekly.sh.j2
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
BACKUP_DIR="{{ minecraft_backups_dir }}/weekly"
|
||||
SERVER_DIR="{{ minecraft_server_dir }}"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_NAME="minecraft_weekly_${DATE}"
|
||||
RETENTION={{ backup_retention_weekly }}
|
||||
|
||||
# Stop server for consistent backup
|
||||
{{ minecraft_tools_dir }}/mcrcon -H 127.0.0.1 -P {{ minecraft_rcon_port }} -p {{ minecraft_rcon_password }} save-all
|
||||
sleep 5
|
||||
{{ minecraft_tools_dir }}/mcrcon -H 127.0.0.1 -P {{ minecraft_rcon_port }} -p {{ minecraft_rcon_password }} save-off
|
||||
|
||||
# Create backup
|
||||
rsync -av --delete "${SERVER_DIR}/" "${BACKUP_DIR}/${BACKUP_NAME}/"
|
||||
|
||||
# Re-enable saving
|
||||
{{ minecraft_tools_dir }}/mcrcon -H 127.0.0.1 -P {{ minecraft_rcon_port }} -p {{ minecraft_rcon_password }} save-on
|
||||
|
||||
# Compress backup if enabled
|
||||
{% if backup_compression %}
|
||||
tar -czf "${BACKUP_DIR}/${BACKUP_NAME}.tar.gz" -C "${BACKUP_DIR}" "${BACKUP_NAME}"
|
||||
rm -rf "${BACKUP_DIR}/${BACKUP_NAME}"
|
||||
{% endif %}
|
||||
|
||||
# Clean old backups
|
||||
find "${BACKUP_DIR}" -name "minecraft_weekly_*" -type {% if backup_compression %}f{% else %}d{% endif %} -mtime +$((${RETENTION} * 7)) -delete
|
||||
|
||||
echo "Weekly backup completed: ${BACKUP_NAME}"
|
Reference in New Issue
Block a user