40 lines
1.3 KiB
Bash
40 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
#
|
|
# Cleanup of local and remote media
|
|
#
|
|
|
|
# Requirements:
|
|
# You'll need the domain of your server (variable "serverDomain").
|
|
#
|
|
# For authentication, you will need the access token of your (admin) account.
|
|
# You can obtain it in your Element client: "All settings" > "Help & About" > scroll down > click on "<click to reveal>" to get your access token.
|
|
# Copy this token and paste it further down (variable "token").
|
|
#
|
|
# You can also specify another time span for deleting media.
|
|
# Default is media, which was not accessed over the last 60 days (variable "timestamp60DaysAgo")
|
|
#
|
|
# You can automate this script via cron, e.g. cleanup every night:
|
|
# 0 1 * * * /path/to/scripts/Matrix-Synapse-Helpers/CleanupMedia.sh > /dev/null 2>&1
|
|
|
|
serverDomain="matrix.mydomain.com"
|
|
token="insert-token-here"
|
|
timestamp60DaysAgo=`date +%s000 --date "60 days ago"`
|
|
|
|
# Delete local media
|
|
echo "Delete local media..."
|
|
echo ""
|
|
curlUrl="http://localhost:8008/_synapse/admin/v1/media/$serverDomain/delete?before_ts=$timestamp60DaysAgo&access_token=$token"
|
|
curl -XPOST $curlUrl
|
|
echo ""
|
|
echo "Done"
|
|
echo ""
|
|
|
|
# Purge remote media
|
|
echo "Purge remote media..."
|
|
echo ""
|
|
curlUrl="http://localhost:8008/_synapse/admin/v1/purge_media_cache?before_ts=$timestamp60DaysAgo&access_token=$token"
|
|
curl -XPOST $curlUrl
|
|
echo ""
|
|
echo "Done"
|
|
echo "" |