forked from skeyby/mysqlfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·111 lines (92 loc) · 3.09 KB
/
update.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
##
## MySQLfs - database upgrade script
##
## rely on a "DATABASE_VERSION" table inside the database
## requires mysql client to be in the path...
##
## if it can't find the table it asks you if you want to create it
##
##
DBUpdateScripts="sql/updates"
echo
echo Welcome to MySQLfs database upgrade script - relase 0.4.2beta
echo
echo It's recommend to shutdown MySQLfs's instance before upgrading the DB.
echo Upgrading the DB with a working instance could corrupt your data.
echo
echo
echo In order to upgrade your DB we need some informations.
echo
echo "Please insert your DB host (usually localhost):"
read DBHost
echo "Please insert your MySQLfs DB name (usually mysqlfs):"
read DBName
echo Please insert your MySQLfs username:
read DBUser
echo Please insert your MySQLfs password:
read DBPass
echo
echo Please confirm the following settings:
echo mysql://$DBUser:$DBPass@$DBHost/$DBName
echo
echo "Correct? (y/n)"
read Correct
if [ "$Correct" != "y" ]; then
echo OK, exiting.
exit 1
fi
echo
echo Checking for DATABASE_VERSION table
TableExists=`echo "SHOW TABLES LIKE 'DATABASE_VERSION';" | mysql -N -h $DBHost -u $DBUser --password=$DBPass $DBName`
if [ "$TableExists" != "DATABASE_VERSION" ]; then
echo "DATABASE_VERSION doesn't seem to exist in your database."
echo If this is your first database upgrade ever this may be normal.
echo PLEASE BE AWARE THAT THIS SCRIPT REQUIRE YOUR CURRENT MYSQLFS
echo RELEASE TO BE AT LEAST 0.4.1!!!!!!
echo
echo Continue creating DATABASE_VERSION?
read Correct
if [ "$Correct" != "y" ]; then
echo OK, exiting.
exit 1
fi
echo Executing $DBUpdateScripts/00000000.sql
mysql -N -h $DBHost -u $DBUser --password=$DBPass $DBName < $DBUpdateScripts/00000000.sql > /tmp/dbupdate_stdout.log 2> /tmp/dbupdate_stderr.log
echo
fi
echo
echo Checking current DATABASE_VERSION:
CurrentDB=`echo "SELECT MAX(CURRENT_VERSION) FROM DATABASE_VERSION;" | mysql -N -h $DBHost -u $DBUser --password=$DBPass $DBName`
if [ "$CurrentDB" = "NULL" ]; then
CurrentDB=0
fi
echo Current DB Version $CurrentDB
echo
NextDB=`expr $CurrentDB + 1`
NextFile=`echo 0000000$NextDB | rev | cut -c 1-8 | rev`
echo "Checking for a possibile DB upgrade (starting from #$NextDB)"
while [ -f $DBUpdateScripts/$NextFile.sql ]; do
echo "Executing $DBUpdateScripts/$NextFile.sql"
mysql -N -h $DBHost -u $DBUser --password=$DBPass $DBName < $DBUpdateScripts/$NextFile.sql > /tmp/dbupdate_stdout.log 2> /tmp/dbupdate_stderr.log
ErrorLevel=$?
if [ $ErrorLevel -ne 0 ]; then
echo "Error applying update $NextDB"
cat /tmp/dbupdate_stdout.log
rm /tmp/dbupdate_stdout.log
cat /tmp/dbupdate_stderr.log
rm /tmp/dbupdate_stderr.log
exit 1
else
echo "INSERT INTO DATABASE_VERSION SET CURRENT_VERSION = $NextDB, LAST_CHANGE=NOW();" | mysql -N -h $DBHost -u $DBUser --password=$DBPass $DBName
echo "Upgrading DATABASE_VERSION to $NextDB"
fi
rm /tmp/dbupdate_std*.log
NextDB=`expr $NextDB + 1`
NextFile=`echo 0000000$NextDB | rev | cut -c 1-8 | rev`
done
echo
echo Everything done.
echo
echo Now you can upgrade your MySQLfs binaries and restart your filesystem
echo