Add tmp everywhere
This commit is contained in:
parent
0bf3288b3e
commit
7b717c14ae
|
@ -18,39 +18,39 @@ function get_room {
|
|||
total_room=$(curl -s --header "Authorization: Bearer ${ACCESS_TOKEN}" "${HS_URL}${API_URL}rooms?limit=1" | jq --raw-output ".total_rooms")
|
||||
|
||||
info "Get ${total_room} rooms"
|
||||
curl -s --header "Authorization: Bearer ${ACCESS_TOKEN}" "${HS_URL}${API_URL}rooms?limit=${total_room}" > "${CLEAN_FOLDER}/roomlist.json"
|
||||
curl -s --header "Authorization: Bearer ${ACCESS_TOKEN}" "${HS_URL}${API_URL}rooms?limit=${total_room}" > "/tmp/${CLEAN_FOLDER}/roomlist.json"
|
||||
}
|
||||
|
||||
function get_purge {
|
||||
jq --raw-output '.rooms[] | select(.joined_local_members == 0) | .room_id' < "${CLEAN_FOLDER}/roomlist.json" > "${CLEAN_FOLDER}/to_purge.txt"
|
||||
jq --raw-output '.rooms[] | select(.joined_local_members == 0) | .room_id' < "/tmp/${CLEAN_FOLDER}/roomlist.json" > "/tmp/${CLEAN_FOLDER}/to_purge.txt"
|
||||
}
|
||||
|
||||
function get_id {
|
||||
jq --raw-output '.rooms[] | .room_id' < "${CLEAN_FOLDER}/roomlist.json" > "${CLEAN_FOLDER}/roomids.txt"
|
||||
jq --raw-output '.rooms[] | .room_id' < "/tmp/${CLEAN_FOLDER}/roomlist.json" > "/tmp/${CLEAN_FOLDER}/roomids.txt"
|
||||
}
|
||||
info "Starting at $(date)"
|
||||
|
||||
info "Create ${CLEAN_FOLDER}"
|
||||
mkdir -p "${CLEAN_FOLDER}"
|
||||
info "Create /tmp/${CLEAN_FOLDER}"
|
||||
mkdir -p "/tmp/${CLEAN_FOLDER}"
|
||||
|
||||
purge_img
|
||||
get_room
|
||||
get_purge
|
||||
info "Pruning empty room"
|
||||
for room_id in $(cat "${CLEAN_FOLDER}/to_purge.txt")
|
||||
for room_id in $(cat "/tmp/${CLEAN_FOLDER}/to_purge.txt")
|
||||
do
|
||||
info "Pruning ${room_id}"
|
||||
curl -X POST -d '{"room_id": "'${room_id}'"}' "${HS_URL}${API_URL}purge_room?access_token=${ACCESS_TOKEN}"
|
||||
sleep 1
|
||||
done
|
||||
info "clean ${CLEAN_FOLDER}"
|
||||
rm -rf "${CLEAN_FOLDER}"/*
|
||||
info "clean /tmp/${CLEAN_FOLDER}"
|
||||
rm -rf "/tmp/${CLEAN_FOLDER}"/*
|
||||
|
||||
get_room
|
||||
get_id
|
||||
|
||||
info "Start purging"
|
||||
for room_id in $(cat "${CLEAN_FOLDER}/roomids.txt")
|
||||
for room_id in $(cat "/tmp/${CLEAN_FOLDER}/roomids.txt")
|
||||
do
|
||||
info "Purge ${room_id}"
|
||||
purge_id=$(curl -s -X POST -d '{"purge_up_to_ts":'$(($(date --date="1 month ago" +%s%N)/1000000))', "delete_local_events": true}' "${HS_URL}${API_URL}purge_history/${room_id}?access_token=${ACCESS_TOKEN}" | jq --raw-output '.purge_id')
|
||||
|
@ -71,22 +71,22 @@ then
|
|||
get_id
|
||||
|
||||
info "Compress states"
|
||||
for room_id in $(cat "${CLEAN_FOLDER}/roomids.txt")
|
||||
for room_id in $(cat "/tmp/${CLEAN_FOLDER}/roomids.txt")
|
||||
do
|
||||
info "Get state compression for ${room_id}"
|
||||
${SYNAPSE_COMPRESS_STATE_PATH} -t -o "${CLEAN_FOLDER}/state-compressor.sql" -p "host=${HOST} user=${USER} password=${PASSWORD} dbname=${DBNAME}" -r "${room_id}"
|
||||
${SYNAPSE_COMPRESS_STATE_PATH} -t -o "/tmp/${CLEAN_FOLDER}/state-compressor.sql" -p "host=${HOST} user=${USER} password=${PASSWORD} dbname=${DBNAME}" -r "${room_id}"
|
||||
|
||||
info "Import state compression"
|
||||
cat "${CLEAN_FOLDER}/state-compressor.sql"
|
||||
PGPASSWORD=${PASSWORD} psql -h "${HOST}" -U "${USER}" "${DBNAME}" < "${CLEAN_FOLDER}/state-compressor.sql"
|
||||
cat "/tmp/${CLEAN_FOLDER}/state-compressor.sql"
|
||||
PGPASSWORD=${PASSWORD} psql -h "${HOST}" -U "${USER}" "${DBNAME}" < "/tmp/${CLEAN_FOLDER}/state-compressor.sql"
|
||||
|
||||
info "Ending, remove file"
|
||||
rm -f "${CLEAN_FOLDER}/state-compressor.sql"
|
||||
rm -f "/tmp/${CLEAN_FOLDER}/state-compressor.sql"
|
||||
info "Finish remove"
|
||||
done
|
||||
|
||||
info "Cleaning"
|
||||
rm -rf "${CLEAN_FOLDER}"
|
||||
rm -rf "/tmp/${CLEAN_FOLDER}"
|
||||
|
||||
PGPASSWORD=${PASSWORD} psql -h "${HOST}" -U "${USER}" "${DBNAME}" -c "REINDEX DATABASE ${DBNAME};"
|
||||
PGPASSWORD=${PASSWORD} psql -h "${HOST}" -U "${USER}" "${DBNAME}" -c "VACUUM FULL VERBOSE;"
|
||||
|
|
Loading…
Reference in New Issue