]> git.rm.cloudns.org Git - xonotic/xonstatdb.git/commitdiff
Add a script to create a data snapshot of the DB.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 19 Jan 2017 21:51:07 +0000 (16:51 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 19 Jan 2017 21:51:07 +0000 (16:51 -0500)
scripts/create_snapshot.shl [new file with mode: 0755]

diff --git a/scripts/create_snapshot.shl b/scripts/create_snapshot.shl
new file mode 100755 (executable)
index 0000000..2f07d1a
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+# This script is used to create data snapshots that don't disclose any
+# identifying player or server information.
+
+psql -U xonstat -h localhost xonstatdb <<EOF
+-- remove email addresses
+update players set email_addr = NULL where email_addr IS NOT NULL;
+
+-- sanitize the server hashkeys
+update servers set hashkey = server_id where hashkey IS NOT NULL;
+
+-- create a sequence to sanitize the player hashkeys
+create sequence sanitize_seq;
+
+-- sanitize all player hashkeys
+update hashkeys set hashkey = nextval('sanitize_seq');
+
+-- get rid of the sequence
+drop sequence sanitize_seq;
+EOF
+
+# create a backup of the database
+DATE=$(/bin/date +'%Y%m%d')
+
+# backup to a compressed file loadable by the "drop_and_load.shl" script
+pg_dump -c -U xonstat -h localhost -n xonstat --format=custom --compress=9
+xonstatdb > ${DATE}_xonstatdb_snapshot.dmp