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,8 @@
---
backup_retention_daily: 7
backup_retention_weekly: 4
backup_retention_monthly: 6
backup_compression: true
backup_remote_host: ""
backup_remote_user: ""
backup_remote_path: ""

View File

View File

@@ -0,0 +1,14 @@
---
- name: Create backup directories
file:
path: "{{ item }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
loop:
- "{{ minecraft_backups_dir }}/daily"
- "{{ minecraft_backups_dir }}/weekly"
- "{{ minecraft_backups_dir }}/monthly"
- "{{ minecraft_backups_dir }}/scripts"
tags: ['backup-structure']

View File

@@ -0,0 +1,27 @@
---
- name: Create daily backup script
template:
src: backup-daily.sh.j2
dest: "{{ minecraft_backups_dir }}/scripts/backup-daily.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
tags: ['backup-scripts']
- name: Create weekly backup script
template:
src: backup-weekly.sh.j2
dest: "{{ minecraft_backups_dir }}/scripts/backup-weekly.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
tags: ['backup-scripts']
- name: Create monthly backup script
template:
src: backup-monthly.sh.j2
dest: "{{ minecraft_backups_dir }}/scripts/backup-monthly.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
tags: ['backup-scripts']

View File

@@ -0,0 +1,29 @@
---
- name: Setup daily backup cron job
cron:
name: "Minecraft daily backup"
user: "{{ minecraft_user }}"
minute: "0"
hour: "2"
job: "{{ minecraft_backups_dir }}/scripts/backup-daily.sh"
tags: ['backup-cron']
- name: Setup weekly backup cron job
cron:
name: "Minecraft weekly backup"
user: "{{ minecraft_user }}"
minute: "0"
hour: "3"
weekday: "0"
job: "{{ minecraft_backups_dir }}/scripts/backup-weekly.sh"
tags: ['backup-cron']
- name: Setup monthly backup cron job
cron:
name: "Minecraft monthly backup"
user: "{{ minecraft_user }}"
minute: "0"
hour: "4"
day: "1"
job: "{{ minecraft_backups_dir }}/scripts/backup-monthly.sh"
tags: ['backup-cron']

View File

@@ -0,0 +1,9 @@
---
- name: Create restore script
template:
src: restore.sh.j2
dest: "{{ minecraft_backups_dir }}/scripts/restore.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
tags: ['backup-restore']

View File

@@ -0,0 +1,16 @@
---
- name: Include backup structure setup tasks
include_tasks: 01-setup-backup-structure.yml
tags: ['backup', 'setup']
- name: Include backup scripts creation tasks
include_tasks: 02-create-backup-scripts.yml
tags: ['backup', 'scripts']
- name: Include cron jobs setup tasks
include_tasks: 03-setup-cron-jobs.yml
tags: ['backup', 'cron']
- name: Include restore script setup tasks
include_tasks: 04-setup-restore-script.yml
tags: ['backup', 'restore']

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

View File