-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackup_database.sh
executable file
·93 lines (74 loc) · 1.51 KB
/
backup_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
FILENAME=""
PASSWORD="mismpass"
VERBOSE=""
CONTAINER="pgadmin"
BASEDIR=$(dirname $0)
USER="mism"
DB=""
usage()
{
echo "Usage: $0 [-v(verbose)] [-u user] -t target (awx*/zabbix) -f filename"
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 [ -z ${TARGET} ]
then
usage
fi
if [ -z ${USER} ]
then
usage
fi
if [ ${TARGET} != "awx" -a ${TARGET} != "zabbix" ]
then
usage
fi
if [ ${TARGET} = "awx" ]
then
HOST="awx_postgres"
DB="mism"
fi
if [ ${TARGET} = "zabbix" ]
then
HOST="zabbix-postgres"
DB="zabbix"
fi
export DEST_DIR="storage/pgadmin_bullsequana.com"
if [ ! -d $DEST_DIR ]
then
mkdir -p $DEST_DIR
fi
docker exec -e PGPASSWORD=${PASSWORD} ${CONTAINER} /usr/local/pgsql-12/pg_dump -f "/var/lib/pgadmin/storage/pgadmin_bullsequana.com/$FILENAME" --host ${HOST} --port "5432" --username=${USER} ${VERBOSE} --format=c --clean --column-inserts $DB
if [ $? -ne 0 ]
then
echo ">> Database dump failed !!!"
exit -1
fi
if [ ! -f $DEST_DIR/$FILENAME ]
then
echo -e "\e[101m>> Database dump not generated in $DEST_DIR/$FILENAME !!!\e[0m"
exit -1
fi
echo -e "\e[42m>> The Database dump is saved under $BASEDIR/$DEST_DIR/${FILENAME}\e[0m"