Add hourly backups to paper serbers
This commit is contained in:
parent
58fca13b5e
commit
779c177447
@ -40,10 +40,14 @@
|
||||
template: src=server.properties dest="{{ paper_home }}/{{ paper_name }}/server.properties"
|
||||
notify: "restart paper {{ paper_name }}"
|
||||
- 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
|
||||
get_url: url="{{ paper_downloadurl }}" dest="{{ paper_home }}/{{ paper_name }}/server.jar"
|
||||
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_user: minecraft-paper
|
||||
- name: Enable service
|
||||
|
52
roles/minecraft-paper/templates/hourly.sh
Normal file
52
roles/minecraft-paper/templates/hourly.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user