test other version
Some checks failed
Ansible Minecraft CI/CD Pipeline / Ansible Lint Check (push) Successful in 58s
Ansible Minecraft CI/CD Pipeline / Project Structure Validation (push) Failing after 3s
Ansible Minecraft CI/CD Pipeline / Security Scan (push) Successful in 4s
Ansible Minecraft CI/CD Pipeline / Deploy to Staging (push) Has been skipped
Ansible Minecraft CI/CD Pipeline / Deploy to Production (push) Has been skipped
Ansible Minecraft CI/CD Pipeline / Backup System Check (push) Has been skipped

This commit is contained in:
2025-08-26 21:59:21 +02:00
parent b2459a2dc0
commit 7a2ccb537b
98 changed files with 2830 additions and 1291 deletions

View File

@@ -1,29 +1,42 @@
#!/bin/bash
# Monthly Minecraft Backup Script
# Generated by Ansible
BACKUP_DIR="{{ minecraft_backups_dir }}/monthly"
SERVER_DIR="{{ minecraft_server_dir }}"
set -e
# Source backup functions
source {{ minecraft_tools_dir }}/backup-functions.sh
# Configuration
BACKUP_DIR="{{ backup_monthly_dir }}"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="minecraft_monthly_${DATE}"
RETENTION={{ backup_retention_monthly }}
BACKUP_NAME="monthly_backup_$DATE"
LOG_FILE="{{ minecraft_base_dir }}/logs/backup-monthly.log"
# 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 log entry
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting monthly backup..." >> "$LOG_FILE"
# Create backup
rsync -av --delete "${SERVER_DIR}/" "${BACKUP_DIR}/${BACKUP_NAME}/"
# Create backup directory
mkdir -p "$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
# Stop Minecraft server for consistent backup
stop_minecraft
# 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 %}
# Perform backup
{% for source in backup_sources %}
echo "Backing up {{ source }}..." >> "$LOG_FILE"
rsync {{ rsync_options }} "{{ source }}/" "$BACKUP_DIR/$BACKUP_NAME/$(basename {{ source }})/"
{% endfor %}
# Clean old backups
find "${BACKUP_DIR}" -name "minecraft_monthly_*" -type {% if backup_compression %}f{% else %}d{% endif %} -mtime +$((${RETENTION} * 30)) -delete
# Start Minecraft server
start_minecraft
echo "Monthly backup completed: ${BACKUP_NAME}"
# Clean old monthly backups (convert months to days approximately)
clean_old_backups "$BACKUP_DIR" $(({{ backup_retention_months }} * 30))
# Compress backup
cd "$BACKUP_DIR"
tar -czf "${BACKUP_NAME}.tar.gz" "$BACKUP_NAME"
rm -rf "$BACKUP_NAME"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Monthly backup completed: ${BACKUP_NAME}.tar.gz" >> "$LOG_FILE"