FIXME
Der Media Cleanup bereinigt Mediendateien, die über Matrix geteilt wurden und ein bestimmtes Alter erreicht haben. Die aktuelle Schwelle liegt bei 2 Jahren. Mediendateien, die älter sind, werden entfernt.
#!/bin/bash
TOKEN="XXXX"
PROTOCOL="http"
SERVER="127.0.0.1"
PORT=8008
# Calculate date
TIMESTAMP=$(date +%s000 --date "2 years ago")
# Build API URLs
API_URL_MEDIA_LOCAL="$PROTOCOL://$SERVER:$PORT/_synapse/admin/v1/media/delete?before_ts=$TIMESTAMP"
API_URL_MEDIA_CACHE="$PROTOCOL://$SERVER:$PORT/_synapse/admin/v1/purge_media_cache?before_ts=$TIMESTAMP"
# Check requiirements
if ! which jq > /dev/null; then
echo "jq not found. Please install required package!"
exit 1
fi
# Log
log(){
>&2 echo "${@:2}"
echo "${@:2}" | logger -i -t synapse_media_cleanup -p local0.$1
}
# Log error message
logError(){
log err "$@"
}
# Log info message
logInfo(){
log info "$@"
}
# Clean up local media
echo "Clean up local media ..."
RESPONSE=$(curl --silent --fail-with-body --header "Authorization: Bearer $TOKEN" -X POST $API_URL_MEDIA_LOCAL)
if [[ $? -ne 0 ]]; then
# Curl error
logError "Request to API failed: ${RESPONSE}"
else
logInfo "Removed $(echo $RESPONSE | jq '.total') entries from local media"
fi
# Clean up media cache
echo "Clean up media cache ..."
RESPONSE=$(curl --silent --fail-with-body --header "Authorization: Bearer $TOKEN" -X POST $API_URL_MEDIA_CACHE)
if [[ $? -ne 0 ]]; then
# Curl error
logError "Request to API failed: ${RESPONSE}"
else
logInfo "Removed $(echo $RESPONSE | jq '.deleted') entries from media cache"
fi
0 2 * * * /usr/local/bin/synapse_media_cleanup.sh > /var/log/synapse_media_cleanup.log 2>&1
Der State Compressor reduziert die Einträge in der Tabelle state_groups_state in PostgreSQL und hält so die Datenbank kompakt.
#!/bin/bash # Run compressor with CHUNK_SIZE=1000 and CHUNKS_TO_COMPRESS=10000000 /usr/local/bin/compressor/synapse_auto_compressor -p postgresql://PGSQL-USER:"PGSQL-PASS"@@10.3.0.102/synapse -c 1000 -n 1000000
0 4 * * * /usr/local/bin/compressor/synapse_auto_compressor.sh > /var/log/synapse_auto_compressor.log 2>&1
...
location:
# List of source directories to backup (required). Globs and
# tildes are expanded.
source_directories:
- /etc
- /home
- /root
- /var/log
- /var/lib/matrix-synapse
...