From d66564cb4bca2c41ab0d8184ab5dfe98e9c92012 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 1 Apr 2024 10:20:38 +0200 Subject: [PATCH] sample backup scripts for boc and onedrive --- process/CMakeLists.txt | 2 +- process/{backup-eressea => backup-box} | 0 process/backup-onedrive | 44 ++++++++++++++++++++++++++ process/cron/run-eressea.cron | 15 ++++++--- src/kernel/save.test.c | 1 + 5 files changed, 57 insertions(+), 5 deletions(-) rename process/{backup-eressea => backup-box} (100%) create mode 100755 process/backup-onedrive diff --git a/process/CMakeLists.txt b/process/CMakeLists.txt index f121e6966..4a4b566ac 100644 --- a/process/CMakeLists.txt +++ b/process/CMakeLists.txt @@ -1,4 +1,4 @@ -install(PROGRAMS create-orders backup-eressea run-turn send-zip-report +install(PROGRAMS create-orders backup-* run-turn send-zip-report send-bz2-report compress.py compress.sh epasswd.py accept-orders.py getemail.py checkpasswd.py sendreport.sh sendreports.sh orders-accept DESTINATION bin) diff --git a/process/backup-eressea b/process/backup-box similarity index 100% rename from process/backup-eressea rename to process/backup-box diff --git a/process/backup-onedrive b/process/backup-onedrive new file mode 100755 index 000000000..1b418053e --- /dev/null +++ b/process/backup-onedrive @@ -0,0 +1,44 @@ +#!/bin/bash +DIR=$(dirname $0) +if [ -z "$ERESSEA" ] ; then + ERESSEA="$HOME/eressea" + echo "The ERESSEA environment variable is not set. Assuming $ERESSEA." +fi +GAME=$1 + +upload() { + onedrive-cli cp "./$1" "Eressea/game-$GAME" +} + +if [ ! -d "$ERESSEA/game-$GAME" ]; then + echo "No such game: game-$GAME." + exit 1 +fi +cd "$ERESSEA/game-$GAME" || exit +TURN=$2 +if [ -z "$TURN" ]; then + TURN=$(cat turn) +fi +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 +fi + +if [ -e reports/reports.txt ] ; then + echo "backup reports $TURN, game $GAME" + tar cjf "backup/$TURN-reports.tar.bz2" reports eressea.db + upload "backup/$TURN-reports.tar.bz2" +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[@]}" +upload "backup/$TURN.tar.bz2" + diff --git a/process/cron/run-eressea.cron b/process/cron/run-eressea.cron index c0a432b35..8c9f5c8c2 100755 --- a/process/cron/run-eressea.cron +++ b/process/cron/run-eressea.cron @@ -5,6 +5,13 @@ GAME=$1 [ "$ENABLED" == "no" ] && exit [ -z "$ERESSEA" ] && ERESSEA="$HOME/eressea" +backup() +{ + if [ -x "$BIN/backup-eressea" ] ; then + "$BIN/backup-eressea" "$1" "$2" + fi +} + export ERESSEA eval "$(luarocks path)" export LUA_PATH="${ERESSEA}/server/scripts/?.lua;$LUA_PATH" @@ -37,12 +44,12 @@ if [ ! -s "orders.$TURN" ]; then exit 2 fi -"$BIN/backup-eressea" "$GAME" "$TURN" +backup "$GAME" "$TURN" rm -f execute.lock "$BIN/run-turn" "$GAME" "$TURN" touch execute.lock -let NEXTTURN=$TURN+1 +(( NEXTTURN=TURN+1 )) || true if [ ! -e "$DATA/$NEXTTURN.dat" ]; then echo "server did not create data file $NEXTTURN.dat" exit 5 @@ -51,7 +58,7 @@ if [ ! -s "$REPORTS/reports.txt" ]; then echo "server did not create reports.txt in game $GAME" exit 4 fi -"$BIN/backup-eressea" "$GAME" "$TURN" +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" @@ -65,7 +72,7 @@ fi echo "sending reports for game $GAME, turn $TURN" "$BIN/compress.sh" "$GAME" "$TURN" "$BIN/sendreports.sh" "$GAME" -"$BIN/backup-eressea" "$GAME" "$TURN" +backup "$GAME" "$TURN" rm -f test/execute.lock ) | tee -a "$HOME/log/eressea.cron.log" diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 814fb3a8b..76beb7d0f 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -15,6 +15,7 @@ #include "race.h" #include "region.h" #include "ship.h" +#include "skill.h" #include "unit.h" #include "version.h"