Remove diagram script; Add postgres-update script

This commit is contained in:
Tobias Reisinger 2023-12-09 20:51:45 +01:00
parent 1cb92e3825
commit a4a5d7f727
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 39 additions and 0 deletions

1
.gitignore vendored
View file

@ -12,6 +12,7 @@ diagram_assets/
/forgejo-runner/ /forgejo-runner/
/gitea/ /gitea/
/gitea-runner/ /gitea-runner/
/healthcheck/
/homebox/ /homebox/
/influxdb/ /influxdb/
/jellyfin/ /jellyfin/

38
_utils/postgres-update.sh Normal file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env sh
# shellcheck disable=SC2162
printf "\nWARNING: This script is work in progress and not tested yet. "; read
printf "\nStep 1: Backup done? "; read
printf "\nStep 2: Stop services - continue? "; read
systemctl stop postgresql.service
systemctl status postgresql.service --no-pager
printf "\nStep 3: Create directories and move data - continue? "; read
[ -d /var/lib/postgres/data ] && mv /var/lib/postgres/data /var/lib/postgres/olddata
mkdir /var/lib/postgres/data /var/lib/postgres/tmp
chown postgres:postgres /var/lib/postgres/data /var/lib/postgres/tmp
cd /var/lib/postgres/tmp || exit
printf "\nStep 4: Init new database - continue? "; read
sudo -u postgres initdb -D /var/lib/postgres/data --locale=en_US.UTF-8 --encoding=UTF8
printf "\nStep 5: Upgrade to new version - continue? "; read
printf "Old version: "; read -r pg_version
pg_path="/opt/pgsql-$pg_version/bin"
[ -d "$pg_path" ] || exit
sudo -u postgres pg_upgrade -b "$pg_path" -B /usr/bin -d /var/lib/postgres/olddata -D /var/lib/postgres/data
printf "\nStep 6: Restart database - continue? "; read
systemctl start postgresql.service
systemctl status postgresql.service --no-pager
printf "\nStep 7: Cleanup - continue? "; read
sudo -u postgres vacuumdb --all --analyze-in-stages
rm -r /var/lib/postgres/olddata /var/lib/postgres/tmp
printf "\nDone. "; read