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
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:
@@ -1,29 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Weekly Minecraft Backup Script
|
||||
# Generated by Ansible
|
||||
|
||||
BACKUP_DIR="{{ minecraft_backups_dir }}/weekly"
|
||||
SERVER_DIR="{{ minecraft_server_dir }}"
|
||||
set -e
|
||||
|
||||
# Source backup functions
|
||||
source {{ minecraft_tools_dir }}/backup-functions.sh
|
||||
|
||||
# Configuration
|
||||
BACKUP_DIR="{{ backup_weekly_dir }}"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_NAME="minecraft_weekly_${DATE}"
|
||||
RETENTION={{ backup_retention_weekly }}
|
||||
BACKUP_NAME="weekly_backup_$DATE"
|
||||
LOG_FILE="{{ minecraft_base_dir }}/logs/backup-weekly.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 weekly 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_weekly_*" -type {% if backup_compression %}f{% else %}d{% endif %} -mtime +$((${RETENTION} * 7)) -delete
|
||||
# Start Minecraft server
|
||||
start_minecraft
|
||||
|
||||
echo "Weekly backup completed: ${BACKUP_NAME}"
|
||||
# Clean old weekly backups (convert weeks to days)
|
||||
clean_old_backups "$BACKUP_DIR" $(({{ backup_retention_weeks }} * 7))
|
||||
|
||||
# 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')] Weekly backup completed: ${BACKUP_NAME}.tar.gz" >> "$LOG_FILE"
|
Reference in New Issue
Block a user