synapse/run_compress.sh
author Peter Gervai <grin@grin.hu>
Fri, 21 Jan 2022 10:22:39 +0100
changeset 4 721d4af9fdd7
parent 1 ba8922061637
permissions -rwxr-xr-x
Add synapse/madmin.sh: simple program to call admin API with curl.

#!/bin/sh
# compress synapse database room graphs
# (cc) Peter 'grin' Gervai, 2020

ARG="$1"

source _config.sh

set -x
CMD="SELECT room_id, COUNT(*), type FROM state_groups_state GROUP BY 1,3 HAVING COUNT(*)>999999 ORDER BY 2 DESC;"

BASE="/root/matrix-synapse/clean_auto"
LOG="${BASE}/process.log"

savelog -c 4 $LOG

TMP=`mktemp /tmp/synapse_compress.XXXXXXXX`

echo "==== `date +%F_%T` now." 						>> ${LOG}

if [ "x$ARG" = "x" ]; then
	echo "Collecting room/state groups data..."				| tee -a ${LOG}
	if ! psql "${DB}" synapse -tAc "${CMD}" > $TMP; then
		echo "Error getting room stats. Exit."
		exit 1
	fi
else
	echo "Processing already collected data ${ARG}."
	rm "${TMP}"
	TMP="$ARG"
fi


awk -F'|' '{print $1}' < $TMP | while read room; do
	NOW=`date +%F_%T`
	echo "Processing room ${room}... into c${NOW}_compress.sql" 	| tee -a ${LOG}
	/usr/bin/time ../synapse-compress-state -o "c${NOW}_compress.sql" -p "${DB}" -t -r "${room}" 	| tee -a ${LOG}
	echo "Actually compressing (c${NOW}_compress.sql)..."		| tee -a ${LOG}
	/usr/bin/time psql "${DBRW}" synapse -f "c${NOW}_compress.sql" 	| tee -a ${LOG}
done
echo "We shall delete ${TMP} file."					| tee -a ${LOG}
set +x