From eae48a09b221c6a5df20f8004e75c39fad71e998 Mon Sep 17 00:00:00 2001 From: Mar Alegre Date: Mon, 29 Jun 2020 11:32:19 -0500 Subject: [PATCH] changed mount points --- src/minecraft_be/Containerfile | 2 +- src/minecraft_be/assets/bin/mcbe-backup | 31 +++++++++++++++---- .../assets/minecraft/permissions.json | 12 ++++--- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/minecraft_be/Containerfile b/src/minecraft_be/Containerfile index 59c9af7..8054c51 100644 --- a/src/minecraft_be/Containerfile +++ b/src/minecraft_be/Containerfile @@ -8,7 +8,7 @@ FROM localhost/debian:latest LABEL deployopts="\ -p 19132:19132/udp \ -p 19133:19133/udp \ --v /srv/vol/minecraft_be/worlds:/vol/worlds" +-v /srv/vol/minecraft_be/data:/vol/data" # Build variables # uid that the files owner user should have diff --git a/src/minecraft_be/assets/bin/mcbe-backup b/src/minecraft_be/assets/bin/mcbe-backup index 763da50..a94da84 100755 --- a/src/minecraft_be/assets/bin/mcbe-backup +++ b/src/minecraft_be/assets/bin/mcbe-backup @@ -1,14 +1,29 @@ #!/bin/bash -do_backup() { +do_stop() { echo "Shutting down server for scheduled daily backup." mcbe-shutdown 10 "Shutting down server for scheduled daily backup." - rsync -vaSH /home/mcadmin/worlds/ /vol/worlds/ +} + +do_start() { sleep 5 echo "Restarting server after backup." service mcbe start } +do_backup() { + day=$(date +%d) + cd /vol/data + mkdir -p worlds-daily-$day/ + rsync -vaSH /home/mcadmin/worlds/ worlds-daily-$day/ + if [[ $day == 1 ]]; then + month=$(date +%m) + year=$(date +%Y) + mkdir -p worlds-$year-$month-$day/ + rsync -vaSH worlds-daily-$day/ worlds-$year-$month-$day/ + fi +} + # Check if server is started status=$(systemctl show mcbe -p ActiveState --value) # Check if any players present @@ -16,22 +31,26 @@ players=$(mcbe-exec list | cut -d ' ' -f 3 | cut -d '/' -f 1) # check when mcbe-backup was last triggered last=$(date -d "$(systemctl show mcbe-backup.timer -p LastTriggerUSec --value)" +%s) # get current time -today=$(date +%s) +now=$(date +%s) # if service is not active, do backup immediately and exit -if [[ $status == inactive ]]; then +if [[ $status != active ]]; then echo "Service is inactive: copying worlds immediately without restarting service." - rsync -vaSH /home/mcadmin/worlds/ /vol/worlds/ + do_backup # if no players are present, do backup immediately and exit elif [[ $players == 0 ]]; then echo "No players detected: running backup immediately." + do_stop do_backup + do_start # if 12 or more hours have passed since backup was triggered, go ahead and force a shutdown anyways -elif [[ $(( $today - $last )) -ge 43200 ]]; then +elif [[ $(( $now - $last )) -ge 43200 ]]; then echo "Backup was triggered more than 12 hours ago: forcing backup now." + do_stop do_backup + do_start # otherwise, schedule another attempt in an hour else diff --git a/src/minecraft_be/assets/minecraft/permissions.json b/src/minecraft_be/assets/minecraft/permissions.json index d5a37be..b2fb42c 100644 --- a/src/minecraft_be/assets/minecraft/permissions.json +++ b/src/minecraft_be/assets/minecraft/permissions.json @@ -1,6 +1,10 @@ [ - { - "permission" : "operator", - "xuid" : "2535473403284928" - } + { + "permission": "operator", + "xuid": "2535473403284928" + }, + { + "permission": "operator", + "xuid": "" + } ]