#!/bin/bash # Check if server is started status=$(systemctl show mcbe -p ActiveState --value) if [[ $status != active ]]; then echo "mcbe.service is inactive. Exiting." exit 1 fi # get time hour=$(date +%H) day=$(date +%d) month=$(date +%m) year=$(date +%Y) # cd to backup dir cd /vol/data/backup # hourly backup mcbe-exec say "Autosaving..." mcbe-backup worlds-hourly-$hour if [[ $hour -eq 1 ]]; then # if no players are present, restart the server # should help deal with any memory leaks players=$(mcbe-exec list | head -n 1 | cut -d ' ' -f 3 | cut -d '/' -f 1) if [[ $players == "0" ]]; then mcbe-restart fi # save daily and longterm backups rsync -a worlds-hourly-$hour/ worlds-daily-$day/ if [[ $day -eq 1 ]]; then rsync -a worlds-daily-$day/ worlds-$year-$month-$day/ fi fi