-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrestore_database.sh
executable file
·63 lines (52 loc) · 1.17 KB
/
restore_database.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
FILENAME=""
PWD="mismpass"
USER="mism"
VERBOSE=""
CONTAINER="pgadmin"
TARGET="awx"
DB="mism"
usage()
{
echo "Usage: $0 [-v(verbose)] [-u user] -t target (awx*/zabbix) -f dump_file"
echo "the dump_file must be under [INSTALL_DIR]/storage/pgadmin_bullsequana.com/ directory"
exit 2
}
while getopts "vu:t:f:" option; do
case "${option}" in
v)
VERBOSE="--verbose"
;;
f)
FILENAME=${OPTARG}
;;
u)
USER=${OPTARG}
;;
t)
TARGET=${OPTARG}
;;
*)
usage
;;
esac
done
if [ -z ${FILENAME} ]
then
usage
fi
if [ ${TARGET} = "awx" ]
then
HOST="awx_postgres"
DB="mism"
fi
if [ ${TARGET} = "zabbix" ]
then
HOST="zabbix-postgres"
DB="zabbix"
fi
docker exec -e PGPASSWORD=${PWD} ${CONTAINER} /usr/local/pgsql-12/pg_restore --host ${HOST} --port "5432" --username=${USER} --dbname $DB -c ${VERBOSE} "/var/lib/pgadmin/storage/pgadmin_bullsequana.com/${FILENAME}"
if [ $? -ne 0 ]; then
echo -e "\e[101m>> The database restore failed !!! \e[0m"
exit -1
fi
echo -e "\e[42m>> The database is restored ! \e[0m"