forked from fabioboris/postgresql-backup-restore-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgsql_restore.sh
executable file
·47 lines (39 loc) · 890 Bytes
/
pgsql_restore.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
#!/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 new database name
if [ -z $2 ]; then
echo "Enter the new 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
echo "drop database $DBNAME;" | psql --username=$USERNAME template1
echo "create database $DBNAME with encoding 'utf8';" | psql --username=$USERNAME template1
psql --username=$USERNAME $DBNAME < $SCHEMA
psql --username=$USERNAME $DBNAME < $DATA