@@ -24,6 +24,7 @@ RESTIC_HOSTNAME="" # Leave empty to use system hostname
2424LOCK_FILE=" " # Optional lock file to acquire to ensure two backups don't run at once
2525LOCK_FILE_TIMEOUT=" " # Optional lock file wait timeout (in seconds)
2626WINDOW_MANAGER=" screen" # Choices: screen, tmux, RCON
27+ SAVE_ALL_WAIT_SECONDS=" " # Delay in seconds after save-all flush (default: 5, 0 if rcon)
2728
2829# Other Variables (do not modify)
2930DATE_FORMAT=" %F_%H-%M-%S"
@@ -41,7 +42,7 @@ debug-log () {
4142 fi
4243}
4344
44- while getopts ' a:cd:e:f:hH:i:l:m:o:p:qr:s:t:u:vw:x ' FLAG; do
45+ while getopts ' a:cd:e:f:hH:i:l:m:o:p:qr:s:t:u:vw:xz: ' FLAG; do
4546 case $FLAG in
4647 a) COMPRESSION_ALGORITHM=$OPTARG ;;
4748 c) ENABLE_CHAT_MESSAGES=true ;;
@@ -69,6 +70,7 @@ while getopts 'a:cd:e:f:hH:i:l:m:o:p:qr:s:t:u:vw:x' FLAG; do
6970 echo " -u Lock file timeout seconds (empty = unlimited)"
7071 echo " -v Verbose mode"
7172 echo " -w Window manager: screen (default), tmux, RCON"
73+ echo " -z Delay in seconds after save-all flush (default: 5, 0 if rcon)"
7274 exit 0
7375 ;;
7476 H) RESTIC_HOSTNAME=$OPTARG ;;
@@ -84,6 +86,7 @@ while getopts 'a:cd:e:f:hH:i:l:m:o:p:qr:s:t:u:vw:x' FLAG; do
8486 u) LOCK_FILE_TIMEOUT=$OPTARG ;;
8587 v) DEBUG=true ;;
8688 w) WINDOW_MANAGER=$OPTARG ;;
89+ z) SAVE_ALL_WAIT_SECONDS=$OPTARG ;;
8790 * ) log-fatal " Invalid option -$FLAG " ; exit 1 ;;
8891 esac
8992done
@@ -290,6 +293,25 @@ message-players-color () {
290293 execute-command " tellraw @a [\"\" ,{\" text\" :\" [$PREFIX ] \" ,\" color\" :\" gray\" ,\" italic\" :true},{\" text\" :\" $MESSAGE \" ,\" color\" :\" $COLOR \" ,\" italic\" :true,\" hoverEvent\" :{\" action\" :\" show_text\" ,\" value\" :{\" text\" :\"\" ,\" extra\" :[{\" text\" :\" $HOVER_MESSAGE \" }]}}}]"
291294 fi
292295}
296+ save-all-flush-delay-seconds () {
297+ if [[ -n " $SAVE_ALL_WAIT_SECONDS " ]]; then
298+ echo " $SAVE_ALL_WAIT_SECONDS "
299+ return
300+ fi
301+
302+ case " $WINDOW_MANAGER " in
303+ # RCON already waits for response
304+ " RCON" |" rcon" |" docker-rcon" ) echo " 0"
305+ ;;
306+ * ) echo " 5" # default value for all other cases
307+ ;;
308+ esac
309+ }
310+ execute-save-all-flush () {
311+ execute-command " save-all" # for versions <1.16
312+ execute-command " save-all flush"
313+ sleep " $( save-all-flush-delay-seconds) "
314+ }
293315
294316# Parse file timestamp to one readable by "date"
295317parse-file-timestamp () {
@@ -489,9 +511,12 @@ do-backup () {
489511 # Notify players of start
490512 message-players " Starting backup..." " $ARCHIVE_PATH "
491513
492- # Disable world autosaving
514+ # Disable world autosaving, still allows save-all
493515 execute-command " save-off"
494516
517+ # Trigger save now to get most up-to-date data
518+ execute-save-all-flush
519+
495520 # Backup world
496521 START_TIME=$( date +" %s" )
497522
0 commit comments