forked from metabrainz/musicbrainz-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade-to-postgres12
executable file
·79 lines (61 loc) · 2.36 KB
/
upgrade-to-postgres12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -e -o pipefail -u
# shellcheck source=admin/lib/common.inc.bash
source "$(dirname "${BASH_SOURCE[0]}")/lib/common.inc.bash"
HELP=$(cat <<EOH
Usage: $SCRIPT_NAME [--help]
Upgrade database from Postgres 9.5 to Postgres 12.
EOH
)
if [[ $# -ne 0 && $1 =~ -*h(elp)? ]]
then
echo "$HELP"
exit 0 # EX_OK
elif [[ $# -ne 0 ]]
then
echo >&2 "$SCRIPT_NAME: unrecognized argument: $1"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 64 # EX_USAGE
fi
$DOCKER_COMPOSE_CMD down
$DOCKER_COMPOSE_CMD \
-f docker-compose.yml \
-f admin/lib/upgrade-to-postgres12/pg-9.5-stopped.yml \
up -d
$DOCKER_COMPOSE_CMD stop indexer search mq redis
$DOCKER_COMPOSE_CMD exec db apt-get update
$DOCKER_COMPOSE_CMD exec db apt-get install \
--no-install-suggests \
--no-install-recommends \
-y \
postgresql-12 \
postgresql-client-12 \
postgresql-server-dev-12 \
sudo
PGDATA=/var/lib/postgresql/data
$DOCKER_COMPOSE_CMD exec db \
sudo -u postgres /usr/lib/postgresql/9.5/bin/pg_ctl start -w -D "$PGDATA"
sleep 5
CURRENT_PG_VERSION=$($DOCKER_COMPOSE_CMD exec db psql -U musicbrainz -d musicbrainz_db -tAq -c 'SHOW server_version_num')
if echo "$CURRENT_PG_VERSION" | grep -v '^905'; then
echo "Error: Current postgres version should be < 90600, not $CURRENT_PG_VERSON"
exit 1
fi
$DOCKER_COMPOSE_CMD exec musicbrainz git fetch --depth=1 --update-shallow origin '+refs/heads/pg12:refs/remotes/origin/pg12'
$DOCKER_COMPOSE_CMD exec musicbrainz git reset --hard origin/pg12
$DOCKER_COMPOSE_CMD exec musicbrainz \
sh -c 'eval "$(perl -Mlocal::lib)"; cd admin; ./psql --system READWRITE < sql/updates/20200518-pg12-before-upgrade.sql 2>&1'
$DOCKER_COMPOSE_CMD stop db
$DOCKER_COMPOSE_CMD \
-f docker-compose.yml \
-f admin/lib/upgrade-to-postgres12/pg-9.5-stopped.yml \
up -d db
$DOCKER_CMD cp admin/lib/upgrade-to-postgres12/do-pg_upgrade.sh musicbrainz-docker_db_1:/tmp/
$DOCKER_COMPOSE_CMD exec db /bin/bash /tmp/do-pg_upgrade.sh
$DOCKER_COMPOSE_CMD exec musicbrainz \
sh -c 'eval "$(perl -Mlocal::lib)"; cd admin; ./psql --system READWRITE < sql/updates/20200518-pg12-after-upgrade.sql 2>&1'
$DOCKER_COMPOSE_CMD exec db sudo -u postgres "$PGDATA"/analyze_new_cluster.sh
$DOCKER_COMPOSE_CMD exec db rm "$PGDATA"/analyze_new_cluster.sh
$DOCKER_COMPOSE_CMD rm --stop --force db
$DOCKER_COMPOSE_CMD up --build -d
echo 'Upgrade complete!'