Browse Source

hopefully last fixes to mcbe-backup scripts

feature/startup-from-labels
Mar Alegre 5 years ago
parent
commit
cccb3bec35
  1. 31
      src/mcbe/assets/bin/maint
  2. 18
      src/mcbe/assets/bin/mcbe-backup

31
src/mcbe/assets/bin/maint

@ -1,5 +1,11 @@
#!/bin/bash #!/bin/bash
rm_ife() {
if [[ -e "$1" ]]; then
rm -r "$1"
fi
}
# Check if server is started # Check if server is started
status=$(systemctl show mcbe -p ActiveState --value) status=$(systemctl show mcbe -p ActiveState --value)
if [[ $status != active ]]; then if [[ $status != active ]]; then
@ -18,21 +24,26 @@ cd /vol/data/backup
# hourly backup # hourly backup
mcbe-exec say "Autosaving..." mcbe-exec say "Autosaving..."
if [[ -e worlds-hourly-$hour ]]; then rm_ife worlds-hourly-$hour
rm -r worlds-hourly-$hour
fi
mcbe-backup worlds-hourly-$hour mcbe-backup worlds-hourly-$hour
if [[ $hour -eq 1 ]]; then # 10#$var construction is to force base-10 interpretation of variable
# because otherwise, numbers starting with 0 are interpreted as octal
if [[ 10#$hour -eq 1 ]]; then
# if no players are present, restart the server # if no players are present, restart the server
# should help deal with any memory leaks # should help deal with any memory leaks or other bugs
players=$(mcbe-exec list | head -n 1 | cut -d ' ' -f 3 | cut -d '/' -f 1) players=""
if [[ $players == "0" ]]; then while [[ -z $players ]]; do
players=$(mcbe-exec list | head -n 1 | cut -d ' ' -f 3 | cut -d '/' -f 1)
done
if [[ $players -eq 0 ]]; then
mcbe-restart mcbe-restart
fi fi
# save daily and longterm backups # save daily and longterm backups
rsync -a worlds-hourly-$hour/ worlds-daily-$day/ rm_ife worlds-daily-$day
if [[ $day -eq 1 ]]; then mv worlds-hourly-$hour worlds-daily-$day
rsync -a worlds-daily-$day/ worlds-$year-$month-$day/ if [[ 10#$day -eq 1 ]]; then
mv worlds-daily-$day worlds-$year-$month-$day
fi fi
fi fi

18
src/mcbe/assets/bin/mcbe-backup

@ -19,15 +19,6 @@ if [[ ! -d "$worlds_dir/$world" ]]; then
exit 1 exit 1
fi fi
# Check if server is active
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."
rsync -a "$worlds_dir/" "$backup_dir/"
exit
fi
# Check if backup dir already exists # Check if backup dir already exists
if [[ -e "$backup_dir" ]]; then if [[ -e "$backup_dir" ]]; then
echo "Error: backup dir already exists. Delete directory before proceeding or use another directory name." echo "Error: backup dir already exists. Delete directory before proceeding or use another directory name."
@ -36,6 +27,15 @@ fi
mkdir -p "$backup_dir" mkdir -p "$backup_dir"
cd "$backup_dir" cd "$backup_dir"
# Check if server is active
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."
rsync -a "$worlds_dir/" ./
exit
fi
# prepare backup of active world # prepare backup of active world
status=$(mcbe-exec save hold) status=$(mcbe-exec save hold)
if [[ $status == "The command is already running" ]]; then if [[ $status == "The command is already running" ]]; then

Loading…
Cancel
Save