Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[5a71fa]: dist / restore / restore-mysql.sh Maximize Restore History

Download this file

restore-mysql.sh    81 lines (70 with data), 1.4 kB

 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
#!/bin/bash
# bbou@ac-toulouse;fr
# 25/11/2013
db=$1
dbtype=mysql
if [ -z "${db}" ]; then
read -s -p "enter ${dbtype} database name: " db
echo
export db
fi
dbuser=root
dbdelete=
if [ "$2" == "-d" ]; then
dbdelete=true
fi
modules="wn legacy vn bnc sumo xwn glf ilfwn logs"
function process()
{
if [ ! -e "$1" ];then
return
fi
echo "$2"
mysql -u ${dbuser} --password=${password} $4 $3 < $1
}
function dbexists()
{
mysql -u ${dbuser} --password=${password} -e "\q" ${db} > /dev/null 2> /dev/null
return $?
}
function deletedb()
{
echo "delete ${db}"
mysql -u ${dbuser} --password=${password} -e "DROP DATABASE ${db};"
}
function createdb()
{
echo "create ${db}"
mysql -u ${dbuser} --password=${password} -e "CREATE DATABASE ${db} DEFAULT CHARACTER SET UTF8;"
}
function getpassword()
{
read -s -p "enter ${dbuser}'s password: " password
echo
}
echo "restoring ${db}"
getpassword
#database
if [ ! -z ${dbdelete} ]; then
deletedb
fi
if ! dbexists; then
createdb
fi
# module tables
for m in ${modules}; do
sql=${dbtype}-${m}-schema.sql
process ${sql} schema ${db}
done
for m in ${modules}; do
sql=${dbtype}-${m}-data.sql
process ${sql} data ${db}
done
for m in ${modules}; do
sql=${dbtype}-${m}-constraints.sql
process ${sql} constraints ${db} --force
done
for m in ${modules}; do
sql=${dbtype}-${m}-views.sql
process ${sql} views ${db}
done