-
Notifications
You must be signed in to change notification settings - Fork 3
/
db_upgrade.sh
84 lines (68 loc) · 1.82 KB
/
db_upgrade.sh
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
80
81
82
83
84
source common.sh
DRY=0
export ENV_FILE=./env
echo "${BLUE}PARSE ARGS"
for i in "$@"; do
case $i in
-e=* | --env=*)
export ENV_FILE="${i#*=}"
echo "${CYAN}USE CUSTOM ENV FILE"
shift
;;
-d | --dry-run)
DRY=1
shift
;;
-h | --help)
echo "
Usage:
$0 [options] OldDbVersion NewDbVersion
Flags:
-e, --env=ENV_FILE Set custom env file. If not set ./env is used
-d, --dry Dry-run
-h, --help Show this help
"
exit 0
;;
esac
done
if [[ $1 =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
export OLD_VERSION=${1}
else
echo "${ERROR}$0 [options] OldDbVersion NewDbVersion"
exit 1
fi
if [[ $2 =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
export NEW_VERSION=${2}
else
echo "${ERROR}$0 [options] OldDbVersion NewDbVersion"
exit 1
fi
# --------------------------------------------------------------
# ---------------------------- MAIN ----------------------------
# --------------------------------------------------------------
function db-compose() {
dc -f docker-compose.dbUpgrade.yml "$@"
}
source_env ${ENV_FILE}
bash ./build.sh -d -e=${ENV_FILE}
db-compose up -d
sleep 1
until db-compose exec -T old-db pg_isready ; do
sleep 3
echo "${YELLOW}waiting for old-db..."
done
until db-compose exec -T new-db pg_isready ; do
sleep 3
echo "${YELLOW}waiting for new-db..."
done
if [ $DRY == 1 ]; then
echo "${MAGENTA}Dry dump from $OLD_VERSION"
echo "${MAGENTA}Dry import to $NEW_VERSION"
else
echo "${GREEN}Dump from $OLD_VERSION"
db-compose exec -T old-db pg_dumpall -U postgres > dump.sql
echo "${GREEN}Import to $NEW_VERSION"
db-compose exec -T new-db psql -U postgres < dump.sql
fi
db-compose down