Browse Source

bugfixes and changes to mcbe scripts

feature/startup-from-labels
Mar Alegre 5 years ago
parent
commit
6c9d536ff8
  1. 8
      src/mcbe/assets/bin/mcbe-backup
  2. 25
      src/mcbe/assets/bin/mcbe-restore
  3. 7
      src/mcbe/assets/bin/mcbe-shutdown

8
src/mcbe/assets/bin/mcbe-backup

@ -24,6 +24,7 @@ if [[ -e "$backup_dir" ]]; then
echo "Error: backup dir already exists. Delete directory before proceeding or use another directory name."
exit 1
fi
echo "Creating directory \"$backup_dir\"..."
mkdir -p "$backup_dir"
cd "$backup_dir"
@ -31,12 +32,13 @@ cd "$backup_dir"
status=$(systemctl show mcbe -p ActiveState --value)
# if service is not active, just rsync folder directly.
if [[ $status != active ]]; then
echo "Service is inactive: running rsync directly."
echo "Server is inactive: copying files directly..."
rsync -a "$worlds_dir/" ./
exit
fi
# prepare backup of active world
echo "Server is active: running save hold command..."
status=$(mcbe-exec save hold)
if [[ $status == "The command is already running" ]]; then
echo "Error: a save seems to be currently in progress. Did the previous save run correctly?"
@ -59,6 +61,7 @@ done
files=$(echo "$buffer" | grep -Eo "${world}[^:]+:[0-9]+")
# copy files for active world
echo "Copying active world..."
echo "$files" | while read -r line; do
file=${line%:*}
size=${line#*:}
@ -71,9 +74,12 @@ done
mcbe-exec save resume
# copy inactive worlds
echo "Copying inactive worlds..."
ls -w 1 "$worlds_dir" | grep -v -E "^$world\$" | while read -r line; do
rsync -a "$worlds_dir/$line" ./
done
# make sure everything is owned by worlds owner
chown -R "$(stat -c %U:%G $worlds_dir)" ./
echo "Done!"

25
src/mcbe/assets/bin/mcbe-restore

@ -16,26 +16,39 @@ fi
status=$(systemctl show mcbe -p ActiveState --value)
# shutdown server if it is active
if [[ $status == active ]]; then
echo "Server is active: executing shutdown"
echo "Server is active: executing shutdown..."
systemctl stop mcbe
sleep 1
fi
# remove current worlds
worlds_dir=/home/mcadmin/worlds
rm -r $worlds_dir/*
# if worlds dir is non-empty, save it as worlds.bak
if [[ ! -z $(ls $worlds_dir) ]]; then
echo "Worlds directory is nonempty: saving backup of current state as $worlds_dir.bak"
if [[ -e $worlds_dir.bak ]]; then
rm -r $worlds_dir.bak
fi
mv $worlds_dir $worlds_dir.bak
mkdir $worlds_dir
chown $(stat -c %U:%G $worlds_dir.bak) $worlds_dir
fi
# copy backup to worlds_dir
rsync -aSH "$backup_dir/" "$worlds_dir/"
echo "Copying worlds from \"$backup_dir\" to \"$worlds_dir\"..."
rsync -aSH "$backup_dir/" $worlds_dir/
# copy resources to each world in worlds_dir
echo "Copying resources to worlds in \"$worlds_dir\"..."
resources_dir=/vol/data/resources
for d in "$worlds_dir/*"; do
for d in $worlds_dir/*; do
rsync -aSH "$resources_dir/" "$d/"
done
# start server back up if it was active
if [[ $status == active ]]; then
echo "Starting server back up..."
echo "Server was active: starting server again..."
systemctl start mcbe
sleep 5
fi
echo "Done!"

7
src/mcbe/assets/bin/mcbe-shutdown

@ -10,7 +10,7 @@ if [[ -z $1 || $1 == "-h" ]]; then
restart=1
elif [[ $1 == "-r" ]]; then
restart=0
else; then
else
echo "Invalid value for shutdown type: acceptable values are \"-h\" for halt, or \"-r\" for restart."
exit 2
fi
@ -48,7 +48,10 @@ done
systemctl stop mcbe
if [[ $restart ]]; then
echo "Starting server..."
sleep 1
systemctl start mcbe
sleep 5
sleep 3
fi
echo "Done!"

Loading…
Cancel
Save