ansible/roles/minecraft-paper/templates/hourly.sh

51 lines
1.1 KiB
Bash
Raw Normal View History

2020-10-12 10:18:47 -05:00
#! /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"
tar czhf "$OUTDIR/backup-$(date -Iseconds).tar.gz" "$MCDIR"/world*
log "World backup complete"
else
log "Could not change directory: $OUTDIR"
stuff "World backup failed: see log for details"
return 3
fi