forked from fabioboris/postgresql-backup-restore-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgsql_backup.sh
executable file
·52 lines (44 loc) · 902 Bytes
/
pgsql_backup.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
#!/bin/sh
# Description: Restore a PostgreSQL database from schema and data dump files
#
# Author: Fabio Agostinho Boris
# github.com/fabioboris
#
# Creation: 2013-05-08
# get username
if [ -z $1 ]; then
echo "Enter the username:"
read USERNAME
else
USERNAME=$1
fi
# get database name
if [ -z $2 ]; then
echo "Enter the database name:"
read DBNAME
else
DBNAME=$2
fi
# get schema file name
if [ -z $3 ]; then
echo "Enter the schema file name:"
read SCHEMA
else
SCHEMA=$3
fi
# get data file name
if [ -z $4 ]; then
echo "Enter the data file name:"
read DATA
else
DATA=$4
fi
# extra params on data file
if [ -z $5 ]; then
echo "Extra params on data file:"
read EXTRA
else
EXTRA=$5
fi
pg_dump --username=$USERNAME --schema-only $DBNAME > $SCHEMA
pg_dump --username=$USERNAME --data-only --disable-triggers $EXTRA $DBNAME > $DATA