forked from hydroshare/hydroshare_drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbrestore.sh
executable file
·39 lines (38 loc) · 1.05 KB
/
dbrestore.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
#!/bin/sh
#
# Script to restore the hydroshare database from the sql dump file
DUMPFILE=sites/default/hydroshare.sql
DATABASE=drupal_hydroshare
DBUSER=admin
RESULT=0
PASSWD=water
if [ -r $DUMPFILE ]
then
printf "Dropping current database: %s\n" $DATABASE
mysql -u $DBUSER -p$PASSWD -e "drop database $DATABASE"
if [ $? -ne 0 ]
then
printf "ERROR: an error occurred while dropping the existing database: %s\n" $DATABASE
RESULT=2
else
printf "Recreating database: %s\n" $DATABASE
mysql -u $DBUSER -p$PASSWD -e "create database $DATABASE"
if [ $? -ne 0 ]
then
printf "ERROR: an error occurred while recreating the hydroshare database: %s\n" $DATABASE
RESULT=3
else
printf "Importing sql dump file: %s\n" $DUMPFILE
mysql -u $DBUSER -p$PASSWD $DATABASE < $DUMPFILE
if [ $? -ne 0 ]
then
printf "ERROR: an error occurred while importing the sql dump: %s\n" $DUMPFILE
RESULT=1
fi
fi
fi
else
printf "ERROR: sql dumpfile \"%s\" does not exist or is not readable\n" $DUMPFILE
RESULT=1
fi
exit $RESULT