The logic is here:
root@438242:~# cat rotate-backup.sh
# Rotation and backup script for the Simutrans-Experimental server
# Written by James E. Petts, December 2012
# Modified September 2018 to add thd date/time
# This script is designed to:
# (1) check whether the saved game has been modified in the last hour;
# (2) if it has not, run the force-sync command;
# (3) check again whether the saved game has been modified in the last hour
# (the force-sync command might or might not modify it depending on whether -
# (a) Simutrans-Experimental is running; and
# (b) there are any players connected); and
# (4) if it has, rotate the saved games using the rotate.sh script.
echo
echo "******"
echo
echo "Running the backup and rotation script..."
echo
echo "The current date and time is"
date
echo
SAVEGAME="/usr/share/games/simutrans-extended/server13353-network.sve"
# Check that the server saved game exists at all
if [ ! -e $SAVEGAME ]
then
echo "Error: saved game not found at $SAVEGAME"
echo
exit 1
fi
# Check the current time and the last modification time of the saved game file
# Use Unix time (seconds since 1 Jan. 1970)
NOWTIME=$(date +%s)
NOWTIME_FRIENDLY=date
SAVEMODTIME=$(stat -c %Y $SAVEGAME)
SAVEMODTIME_FRIENDLY="stat -c %y $SAVEGAME"
HOURAGO=$(expr $NOWTIME - 3600)
HALFHOURAGO=$(expr $NOWTIME - 1800)
echo "Current time:"
$NOWTIME_FRIENDLY
echo
echo "Game last saved:"
$SAVEMODTIME_FRIENDLY
echo
# Check whether the saved game was modified more than an hour ago
if [ $HALFHOURAGO -gt $SAVEMODTIME ]
then
echo "The game was last saved more than half an hour ago. Run a force sync."
echo
/root/force-sync.sh
# Check again whether the saved game was modified more than an hour ago.
# But first, wait two minutes, as it might take a while to execute the
# force-sync command.
sleep 120
else
echo "The game was last saved within half an hour - do not run a force sync."
echo
fi
NEWSAVEMODTIME=$(stat -c %Y $SAVEGAME)
if [ $HOURAGO -gt $NEWSAVEMODTIME ]
then
echo "The game was not updated with a force-sync. Either the server is not running, or no clients are connected."
echo
exit 2
else
echo "The saved game has been updated in the last hour. Rotate the backups."
echo
/root/rotate.sh
fi
sync
The above is a shell script set to run once every minute on the server.