Add hourly backups to paper serbers

This commit is contained in:
Salt 2020-10-12 10:18:47 -05:00
parent 58fca13b5e
commit 779c177447
2 changed files with 57 additions and 1 deletions

View File

@ -40,10 +40,14 @@
template: src=server.properties dest="{{ paper_home }}/{{ paper_name }}/server.properties" template: src=server.properties dest="{{ paper_home }}/{{ paper_name }}/server.properties"
notify: "restart paper {{ paper_name }}" notify: "restart paper {{ paper_name }}"
- name: Accept EULA - name: Accept EULA
template: src=eula.txt dest="{{ paper_home }}/{{ paper_name }}/eula.txt" template: src=eula.txt dest="{{ paper_home }}/{{ paper_name }}/eula.txt" mode="0644"
- name: Download Paper - name: Download Paper
get_url: url="{{ paper_downloadurl }}" dest="{{ paper_home }}/{{ paper_name }}/server.jar" get_url: url="{{ paper_downloadurl }}" dest="{{ paper_home }}/{{ paper_name }}/server.jar"
notify: "restart paper {{ paper_name }}" notify: "restart paper {{ paper_name }}"
- name: Template out hourly backup job
template: src=hourly.sh dest="{{ paper_home }}/{{ paper_name }}/hourly.sh" mode="0775"
- name: Set up hourly backup job
cron: minute="0" name="{{ paper_name }}-nightly" job="{{ paper_home }}/{{ paper_name }}/hourly.sh"
become: yes become: yes
become_user: minecraft-paper become_user: minecraft-paper
- name: Enable service - name: Enable service

View File

@ -0,0 +1,52 @@
#! /bin/sh
#
# nightly.sh
# Nightly world backups for Minecraft
# Copyright (C) 2020 Vintage Salt <rehashedsalt@cock.li>
#
# Distributed under terms of the MIT license.
#
set -e
export MCDIR="{{ paper_home }}/{{ paper_name }}"
export OUTDIR="$MCDIR/backups"
retention=24 # 1hr intervals
# Helper functions
log() {
[ -z "$1" ] && return 1
printf "$(date -Iseconds): $1\n"
}
stuff() {
[ -z "$1" ] && return 1
screen -p 0 -S "{{ paper_name }}" -X eval "stuff \"say $1\\015\""
}
# Sanity checks
if ! [ -d "$OUTDIR" ]; then
if ! mkdir "$OUTDIR"; then
log "Unable to find or create output directory: $OUTDIR"
stuff "World backup failed: see log for details"
retuirn 2
fi
fi
# Enforce permissions on our output dir
chown -R minecraft-paper. "$OUTDIR"
# Remove old backups
find "$OUTDIR" -type f -mtime +1 -iname "backup-*.tar.gz" -delete
# WE MAKE BACKUP NOW SERGEI
if cd "$OUTDIR"; then
log "Initiating world backup"
stuff "Initiating world backup"
tar czhf "$OUTDIR/backup-$(date -Iseconds).tar.gz" "$MCDIR"/world*
log "World backup complete"
stuff "World backup complete"
else
log "Could not change directory: $OUTDIR"
stuff "World backup failed: see log for details"
return 3
fi