|
|
@ -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!" |
|
|
|