Backub and Restore
We splitting the Backup in two different parts, the World Data Backups and the Plugins Data Backups. The Structure configuration is located at /provisioning/vars/facts_mc_node.yml
.
---
backup_dirs:
plugins:
source:
basedir: /opt/minecraft/plugins
excludes:
- shared/dynmap/*
dest:
local:
restic_job_cron: '15 1 * * *'
RESTIC_REPOSITORY: "{{ restic_repos_localbackup_url }}/plugindata"
RESTIC_PASSWORD: "{{ mc_backup_restic_repository_password | default('dolphins') }}"
b2:
RESTIC_REPOSITORY: "b2:mcbackup-plugindata"
s3:
restic_job_cron: '40 2 * * *'
RESTIC_S3_URL: "{{ restic_s3_endpoint | default('') }}"
RESTIC_S3_BUCKET: backup
RESTIC_S3_PATH: "/{{ backup_s3_subpath | default('') }}/restic/plugindata"
RESTIC_PASSWORD: "{{ mc_backup_restic_repository_password | default('dolphins') }}"
AWS_ACCESS_KEY_ID: "{{ s3_access_key | default('') }}"
AWS_SECRET_ACCESS_KEY: "{{ s3_secret_key | default('') }}"
worlddata:
source:
basedir: /opt/minecraft/server/shared
excludes:
- plugins/*
- logs/*
- crash-reports/*
dest:
local:
restic_job_cron: '0 1 * * *'
RESTIC_REPOSITORY: "{{ restic_repos_localbackup_url }}/gamedata"
RESTIC_PASSWORD: "{{ mc_backup_restic_repository_password | default('dolphins') }}"
b2:
RESTIC_REPOSITORY: "b2:mcbackup-worlddata"
s3:
# restic_job_cron: '*/10 * * * *'
restic_job_cron: '0 2 * * *'
RESTIC_S3_URL: "{{ restic_s3_endpoint | default('') }}"
RESTIC_S3_BUCKET: backup
RESTIC_S3_PATH: "/{{ backup_s3_subpath | default('') }}/restic/gamedata"
RESTIC_PASSWORD: "{{ mc_backup_restic_repository_password | default('dolphins') }}"
AWS_ACCESS_KEY_ID: "{{ s3_access_key | default('') }}"
AWS_SECRET_ACCESS_KEY: "{{ s3_secret_key | default('') }}"
You will find the implementation at a ugly but functional Ansible Role, located at provisioning/maintenance/roles/backup
.
World Data Backups
Plugins Data Backups
Working with Backups
Daily Backups
#!/bin/bash
backup_excludes=$1
backup_source=$2
# exit with this by default, if it is not set later
exit_code=0
rcon_password=$(awk -F "=" '/rcon.password/ {print $2}' /opt/minecraft/server/shared/server.properties)
rcon_port=$(awk -F "=" '/rcon.port/ {print $2}' /opt/minecraft/server/shared/server.properties)
# the cleanup function will be the exit point
cleanup () {
# ignore stderr from rm incase the hook is called twice
/usr/local/bin/rcon-cli --port $rcon_port --password $rcon_password save-on
/usr/local/bin/rcon-cli --port $rcon_port --password $rcon_password say "backup finished $backup_source"
# exit(code)
exit $exit_code
}
# register the cleanup function for all these signal types (see link below)
trap cleanup EXIT ERR INT TERM
/usr/local/bin/rcon-cli --port $rcon_port --password $rcon_password save-off
/usr/local/bin/rcon-cli --port $rcon_port --password $rcon_password say "backup starts $backup_source"
restic backup $backup_excludes $backup_source
# set the exit_code with the real result, used when cleanup is called
exit_code=$?
You can controll the the Jobs by define Variabels at the Inventory:
backup_dests:
- "s3"
- "local"
backup_parts:
- "plugins"
- "worlddata"
Adhoc Backups
You can execute Adhoc Restic Backup when you destroying the Computing Elements, and will be safe that all gamedata saved! Or You can use the Adhoc Archiving Backup function to share your Server over GDrive, or a local archive. For executing be ensure that you have set the Required Environment Variables.
Adhoc Restic Backup
The Adhoc Restic Backup are usefull for store the current state before you change any configruations.
ansible-playbook maintenance/playbook-execute-backup.yml --extra-vars '{"backup_dests":["s3","local"]}' --extra-vars '{"backup_parts":["plugins","worlddata"]}'
when you Call the playbook playbook-execute-backup.yml
without any --extra-vars
we use the configuration from, Configure Backup Jobs.
Adhoc Archiving Backup
Local Archive
ansible-playbook maintenance/playbook-execute-backup.yml --extra-vars 'backup_type=archive' --extra-vars 'backup_adhoc_publish=local'
Gdrive Upload
For Upload to GDrive you must define your gdrive_refresh_token
as Variable.
Restore on Create
At the moment you can only use restic (local or remote) Repositories for automatical restore.
minecraft_restore_src: "s3" minecraft_restore_elements: - "worlddata" # - "plugins"
The Values must match with entries from the Static Backup Config.