- the new yhub service needs new initialisation and RSA keys - SOFT_MIGRATION on by default, add migrate_documents command - back up the yhub database too - document the v5 -> v6 upgrade in README and release/next Following the [C4DT AI Policy](https://git.coopcloud.tech/c4dt/ai-policy/src/branch/main/AI-POLICY.md): #LLM_vibe #LLM_model Claude Opus 5.5 - [x] I take full responsibility for this code - [x] I understand every line of this code - [x] I tested this code thoroughly on my own computer / servers - [x] None of the commit messages were created using LLMs - [x] I will participate in any discussion on my own and will not use an LLM for the discussion
47 lines
1.5 KiB
Bash
47 lines
1.5 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
BACKUP_FILE='/var/lib/postgresql/data/pgdata/backup.sql'
|
|
# database of the collaboration server (yhub), since v6
|
|
YHUB_DB='yhub'
|
|
YHUB_BACKUP_FILE='/var/lib/postgresql/data/pgdata/backup-yhub.sql'
|
|
|
|
function backup {
|
|
export PGPASSWORD=$(cat $POSTGRES_PASSWORD_FILE)
|
|
pg_dump -U ${POSTGRES_USER} ${POSTGRES_DB} > $BACKUP_FILE
|
|
if psql -U ${POSTGRES_USER} -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='${YHUB_DB}'" | grep -q 1; then
|
|
pg_dump -U ${POSTGRES_USER} ${YHUB_DB} > $YHUB_BACKUP_FILE
|
|
fi
|
|
}
|
|
|
|
function restore {
|
|
cd /var/lib/postgresql/data/pgdata/
|
|
restore_config(){
|
|
# Restore allowed connections
|
|
cat pg_hba.conf.bak > pg_hba.conf
|
|
su postgres -c 'pg_ctl reload'
|
|
}
|
|
# Don't allow any other connections than local
|
|
cp pg_hba.conf pg_hba.conf.bak
|
|
echo "local all all trust" > pg_hba.conf
|
|
su postgres -c 'pg_ctl reload'
|
|
trap restore_config EXIT INT TERM
|
|
|
|
# Recreate Database
|
|
psql -U ${POSTGRES_USER} -d postgres -c "DROP DATABASE ${POSTGRES_DB} WITH (FORCE);"
|
|
createdb -U ${POSTGRES_USER} ${POSTGRES_DB}
|
|
psql -U ${POSTGRES_USER} -d ${POSTGRES_DB} -1 -f $BACKUP_FILE
|
|
|
|
if [ -f $YHUB_BACKUP_FILE ]; then
|
|
psql -U ${POSTGRES_USER} -d postgres -c "DROP DATABASE IF EXISTS ${YHUB_DB} WITH (FORCE);"
|
|
createdb -U ${POSTGRES_USER} ${YHUB_DB}
|
|
psql -U ${POSTGRES_USER} -d ${YHUB_DB} -1 -f $YHUB_BACKUP_FILE
|
|
fi
|
|
|
|
trap - EXIT INT TERM
|
|
restore_config
|
|
}
|
|
|
|
$@
|