Skip to content

Commit

Permalink
fix the backups quickly, needs some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling committed Apr 14, 2024
1 parent 992e9ac commit 3ecfb9a
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions process/cron/run-eressea.cron
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,55 @@ GAME=$1
[ "$ENABLED" == "no" ] && exit
[ -z "$ERESSEA" ] && ERESSEA="$HOME/eressea"

upload()
{
FILEPATH=$(realpath "$1")
scp "$FILEPATH" "synology:Backup/Eressea/game-$GAME/"
}

backup_reports()
{
GAME="$1"
TURN="$2"
files=("data/$TURN.dat" parteien.full parteien)
if [ -e "orders.$TURN" ]; then
files+=("orders.$TURN")
fi
echo "backup turn $TURN, game $GAME, files: ${files[*]}"
tar cjf "backup/$TURN.tar.bz2" "${files[@]}"
upload "backup/$TURN.tar.bz2"
echo "backup reports $TURN, game $GAME"
tar cjf "backup/$TURN-reports.tar.bz2" reports eressea.db
echo "backup/$TURN-reports.tar.bz2"
}

backup()
{
<<<<<<< Updated upstream
if [ -x "$BIN/backup-eressea" ] ; then
"$BIN/backup-eressea" "$@"
=======
GAME="$1"
TURN="$2"
cd "$ERESSEA/game-$GAME" || exit
if [ ! -e "data/$TURN.dat" ]; then
echo "No data for turn $TURN in game $GAME."
exit 2
fi
if [ ! -d backup ] ; then
echo "creating missing backup directory for game $GAME."
mkdir -p "$HOME/backup/eressea/game-$GAME"
ln -sf "$HOME/backup/eressea/game-$GAME" backup
>>>>>>> Stashed changes
fi

files=("data/$TURN.dat" parteien.full parteien)
if [ -e "orders.$TURN" ]; then
files+=("orders.$TURN")
fi
echo "backup turn $TURN, game $GAME, files: ${files[*]}"
tar cjf "backup/$TURN.tar.bz2" "${files[@]}"
echo "backup/$TURN.tar.bz2"
}

export ERESSEA
Expand Down Expand Up @@ -44,7 +88,9 @@ if [ ! -s "orders.$TURN" ]; then
exit 2
fi

backup "$GAME" "$TURN"
## pre-game backup, data and orders only:
BACKUP=$(backup "$GAME" "$TURN")
upload "$BACKUP"
rm -f execute.lock
"$BIN/run-turn" "$GAME" "$TURN"
touch execute.lock
Expand All @@ -58,21 +104,24 @@ if [ ! -s "$REPORTS/reports.txt" ]; then
echo "server did not create reports.txt in game $GAME"
exit 4
fi
backup "$GAME" "$TURN"
TURN=$NEXTTURN
if [ ! -s "$ERESSEA/game-$GAME/data/$TURN.dat" ]; then
echo "server did not create data for turn $TURN in game $GAME"
exit 3
fi
echo "sending reports for game $GAME, turn $TURN"
"$BIN/compress.sh" "$GAME" "$TURN"
"$BIN/sendreports.sh" "$GAME"
## post-game backup of new data:
NEWFILE=$(backup "$GAME" "$TURN")
upload "$NEWFILE"
## post-game backup of reports:
backup_reports "$GAME" "$TURN"
if [ ! -f "express-$TURN.txt" ]; then
if [ -f express.txt ]; then
mv express.txt "express-$TURN.txt"
fi
fi
echo "sending reports for game $GAME, turn $TURN"
"$BIN/compress.sh" "$GAME" "$TURN"
"$BIN/sendreports.sh" "$GAME"
backup "$GAME" "$TURN"
rm -f test/execute.lock
) | tee -a "$HOME/log/eressea.cron.log"

0 comments on commit 3ecfb9a

Please sign in to comment.