Last active
January 14, 2023 22:35
-
-
Save rubo77/5305b76a3805e1b6524ff8e5d5c3d15f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script purges the local history older than 90 days in some rooms, that you can define in an array | |
# | |
# crontab -e | |
# 23 4 * * * bash /home/irc-bridge/.synapse/EIGENE_purge_history_daily > /dev/null 2>&1 | |
cd /home/irc-bridge/.synapse/ | |
DOMAIN="matrix.yourserver.org" | |
ADMIN="@some_adminuser:matrix.yourserver.org" | |
TOKEN=$(psql -t -A --dbname="synapse" --command="select token from access_tokens where user_id='$ADMIN' order by id desc limit 1;" |grep -v "Pager") | |
#------------------ | |
TIME='90 days ago' | |
UNIX_TIMESTAMP=$(date +%s%3N --date='TZ="UTC+2" '"$TIME") | |
#rooms | |
ROOMS_ARRAY=( | |
'!kctHiBoIzDvfWZiGxI:matrix.yourserver.org' | |
'!gNfrEAqZhLtlSwOAYS:matrix.yourserver.org' | |
'!WgdJDQCGXmzzsYfGuo:matrix.yourserver.org' | |
'!iKYnoXwCXUpxsRFQrI:matrix.yourserver.org' | |
'!MBBFSjjzZSUazforjQ:matrix.yourserver.org' | |
) | |
for ROOM_NAME in "${ROOMS_ARRAY[@]}" | |
do | |
: | |
EVENT_ID=$(psql -A -t --dbname="synapse" --command="select event_id from events where type='m.room.message' and received_ts<'$UNIX_TIMESTAMP' and room_id='$ROOM_NAME' order by received_ts desc limit 1;"|grep -v 'Pager') | |
sleep 1 | |
curl -X POST $DOMAIN':8008/_matrix/client/r0/admin/purge_history/'$ROOM_NAME'/'$EVENT_ID'?access_token='$TOKEN | |
sleep 1 | |
done | |
A nice script. Another idea for cleaning all rooms without a defined array:
ROOMS=$(sudo -u postgres psql -t -A --dbname="synapse" --command="SELECT room_id FROM rooms;")
and
for ROOM_NAME in $ROOMS
...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script purges the local history in some rooms, that you can define in an array