mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-13 17:40:31 +02:00
Upgrade
This commit is contained in:
@@ -87,47 +87,23 @@ update_postgres() {
|
|||||||
if [ "$OLD_PG_VERSION" != "$PG_MAJOR_VERSION" ]; then
|
if [ "$OLD_PG_VERSION" != "$PG_MAJOR_VERSION" ]; then
|
||||||
bashio::log.warning "PostgreSQL major version changed ($OLD_PG_VERSION → $PG_MAJOR_VERSION). Running upgrade..."
|
bashio::log.warning "PostgreSQL major version changed ($OLD_PG_VERSION → $PG_MAJOR_VERSION). Running upgrade..."
|
||||||
|
|
||||||
OLD_BIN_DIR="/usr/lib/postgresql/$OLD_PG_VERSION/bin"
|
# Set environment variables for the upgrade script
|
||||||
NEW_BIN_DIR="/usr/lib/postgresql/$PG_MAJOR_VERSION/bin"
|
export DATA_DIR="$PGDATA"
|
||||||
|
export BINARIES_DIR="/usr/lib/postgresql/$PG_MAJOR_VERSION/bin"
|
||||||
|
export BACKUP_DIR="/config/backups"
|
||||||
|
export PSQL_VERSION="$PG_MAJOR_VERSION"
|
||||||
|
|
||||||
# Check if the old PostgreSQL binaries exist
|
# Install binaries
|
||||||
if [ ! -d "$OLD_BIN_DIR" ]; then
|
apt-get update &>/dev/null
|
||||||
bashio::log.warning "Old PostgreSQL binaries ($OLD_PG_VERSION) not found! Downloading..."
|
install -y procps rsync postgresql-$PG_MAJOR_VERSION postgresql-$OLD_PG_VERSION &>/dev/null
|
||||||
|
|
||||||
# Determine the package URL (adjust this as needed for your PostgreSQL distribution)
|
# Download and run the upgrade script
|
||||||
PG_DOWNLOAD_URL="https://ftp.postgresql.org/pub/source/v$OLD_PG_VERSION/postgresql-$OLD_PG_VERSION.tar.gz"
|
TMP_SCRIPT=$(mktemp)
|
||||||
|
wget https://raw.githubusercontent.com/linkyard/postgres-upgrade/refs/heads/main/upgrade-postgres.sh -O "$TMP_SCRIPT"
|
||||||
|
chmod +x "$TMP_SCRIPT"
|
||||||
|
"$TMP_SCRIPT"
|
||||||
|
|
||||||
# Create a temporary directory for the download
|
# Store the new PostgreSQL version if successful
|
||||||
TMP_DIR=$(mktemp -d)
|
|
||||||
cd "$TMP_DIR" || exit 1
|
|
||||||
|
|
||||||
# Download and extract PostgreSQL source
|
|
||||||
wget "$PG_DOWNLOAD_URL" -O postgresql.tar.gz
|
|
||||||
tar -xzf postgresql.tar.gz
|
|
||||||
|
|
||||||
# Build only the necessary binaries
|
|
||||||
cd "postgresql-$OLD_PG_VERSION" || exit 1
|
|
||||||
./configure --prefix="$OLD_BIN_DIR"
|
|
||||||
make -j$(nproc)
|
|
||||||
make install
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
cd /config || exit 1
|
|
||||||
rm -rf "$TMP_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run pg_upgrade with the correct paths
|
|
||||||
pg_upgrade --old-datadir="$PGDATA" \
|
|
||||||
--new-datadir="$PGDATA-new" \
|
|
||||||
--old-bindir="$OLD_BIN_DIR" \
|
|
||||||
--new-bindir="$NEW_BIN_DIR"
|
|
||||||
|
|
||||||
# Replace old data directory with upgraded one
|
|
||||||
mv "$PGDATA" "$PGDATA-old"
|
|
||||||
mv "$PGDATA-new" "$PGDATA"
|
|
||||||
rm -rf "$PGDATA-old"
|
|
||||||
|
|
||||||
# Store the new PostgreSQL version
|
|
||||||
echo "$PG_MAJOR_VERSION" > "$PG_VERSION_FILE"
|
echo "$PG_MAJOR_VERSION" > "$PG_VERSION_FILE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user