check new version
Some checks failed
Ansible Minecraft Server CI/CD / lint (push) Failing after 21s
Ansible Minecraft Server CI/CD / test (push) Has been skipped
Ansible Minecraft Server CI/CD / deploy (push) Has been skipped

This commit is contained in:
2025-08-27 07:59:19 +02:00
parent 7a2ccb537b
commit 9ea9ac7254
125 changed files with 2696 additions and 1511 deletions

View File

@@ -1,42 +0,0 @@
#!/bin/bash
# Daily Minecraft Backup Script
# Generated by Ansible
set -e
# Source backup functions
source {{ minecraft_tools_dir }}/backup-functions.sh
# Configuration
BACKUP_DIR="{{ backup_daily_dir }}"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_NAME="daily_backup_$DATE"
LOG_FILE="{{ minecraft_base_dir }}/logs/backup-daily.log"
# Create log entry
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting daily backup..." >> "$LOG_FILE"
# Create backup directory
mkdir -p "$BACKUP_DIR/$BACKUP_NAME"
# Stop Minecraft server for consistent backup
stop_minecraft
# Perform backup
{% for source in backup_sources %}
echo "Backing up {{ source }}..." >> "$LOG_FILE"
rsync {{ rsync_options }} "{{ source }}/" "$BACKUP_DIR/$BACKUP_NAME/$(basename {{ source }})/"
{% endfor %}
# Start Minecraft server
start_minecraft
# Clean old daily backups
clean_old_backups "$BACKUP_DIR" {{ backup_retention_days }}
# 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')] Daily backup completed: ${BACKUP_NAME}.tar.gz" >> "$LOG_FILE"

View File

@@ -1,42 +0,0 @@
#!/bin/bash
# Monthly Minecraft Backup Script
# Generated by Ansible
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="monthly_backup_$DATE"
LOG_FILE="{{ minecraft_base_dir }}/logs/backup-monthly.log"
# Create log entry
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting monthly backup..." >> "$LOG_FILE"
# Create backup directory
mkdir -p "$BACKUP_DIR/$BACKUP_NAME"
# Stop Minecraft server for consistent backup
stop_minecraft
# Perform backup
{% for source in backup_sources %}
echo "Backing up {{ source }}..." >> "$LOG_FILE"
rsync {{ rsync_options }} "{{ source }}/" "$BACKUP_DIR/$BACKUP_NAME/$(basename {{ source }})/"
{% endfor %}
# Start Minecraft server
start_minecraft
# 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"

View File

@@ -1,42 +0,0 @@
#!/bin/bash
# Weekly Minecraft Backup Script
# Generated by Ansible
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="weekly_backup_$DATE"
LOG_FILE="{{ minecraft_base_dir }}/logs/backup-weekly.log"
# Create log entry
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting weekly backup..." >> "$LOG_FILE"
# Create backup directory
mkdir -p "$BACKUP_DIR/$BACKUP_NAME"
# Stop Minecraft server for consistent backup
stop_minecraft
# Perform backup
{% for source in backup_sources %}
echo "Backing up {{ source }}..." >> "$LOG_FILE"
rsync {{ rsync_options }} "{{ source }}/" "$BACKUP_DIR/$BACKUP_NAME/$(basename {{ source }})/"
{% endfor %}
# Start Minecraft server
start_minecraft
# 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"

View File

