Skip to content

Commit

Permalink
Cleaning up new cluster if migration fail
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Oct 22, 2021
1 parent 87fb8dd commit 770aff0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Postgres/13.4/migrate-docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ if [[ "$CURRENT_PGVERSION" != "$EXPECTED_PGVERSION" ]] && \
-not -wholename "$PGDATAOLD" \
-not -wholename "$PGDATANEW" \
-exec mv {} "$PGDATAOLD/" \;

chmod 700 "$PGDATAOLD" "$PGDATANEW"
chown postgres .
chown -R postgres "$PGDATAOLD" "$PGDATANEW" "$PGDATABASE"
cp "$PGDATAOLD/PG_VERSION" "$PGDATABASE/PG_MIGRATING_FROM_VERSION"
else
echo "Previous migration failed, trying one more time..."
fi

chmod 700 "$PGDATAOLD" "$PGDATANEW"
chown postgres .
chown -R postgres "$PGDATAOLD" "$PGDATANEW" "$PGDATABASE"

[[ "$POSTGRES_USER" ]] && export PGUSER="$POSTGRES_USER"
[[ "$POSTGRES_PASSWORD" ]] && export PGPASSWORD="$POSTGRES_PASSWORD"
if [ ! -s "$PGDATANEW/PG_VERSION" ]; then
Expand All @@ -77,8 +77,12 @@ if [[ "$CURRENT_PGVERSION" != "$EXPECTED_PGVERSION" ]] && \
fi

if ! gosu postgres pg_upgrade; then
echo "Failed to upgrade the server"
echo "Failed to upgrade the server, showing pg_upgrade_server.log"
cat pg_upgrade_server.log
if [ -f "$PGDATAOLD/PG_VERSION" ] && [ -f "$PGDATANEW/PG_VERSION" ]; then
echo "Cleaning up the new cluster"
rm -r $PGDATANEW/*
fi
exit 1
fi

Expand Down

0 comments on commit 770aff0

Please sign in to comment.