Add matrix room cleaning script
This commit is contained in:
parent
dad01767b5
commit
5c5b12cfe6
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eou pipefail
|
||||||
|
|
||||||
|
# Get the list of rooms with no local users
|
||||||
|
empty_rooms() {
|
||||||
|
psql -d synapse -c "SELECT room_id FROM room_stats_current WHERE local_users_in_room = 0 \
|
||||||
|
ORDER BY current_state_events DESC LIMIT 1;" -t --csv
|
||||||
|
}
|
||||||
|
|
||||||
|
# Delete a room and purge its history
|
||||||
|
delete_room() {
|
||||||
|
details=$(synadm room details $1)
|
||||||
|
name=$(echo $details | jq -r '.name')
|
||||||
|
canonical_alias=$(echo $details | jq -r '.canonical_aliacanonical_alias')
|
||||||
|
topic=$(echo $details | jq -r '.topic')
|
||||||
|
joined_local_members=$(echo $details | jq -r '.joined_local_members')
|
||||||
|
state_events=$(echo $details | jq -r '.state_events')
|
||||||
|
echo "Deleting room $1 (name: $name, canonical alias: $canonical_alias, topic: $topic)[$joined_local_members]"
|
||||||
|
echo "This will remove $state_events state events"
|
||||||
|
if [[ $joined_local_members == "0" ]];
|
||||||
|
then
|
||||||
|
time synadm --yes room delete $1
|
||||||
|
else
|
||||||
|
echo "Room still had active members!!! $1"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
log_file="empty-removal-$(date -Iminutes).log"
|
||||||
|
touch $log_file
|
||||||
|
for room in $(empty_rooms); do
|
||||||
|
delete_room $room | tee -a $log_file
|
||||||
|
done
|
Loading…
Reference in New Issue