]> de.git.xonotic.org Git - xonotic/xonstatdb.git/blob - scripts/create_snapshot.shl
Merge branch 'frag-matrix'
[xonotic/xonstatdb.git] / scripts / create_snapshot.shl
1 #!/bin/bash
2
3 # This script is used to create data snapshots that don't disclose any
4 # identifying player or server information.
5
6 psql -U xonstat -h localhost xonstatdb <<EOF
7 -- remove email addresses
8 update players set email_addr = NULL where email_addr IS NOT NULL;
9
10 -- sanitize the server hashkeys
11 update servers set hashkey = server_id where hashkey IS NOT NULL;
12
13 -- create a sequence to sanitize the player hashkeys
14 create sequence sanitize_seq;
15
16 -- sanitize all player hashkeys
17 update hashkeys set hashkey = nextval('sanitize_seq');
18
19 -- get rid of the sequence
20 drop sequence sanitize_seq;
21 EOF
22
23 # create a backup of the database
24 DATE=$(/bin/date +'%Y%m%d')
25
26 # backup to a compressed file loadable by the "drop_and_load.shl" script
27 pg_dump -c -U xonstat -h localhost -n xonstat --format=custom --compress=9
28 xonstatdb > ${DATE}_xonstatdb_snapshot.dmp