update
Some checks failed
Deploy Minecraft Server / deploy (push) Failing after 1m25s
Ansible Lint / lint (push) Failing after 12s

This commit is contained in:
2025-08-26 14:28:09 +02:00
parent 0315edf95f
commit 31711c7627
105 changed files with 1419 additions and 366 deletions

View File

@@ -0,0 +1,29 @@
#!/bin/bash
BACKUP_DIR="{{ minecraft_backups_dir }}/daily"
SERVER_DIR="{{ minecraft_server_dir }}"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="minecraft_daily_${DATE}"
RETENTION={{ backup_retention_daily }}
# 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_daily_*" -type {% if backup_compression %}f{% else %}d{% endif %} -mtime +${RETENTION} -delete
echo "Daily backup completed: ${BACKUP_NAME}"

View File

@@ -0,0 +1,29 @@
#!/bin/bash
BACKUP_DIR="{{ minecraft_backups_dir }}/monthly"
SERVER_DIR="{{ minecraft_server_dir }}"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="minecraft_monthly_${DATE}"
RETENTION={{ backup_retention_monthly }}
# 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_monthly_*" -type {% if backup_compression %}f{% else %}d{% endif %} -mtime +$((${RETENTION} * 30)) -delete
echo "Monthly backup completed: ${BACKUP_NAME}"

View 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}"

View File

@@ -0,0 +1,59 @@
#!/bin/bash
BACKUP_TYPE="$1" # daily, weekly, monthly
BACKUP_DATE="$2" # YYYYMMDD_HHMMSS format
SERVER_DIR="{{ minecraft_server_dir }}"
BACKUP_BASE_DIR="{{ minecraft_backups_dir }}"
if [ $# -ne 2 ]; then
echo "Usage: $0 <backup_type> <backup_date>"
echo "Example: $0 daily 20241201_020000"
echo "Available backups:"
echo "Daily:"
ls -1 "${BACKUP_BASE_DIR}/daily/" | grep minecraft_daily
echo "Weekly:"
ls -1 "${BACKUP_BASE_DIR}/weekly/" | grep minecraft_weekly
echo "Monthly:"
ls -1 "${BACKUP_BASE_DIR}/monthly/" | grep minecraft_monthly
exit 1
fi
BACKUP_NAME="minecraft_${BACKUP_TYPE}_${BACKUP_DATE}"
BACKUP_DIR="${BACKUP_BASE_DIR}/${BACKUP_TYPE}"
{% if backup_compression %}
BACKUP_FILE="${BACKUP_DIR}/${BACKUP_NAME}.tar.gz"
{% else %}
BACKUP_FILE="${BACKUP_DIR}/${BACKUP_NAME}"
{% endif %}
if [ ! -e "${BACKUP_FILE}" ]; then
echo "Backup not found: ${BACKUP_FILE}"
exit 1
fi
# Stop Minecraft server
systemctl stop minecraft
# Backup current server (just in case)
RESTORE_BACKUP_DIR="${BACKUP_BASE_DIR}/restore_backup"
mkdir -p "${RESTORE_BACKUP_DIR}"
mv "${SERVER_DIR}" "${RESTORE_BACKUP_DIR}/server_before_restore_$(date +%Y%m%d_%H%M%S)"
# Restore from backup
{% if backup_compression %}
mkdir -p "${SERVER_DIR}"
tar -xzf "${BACKUP_FILE}" -C "${BACKUP_DIR}"
rsync -av "${BACKUP_DIR}/${BACKUP_NAME}/" "${SERVER_DIR}/"
rm -rf "${BACKUP_DIR}/${BACKUP_NAME}"
{% else %}
rsync -av "${BACKUP_FILE}/" "${SERVER_DIR}/"
{% endif %}
# Fix permissions
chown -R {{ minecraft_user }}:{{ minecraft_group }} "${SERVER_DIR}"
# Start Minecraft server
systemctl start minecraft
echo "Restore completed from: ${BACKUP_FILE}"