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

@@ -0,0 +1,18 @@
---
- name: Create backup directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
loop:
- "{{ backup_base_dir }}"
- "{{ backup_daily_dir }}"
- "{{ backup_weekly_dir }}"
- "{{ backup_monthly_dir }}"
- name: Install rsync
ansible.builtin.apt:
name: rsync
state: present

View File

@@ -1,14 +0,0 @@
---
- 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

@@ -1,27 +0,0 @@
---
- 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,17 @@
---
- name: Create daily backup script
ansible.builtin.template:
src: backup-daily.sh.j2
dest: "{{ minecraft_tools_dir }}/backup-daily.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
- name: Setup daily backup cron job
ansible.builtin.cron:
name: "Minecraft daily backup"
minute: "0"
hour: "{{ backup_daily_time.split(':')[0] }}"
job: "{{ minecraft_tools_dir }}/backup-daily.sh"
user: "{{ minecraft_user }}"
state: present

View File

@@ -1,29 +0,0 @@
---
- 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,18 @@
---
- name: Create weekly backup script
ansible.builtin.template:
src: backup-weekly.sh.j2
dest: "{{ minecraft_tools_dir }}/backup-weekly.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
- name: Setup weekly backup cron job
ansible.builtin.cron:
name: "Minecraft weekly backup"
minute: "0"
hour: "{{ backup_weekly_time.split(':')[0] }}"
weekday: "{{ backup_weekly_day }}"
job: "{{ minecraft_tools_dir }}/backup-weekly.sh"
user: "{{ minecraft_user }}"
state: present

View File

@@ -0,0 +1,18 @@
---
- name: Create monthly backup script
ansible.builtin.template:
src: backup-monthly.sh.j2
dest: "{{ minecraft_tools_dir }}/backup-monthly.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'
- name: Setup monthly backup cron job
ansible.builtin.cron:
name: "Minecraft monthly backup"
minute: "0"
hour: "{{ backup_monthly_time.split(':')[0] }}"
day: "{{ backup_monthly_day }}"
job: "{{ minecraft_tools_dir }}/backup-monthly.sh"
user: "{{ minecraft_user }}"
state: present

View File

@@ -1,9 +0,0 @@
---
- 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,38 @@
---
- name: Create backup utility script
ansible.builtin.copy:
content: |
#!/bin/bash
# Backup utility functions
# Function to stop Minecraft server safely
stop_minecraft() {
if systemctl is-active --quiet minecraft; then
echo "Stopping Minecraft server..."
/usr/local/bin/mcrcon -H 127.0.0.1 -P {{ rcon_port }} -p "{{ rcon_password }}" "say Server backup starting in 30 seconds..."
sleep 30
/usr/local/bin/mcrcon -H 127.0.0.1 -P {{ rcon_port }} -p "{{ rcon_password }}" stop
sleep 10
fi
}
# Function to start Minecraft server
start_minecraft() {
if ! systemctl is-active --quiet minecraft; then
echo "Starting Minecraft server..."
systemctl start minecraft
fi
}
# Function to clean old backups
clean_old_backups() {
local backup_dir=$1
local retention_days=$2
find "$backup_dir" -type f -mtime +$retention_days -delete
find "$backup_dir" -type d -empty -delete
}
dest: "{{ minecraft_tools_dir }}/backup-functions.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'

View File

@@ -0,0 +1,8 @@
---
- name: Create restore backup script
ansible.builtin.template:
src: restore-backup.sh.j2
dest: "{{ minecraft_tools_dir }}/restore-backup.sh"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_group }}"
mode: '0755'

View File

@@ -1,16 +1,18 @@
---
- name: Include backup structure setup tasks
include_tasks: 01-setup-backup-structure.yml
tags: ['backup', 'setup']
- name: Include backup directories creation tasks
ansible.builtin.include_tasks: 01-create-backup-directories.yml
- name: Include backup scripts creation tasks
include_tasks: 02-create-backup-scripts.yml
tags: ['backup', 'scripts']
- name: Include daily backup setup tasks
ansible.builtin.include_tasks: 02-setup-daily-backup.yml
- name: Include cron jobs setup tasks
include_tasks: 03-setup-cron-jobs.yml
tags: ['backup', 'cron']
- name: Include weekly backup setup tasks
ansible.builtin.include_tasks: 03-setup-weekly-backup.yml
- name: Include restore script setup tasks
include_tasks: 04-setup-restore-script.yml
tags: ['backup', 'restore']
- name: Include monthly backup setup tasks
ansible.builtin.include_tasks: 04-setup-monthly-backup.yml
- name: Include backup scripts setup tasks
ansible.builtin.include_tasks: 05-setup-backup-scripts.yml
- name: Include restore scripts setup tasks
ansible.builtin.include_tasks: 06-setup-restore-scripts.yml