0
|
1 |
#!/bin/sh |
|
2 |
# compress synapse database room graphs |
|
3 |
# (cc) Peter 'grin' Gervai, 2020 |
|
4 |
|
|
5 |
ARG="$1" |
|
6 |
|
|
7 |
source _config.sh |
|
8 |
|
|
9 |
set -x |
|
10 |
CMD="SELECT room_id, COUNT(*), type FROM state_groups_state GROUP BY 1,3 HAVING COUNT(*)>999999 ORDER BY 2 DESC;" |
|
11 |
|
|
12 |
BASE="/root/matrix-synapse/clean_auto" |
|
13 |
LOG="${BASE}/process.log" |
|
14 |
|
|
15 |
savelog -c 4 $LOG |
|
16 |
|
|
17 |
TMP=`mktemp /tmp/synapse_compress.XXXXXXXX` |
|
18 |
|
|
19 |
echo "==== `date +%F_%T` now." >> ${LOG} |
|
20 |
|
|
21 |
if [ "x$ARG" = "x" ]; then |
|
22 |
echo "Collecting room/state groups data..." | tee -a ${LOG} |
|
23 |
if ! psql "${DB}" synapse -tAc "${CMD}" > $TMP; then |
|
24 |
echo "Error getting room stats. Exit." |
|
25 |
exit 1 |
|
26 |
fi |
|
27 |
else |
|
28 |
echo "Processing already collected data ${ARG}." |
|
29 |
rm "${TMP}" |
|
30 |
TMP="$ARG" |
|
31 |
fi |
|
32 |
|
|
33 |
|
|
34 |
awk -F'|' '{print $1}' < $TMP | while read room; do |
|
35 |
NOW=`date +%F_%T` |
|
36 |
echo "Processing room ${room}... into c${NOW}_compress.sql" | tee -a ${LOG} |
|
37 |
/usr/bin/time ../synapse-compress-state -o "c${NOW}_compress.sql" -p "${DB}" -t -r "${room}" | tee -a ${LOG} |
|
38 |
echo "Actually compressing (c${NOW}_compress.sql)..." | tee -a ${LOG} |
|
39 |
/usr/bin/time psql "${DBRW}" synapse -f "c${NOW}_compress.sql" | tee -a ${LOG} |
|
40 |
done |
|
41 |
echo "We shall delete ${TMP} file." | tee -a ${LOG} |
|
42 |
set +x |
|
43 |
|