5
0

synapse-purge-compress.sh: be less verbose

This commit is contained in:
sceox 2021-10-09 11:10:57 -07:00
parent 9f918ba30c
commit 5609ccf6a6

View File

@ -8,6 +8,8 @@ port='8008'
synapse_log='/var/log/matrix-synapse/homeserver.log' synapse_log='/var/log/matrix-synapse/homeserver.log'
homeserver_config='/etc/matrix-synapse/homeserver.yaml' homeserver_config='/etc/matrix-synapse/homeserver.yaml'
debug=0
# don't bother compressing unless we will save this much: # don't bother compressing unless we will save this much:
min_compression_percent=15 min_compression_percent=15
@ -25,6 +27,11 @@ fi
ts_history="$(date -d-${range} +%s)000" ts_history="$(date -d-${range} +%s)000"
ts_media="$(date -d-1month +%s)000" ts_media="$(date -d-1month +%s)000"
debug () {
if [ "$debug" = 1 ]; then
echo $* 1>&2
fi
}
get_obsolete_rooms () { get_obsolete_rooms () {
curl --silent -H "Authorization: Bearer $token" \ curl --silent -H "Authorization: Bearer $token" \
"${host}:${port}/_synapse/admin/v1/rooms" \ "${host}:${port}/_synapse/admin/v1/rooms" \
@ -63,16 +70,14 @@ purge_history () {
--header "Authorization: Bearer $token" \ --header "Authorization: Bearer $token" \
-d "{ \"delete_local_events\": false, \"purge_up_to_ts\": $ts_history }" \ -d "{ \"delete_local_events\": false, \"purge_up_to_ts\": $ts_history }" \
"${host}:${port}/_synapse/admin/v1/purge_history/${room_id}") "${host}:${port}/_synapse/admin/v1/purge_history/${room_id}")
echo $json | jq
if echo $json | grep -q 'purge_id'; then if echo $json | grep -q 'purge_id'; then
echo "waiting for purge to complete..." debug "waiting for purge to complete..."
tail -n 0 -f $synapse_log \ tail -n 0 -f $synapse_log \
| sed '/\[purge\] complete/q' > /dev/null | sed '/\[purge\] complete/q' > /dev/null
echo "purge completed." debug "purge completed."
fi fi
done done
echo "it is recommended to run VACUUM FULL on the database now"
echo "(note: VACUUM FULL requires up to 50% of the disk be available)"
} }
purge_media_cache () { purge_media_cache () {
@ -91,7 +96,7 @@ compress_state () {
-r "$room_id" | sed -n '/%/s/.*(\([0-9]*\).[0-9]*%).*/\1/p') -r "$room_id" | sed -n '/%/s/.*(\([0-9]*\).[0-9]*%).*/\1/p')
if [ "$repl" -le "$((100 - $min_compression_percent))" ]; then if [ "$repl" -le "$((100 - $min_compression_percent))" ]; then
echo "compressing room" $room_id "..." debug "compressing room" $room_id "..."
psql -q -U 'synapse' -f $sqlf 'synapse' psql -q -U 'synapse' -f $sqlf 'synapse'
fi fi
rm $sqlf rm $sqlf