Skip to content

Commit

Permalink
Improve upgrade script
Browse files Browse the repository at this point in the history
Pull containers up front
Take backup snapshot
  • Loading branch information
schnapster committed Sep 27, 2023
1 parent fcf5251 commit 8986d2b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions upgrade-old-new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,43 @@ NEW=$4

cd "$APP_PATH"

# 1. stop db container
# Pull necessary containers
echo "Pulling containers for later steps"
docker pull tianon/postgres-upgrade:"$OLD"-to-"$NEW"
docker pull napstr/poggres:"$NEW"

# Stop db container
echo "Stopping DB container $CONTAINER_NAME"
docker stop "$CONTAINER_NAME"

# 2. Create new directory
DATA_PATH="$APP_PATH/postgres-data/$NEW/data"
echo "Creating $DATA_PATH"
mkdir -p "$DATA_PATH"
# Make backup of the directory
DATA_PATH="$APP_PATH/postgres-data/"
echo "Creating a backup"
tar --use-compress-program="pigz --best --recursive" -cvf postgres-data.tar.gz "$DATA_PATH"

# Create new directory
NEW_DATA_PATH="$APP_PATH/postgres-data/$NEW/data"
echo "Creating $NEW_DATA_PATH"
mkdir -p "$NEW_DATA_PATH"

# 3. run upgrade container
# Run upgrade container
echo "Running upgrade container"
docker run --rm \
-v "$APP_PATH"/postgres-data:/var/lib/postgresql \
tianon/postgres-upgrade:"$OLD"-to-"$NEW" \
--link

# 4. pull and run latest database container
# Run latest database container
UPDATE_SCRIPT="$APP_PATH/docker-update.sh"
echo "Updating containers $UPDATE_SCRIPT"
sh "$UPDATE_SCRIPT"

# 5. Fix pg_hba
# Fix pg_hba
echo "Fixing pg_hba"
echo "host all all all md5" >> "$APP_PATH"/postgres-data/"$NEW"/data/pg_hba.conf
docker restart "$CONTAINER_NAME"

# 6. generate optimizer statistics
# Generate optimizer statistics
echo "Waiting a bit"
sleep 10
echo "Generating optimizer statistics"
Expand Down

0 comments on commit 8986d2b

Please sign in to comment.