--- - 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'