build files for making podman containers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
1.3 KiB

#!/bin/bash
if [[ -z $1 ]]; then
echo "Usage: $0 backup_dir"
exit 2
fi
backup_dir="$1"
# Check if directory exists
if [[ ! -d "$backup_dir" ]]; then
echo "Error: directory \"$backup_dir\" not found."
exit 1
fi
# Check if server is active
status=$(systemctl show mcbe -p ActiveState --value)
# shutdown server if it is active
if [[ $status == active ]]; then
echo "Server is active: executing shutdown..."
systemctl stop mcbe
sleep 1
fi
worlds_dir=/home/mcadmin/worlds
# if worlds dir is non-empty, save it as worlds.bak
if [[ ! -z $(ls $worlds_dir) ]]; then
echo "Worlds directory is nonempty: saving backup 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
echo "Copying worlds from backup directory..."
rsync -aSH "$backup_dir/" $worlds_dir/
# copy resources to each world in worlds_dir
echo "Copying resources to worlds..."
resources_dir=/vol/data/resources
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 "Server was active: starting server again..."
systemctl start mcbe
sleep 5
fi
echo "Done!"