summaryrefslogtreecommitdiff
path: root/tools/unarchive.sh
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-03-24 18:42:29 +0100
committerTor Andersson <tor@ccxvii.net>2024-03-25 23:18:55 +0100
commit38bd46ce38f2b44bcebc329343a5ab479c8b7e84 (patch)
tree741d8a80181940776e0aa5dc4a6689abb49d6c87 /tools/unarchive.sh
parent6d56af566dc688e3f2af800dbd17950b06297fe7 (diff)
downloadserver-38bd46ce38f2b44bcebc329343a5ab479c8b7e84.tar.gz
Add tool to restore archived game state.
Diffstat (limited to 'tools/unarchive.sh')
-rw-r--r--tools/unarchive.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/unarchive.sh b/tools/unarchive.sh
new file mode 100644
index 0000000..6adb300
--- /dev/null
+++ b/tools/unarchive.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+# Restore purged game state from archive.
+
+if [ -z "$1" ]
+then
+ echo 'usage: bash tools/unarchive.sh <gameid>'
+ exit 1
+fi
+
+sqlite3 db << EOF
+
+attach database 'archive.db' as archive;
+
+begin;
+
+select 'RESTORE ' || $1 || ' FROM ARCHIVE';
+
+.mode table
+select * from archive.games where game_id = $1;
+
+insert or replace into game_state (game_id, state)
+ select game_id, state
+ from archive.game_state where game_id = $1;
+
+insert or replace into game_replay (game_id, replay_id, role, action, arguments)
+ select game_id, replay_id, role, action, arguments
+ from archive.game_replay where game_id = $1;
+
+insert or replace into game_chat (game_id, chat_id, user_id, time, message)
+ select game_id, chat_id, user_id, time, message
+ from archive.game_chat where game_id = $1;
+
+commit;
+
+EOF