From fce45e26f593b79fd4953c1cb8ce66fd6848d83a Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sun, 27 Dec 2020 00:01:42 +0100 Subject: [PATCH] New step to debloat postgres database --- seqs/matrix.sh | 57 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/seqs/matrix.sh b/seqs/matrix.sh index 178d3fa..8d8412f 100755 --- a/seqs/matrix.sh +++ b/seqs/matrix.sh @@ -6,6 +6,7 @@ toolDeps+=" jq" # used as helper for api access toolDepsRaspi="ilibopenjp2-7 libtiff5" toolUser="synapse" toolGroup="synapse" +toolServiceName="matrix-synapse" synapseHashTool="env/bin/hash_password" toolUrlLocal="http://localhost:8008" # Filled by configuration @@ -121,10 +122,10 @@ step_6() { local localService=`eval "echo \"$toolService\""` addConf -c "$localService" "$toolServiceLoc" exe systemctl daemon-reload - exe systemctl enable matrix-synapse.service - exe service matrix-synapse start + exe systemctl enable ${toolServiceName}.service + exe service ${toolServiceName} start } -toolServiceLoc="/etc/systemd/system/matrix-synapse.service" +toolServiceLoc="/etc/systemd/system/${toolServiceName}.service" toolService="[Unit] Description=Matrix Synapse service After=network.target postgresql.service @@ -169,10 +170,10 @@ step_10() { step version } -step_12_info() { echo "Restart $toolName systemd service"; } +step_12_info() { echo "Restart $toolName systemd service"; echo; } step_12_alias() { ALIAS="restart"; } step_12() { - exe service matrix-synapse restart + exe service ${toolServiceName} restart } step_14_info() { echo "Show $toolName version running at [IP]:8008"; } @@ -411,18 +412,48 @@ postDataDeleteRoom() EOF } -step_30_info() { echo "Drop postgres database for $toolName"; } -step_30_alias() { ALIAS="dropdb"; } +step_30_info() { echo "Debloat postgres [DATABASE]"; echo; } +step_30_alias() { ALIAS="debloat"; } step_30() { + shift + local pgVerboseReId=" (VERBOSE) " + local pgVerboseVac=" VERBOSE" + + if [ $VERBOSE == 0 ]; then + pgVerboseReId=" " + pgVerboseVac="" + fi + + if [ -z $1 ]; then + readDatabaseInfos + else + postgresDb="$1" + fi + + echo " [I] Stopping ${toolServiceName}" + exe service ${toolServiceName} stop + endReturn -o $? "Couldn't stop ${toolServiceName}. Stopping debloat." + + exe cd ~postgres + exe su -c "psql -d ${postgresDb} -c \"REINDEX${pgVerboseReId}DATABASE ${postgresDb};\"" - postgres + exe su -c "psql -c \"VACUUM FULL${pgVerboseVac};\"" - postgres + + echo -e "\n [I] Starting ${toolServiceName}" + exe service ${toolServiceName} start +} + +step_50_info() { echo "Drop postgres database for $toolName"; } +step_50_alias() { ALIAS="dropdb"; } +step_50() { readDatabaseInfos exe cd ~postgres exe su -c "psql -c \"DROP DATABASE ${postgresDb};\"" - postgres } -step_32_info() { echo "Backup postgres database"; } -step_32_alias() { ALIAS="backupdb"; } -step_32() { +step_52_info() { echo "Backup postgres database"; } +step_52_alias() { ALIAS="backupdb"; } +step_52() { local DELYEAR=$(($(date +%Y)-2)) if [ ! -s ~/.pgpass ] ; then echo " [I] For unattended backup please define ~/.pgpass containing credentials" @@ -435,9 +466,9 @@ step_32() { toolDbBackupFolder=/root/backupdb -step_34_info() { echo "Postgres database restore"; } -step_34_alias() { ALIAS="restoredb"; } -step_34() { +step_54_info() { echo "Postgres database restore"; } +step_54_alias() { ALIAS="restoredb"; } +step_54() { echo " [I] Postgres database restore procedure" echo "1. Create a empty postgres database first (step 4)" echo "2. psql -h -U -d -W -f "