Minecraft: improving backup:

1. Now it uses just 1 screen session
2. Backup wait for the right trigger on log file to save
This commit is contained in:
Bruno F. Fontes 2020-05-21 16:07:38 -03:00
parent 9ae2401091
commit dcc4511ebb
Signed by: brunofontes
GPG Key ID: EE3447CE80048495

View File

@ -1,23 +1,57 @@
if ! screen -list | grep -q "minecraftPE"; then if ! screen -list | grep -q "Minecraft"; then
exit 1 exit 1
fi fi
function runAllWorlds () { BACKUPDIR="/home/bruno/Backups/Minecraft"
screen -S minecraftPESurvival -X stuff "$1" SERVERDIR="/home/bruno/Apps/Minecraft"
screen -S minecraftPECreative -X stuff "$1" SURVIVALDIR="$SERVERDIR/BedrockServer_Survival_19132"
} CREATIVEDIR="$SERVERDIR/BedrockServer_Creative_19134"
LogFile="log.txt"
runAllWorlds "say $(date +%l:%M)\n" alias run='screen -S Minecraft -X'
alias runSurvival='run at Survival stuff'
alias runCreative='run at Creative stuff'
alias runAllWorlds='run at "#" stuff'
HORA=$(date +%H) cd /home/bruno/Apps/Minecraft
if [ "$HORA" -ge 23 ]; then
screen -S minecraftPECreative -X stuff $'say Hora de dormir\n'
sleep 5
screen -S minecraftPECreative -X stuff $'stop\n'
if [ "$HORA" -ge 1 -a "$HORA" -lt 5 ]; then runAllWorlds "^u"
screen -S minecraftPESurvival -X stuff $'say Hora de dormir\n' runAllWorlds "say $(date +%l:%M) - Saving worlds\n"
source /home/bruno/Apps/Minecraft/stopServers.sh runAllWorlds "save hold\n"
sleep 2s
finishedCreative=""
timeout=30
while [[ $finishedCreative != *"Data saved."* ]]; do
if [[ $timeout -lt 1 ]]; then
notify-send "Error backuping Creative world"
exit 1
fi fi
(( timeout-- ))
sleep 1s
runCreative "^u"
runCreative "save query\n"
finishedCreative=$(tail -n 4 "$CREATIVEDIR/$LogFile")
done
timeout=30
finishedSurvival=""
while [[ $finishedSurvival != *"Data saved."* ]]; do
if [[ $timeout -lt 1 ]]; then
notify-send "Error backuping Survival world"
exit 1
fi fi
(( timeout-- ))
sleep 1s
runSurvival "^u"
runSurvival "save query\n"
finishedSurvival=$(tail -n 4 "$SURVIVALDIR/$LogFile")
done
BACKUPDATE=$(date +"%Y-%m-%d_%H-%M-%S")
mkdir "$BACKUPDIR/$BACKUPDATE"
/bin/tar cz --exclude=behavior_packs/* --exclude=resource_packs/* -f "$BACKUPDIR/$BACKUPDATE/Survival.tar.gz" "$SURVIVALDIR/worlds/Survival"
/bin/tar cz --exclude=behavior_packs/* --exclude=resource_packs/* -f "$BACKUPDIR/$BACKUPDATE/Creative.tar.gz" "$CREATIVEDIR/worlds/Creative"
runAllWorlds "^u"
runAllWorlds "save resume\n"