@@ -0,0 +1,69 @@
#!/bin/bash
# {{ ansible_managed }}
BACKUP_TYPE=$1
BACKUP_BASE="{{ backup_base_dir }}"
SERVER_DIR="{{ minecraft_server_dir }}"
TOOLS_DIR="{{ minecraft_tools_dir }}"
RCON_CMD="{{ minecraft_tools_dir }}/mcrcon -H localhost -P {{ rcon_port }} -p {{ rcon_password }}"
DATE=$(date +%Y%m%d_%H%M%S)
# Function to clean old backups
clean_old_backups() {
local dir=$1
local keep=$2
ls -1t $dir/*.tar.gz 2>/dev/null | tail -n +$((keep+1)) | xargs rm -f
}
# Function to perform backup
perform_backup() {
local backup_dir=$1
local retention=$2
echo "Starting $BACKUP_TYPE backup at $(date)"
# Notify players
$RCON_CMD "say Server backup starting in 10 seconds..."
sleep 10
# Save world
$RCON_CMD "save-all"
sleep 5
# Disable auto-save
$RCON_CMD "save-off"
# Create backup
tar -czf "$backup_dir/minecraft_${BACKUP_TYPE}_${DATE}.tar.gz" \
-C "{{ minecraft_base_dir }}" \
server/ sources/ tools/ \
--exclude='*.log' \
--exclude='logs/*'
# Re-enable auto-save
$RCON_CMD "save-on"
# Clean old backups
clean_old_backups "$backup_dir" "$retention"
# Notify players
$RCON_CMD "say Server backup completed!"
echo "Backup completed at $(date)"
}
case "$BACKUP_TYPE" in
daily)
perform_backup "{{ backup_daily_dir }}" "{{ backup_retention_daily }}"
;;
weekly)
perform_backup "{{ backup_weekly_dir }}" "{{ backup_retention_weekly }}"
;;
monthly)
perform_backup "{{ backup_monthly_dir }}" "{{ backup_retention_monthly }}"
;;
*)
echo "Usage: $0 {daily|weekly|monthly}"
exit 1
;;
esac

View File

@@ -1,116 +0,0 @@
#!/bin/bash
# Minecraft Backup Restore Script
# Generated by Ansible
set -e
# Usage function
usage() {
echo "Usage: $0 <backup_type> <backup_file>"
echo "backup_type: daily, weekly, or monthly"
echo "backup_file: name of the backup file to restore"
echo ""
echo "Example: $0 daily daily_backup_20241225_120000.tar.gz"
exit 1
}
# Check arguments
if [ $# -ne 2 ]; then
usage
fi
BACKUP_TYPE="$1"
BACKUP_FILE="$2"
LOG_FILE="{{ minecraft_base_dir }}/logs/restore.log"
# Source backup functions
source {{ minecraft_tools_dir }}/backup-functions.sh
# Validate backup type
case "$BACKUP_TYPE" in
daily)
BACKUP_DIR="{{ backup_daily_dir }}"
;;
weekly)
BACKUP_DIR="{{ backup_weekly_dir }}"
;;
monthly)
BACKUP_DIR="{{ backup_monthly_dir }}"
;;
*)
echo "Invalid backup type: $BACKUP_TYPE"
usage
;;
esac
# Check if backup file exists
BACKUP_PATH="$BACKUP_DIR/$BACKUP_FILE"
if [ ! -f "$BACKUP_PATH" ]; then
echo "Backup file not found: $BACKUP_PATH"
exit 1
fi
# Confirmation
echo "WARNING: This will replace the current Minecraft server data!"
echo "Backup file: $BACKUP_PATH"
echo "Type 'yes' to continue:"
read -r confirmation
if [ "$confirmation" != "yes" ]; then
echo "Restore cancelled."
exit 0
fi
# Start restoration process
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Starting restore from $BACKUP_FILE..." >> "$LOG_FILE"
# Stop Minecraft server
stop_minecraft
# Create temporary restore directory
TEMP_DIR="/tmp/minecraft_restore_$"
mkdir -p "$TEMP_DIR"
# Extract backup
echo "Extracting backup..." >> "$LOG_FILE"
cd "$TEMP_DIR"
tar -xzf "$BACKUP_PATH"
# Find the extracted directory
EXTRACTED_DIR=$(find . -maxdepth 1 -type d -name "*backup*" | head -1)
if [ -z "$EXTRACTED_DIR" ]; then
echo "Could not find extracted backup directory"
rm -rf "$TEMP_DIR"
exit 1
fi
# Backup current data
CURRENT_BACKUP="{{ minecraft_base_dir }}/current_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$CURRENT_BACKUP"
{% for source in backup_sources %}
if [ -d "{{ source }}" ]; then
cp -r "{{ source }}" "$CURRENT_BACKUP/"
fi
{% endfor %}
echo "Current data backed up to: $CURRENT_BACKUP" >> "$LOG_FILE"
# Restore data
echo "Restoring data..." >> "$LOG_FILE"
{% for source in backup_sources %}
SOURCE_NAME=$(basename {{ source }})
if [ -d "$EXTRACTED_DIR/$SOURCE_NAME" ]; then
rm -rf "{{ source }}"
cp -r "$EXTRACTED_DIR/$SOURCE_NAME" "{{ source }}"
chown -R {{ minecraft_user }}:{{ minecraft_group }} "{{ source }}"
fi
{% endfor %}
# Cleanup temporary directory
rm -rf "$TEMP_DIR"
# Start Minecraft server
start_minecraft
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Restore completed successfully" >> "$LOG_FILE"
echo "Restore completed successfully!"
echo "Previous data backed up to: $CURRENT_BACKUP"

View File

@@ -0,0 +1,61 @@
#!/bin/bash
# {{ ansible_managed }}
BACKUP_TYPE=$1
BACKUP_DATE=$2
BACKUP_BASE="{{ backup_base_dir }}"
SERVER_DIR="{{ minecraft_server_dir }}"
# Function to find backup file
find_backup() {
local type=$1
local date=$2
local dir=""
case "$type" in
daily) dir="{{ backup_daily_dir }}" ;;
weekly) dir="{{ backup_weekly_dir }}" ;;
monthly) dir="{{ backup_monthly_dir }}" ;;
*) echo "Invalid backup type"; exit 1 ;;
esac
if [ "$date" = "latest" ]; then
ls -1t $dir/*.tar.gz 2>/dev/null | head -n 1
else
ls $dir/*${date}*.tar.gz 2>/dev/null | head -n 1
fi
}
# Main restore process
BACKUP_FILE=$(find_backup "$BACKUP_TYPE" "$BACKUP_DATE")
if [ -z "$BACKUP_FILE" ]; then
echo "No backup found for type: $BACKUP_TYPE, date: $BACKUP_DATE"
exit 1
fi
echo "Restoring from: $BACKUP_FILE"
# Create restore directory
RESTORE_DIR="{{ minecraft_base_dir }}/restore_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$RESTORE_DIR"
# Extract backup
tar -xzf "$BACKUP_FILE" -C "$RESTORE_DIR"
# Backup current server
echo "Backing up current server state..."
tar -czf "{{ backup_base_dir }}/pre_restore_$(date +%Y%m%d_%H%M%S).tar.gz" \
-C "{{ minecraft_base_dir }}" server/
# Restore files
echo "Restoring server files..."
rsync -av --delete "$RESTORE_DIR/server/" "$SERVER_DIR/"
# Set permissions
chown -R {{ minecraft_user }}:{{ minecraft_group }} "$SERVER_DIR"
# Clean up
rm -rf "$RESTORE_DIR"
echo "Restore completed successfully!"