cat $LOGFILE| mail -s "${SUJET} : ${RESULTAT}"${POSTMASTER}
["${RESULTAT}"="OK"]&&exit0||exit1
}
#####################################
# Main
#####################################
# pre-cleanup
jnl "Remove temporary files..."
rm -f /opt/synapse-compress/*.sql
rm -f /root/matrix_cleanup/*.txt
jnl "Dumping current status on Database"
biggestTables=$(echo"SELECT nspname || '.' || relname AS \"relation\", pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C.relkind <> 'i' AND nspname !~ '^pg_toast' ORDER BY pg_total_relation_size(C.oid) DESC LIMIT 20;"| psql -h ${PGHOST} -d ${PGDB} -U ${PGUSER})
curl -X POST -H "HOST: ${FQDN}" -H "Authorization: Bearer $TOKEN""http://127.0.0.1:8008/_synapse/admin/v1/purge_media_cache?before_ts=$(one_year_ago)"
jnl "Optimizing synapse cache for rooms with more than 100 000 state changes"
# Get the list of rooms with more than 99 999 state groups events
jnl "Gathering list"
psql -h "${PGHOST}" -d "${PGDB}" -U "${PGUSER}" -t -c "SELECT room_id, count(*) AS count FROM state_groups_state GROUP BY room_id HAVING count(*) > 99999 ORDER BY count DESC;"| sed -r 's/\s//g'| egrep -v '^$'|awk -F "|"'{print $1}' > ${WORKDIR}/to_compress.txt
jnl "Prepare compression files state-compressor"
cpt=1
whileread room_id;do
# Could we remove the password / is it using .pgpass?