sh
#! /bin/bash
HS_HOME=/opt/hengshi
PG_HOME=$HS_HOME/lib/pgsql
export PATH=$PATH:$PG_HOME/bin
PG_USR=postgres
PG_PWD=postgres
PG_HOST=127.0.0.1
PG_PORT=54320
# ----------- meta ------------
restore_meta() {
local dbname="$1"
echo PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT $dbname -c "create database $dbname"
PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "create database $dbname"
echo PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT $dbname -f $dbname.backup.sql
PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -f $dbname.backup.sql
}
modify_connection() {
PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5432, \"type\": \"postgresql\", \"config\": {}, \"database\": \"postgres\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=3"
PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5432, \"type\": \"postgresql\", \"config\": {}, \"database\": \"postgres\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=4"
PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5432, \"type\": \"postgresql\", \"config\": {}, \"database\": \"adhoc\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=6 "
PGPASSOWRD=$PG_PWD psql -U$PG_USR -h$PG_HOST -p$PG_PORT postgres -c "update connection set options='{\"host\": \"10.240.1.1\", \"port\": 5434, \"type\": \"postgresql\", \"config\": {}, \"database\": \"postgres\", \"encoding\": \"UTF-8\", \"password\": \"postgres\", \"username\": \"postgres\"}' where id=12 "
}
# -------------- engine -----------------
ENGINE_HOME=$HS_HOME/engine-cluster
restore_engine() {
source $ENGINE_HOME/export-cluster.sh
echo "engine: pg_restore"
psql postgres -f engine.back.sql
}
# ------- run -------------
restore_meta postgres
modify_connection
restore_meta hengshi_sense_internal_storage
restore_engine
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
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