-
Notifications
You must be signed in to change notification settings - Fork 3
/
staging.sh
executable file
·55 lines (48 loc) · 1.5 KB
/
staging.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
#!/bin/sh
set -e
# wait for mysql at least 30 seconds
MYSQL_SLEEP=30
sleep $MYSQL_SLEEP &
sql=/tmp/staging.sql
rm -f $sql
# empty file to start with
touch sql
cd /staging
# Forget about any incomplete staging
rm -rf staging
mkdir -p staging staged
for file in *.sql.gz ; do
db=`echo $file | sed 's/\\.gz$//' | sed 's/\\.sql//'`
staged=staged/$db
staging=staging/$db
if ! [ -f $staged ] ; then
echo "Preparing to stage $db"
echo "CREATE DATABASE IF NOT EXISTS $db;" >> $sql
echo "USE $db;" >> $sql
echo "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;" >> $sql
gunzip --stdout $file | sed s/InnoDB/MyISAM/ >> $sql
# workaround for 1.5 mysql dump
echo 'UPDATE mappingSet SET justification="http://semanticscience.org/resource/SIO_000985" WHERe sourceDataSource="ConceptWiki" AND justification="http://example.com/ConceptWikiProtein";' >> $sql
touch $staging
fi
done
if ! [ -f $sql ] ; then
echo "mySQL already staged"
exit 0
fi
# To avoid password warnings..
echo "[client]" > /tmp/my.conf
echo "host=$MYSQL_PORT_3306_TCP_ADDR" >> /tmp/my.conf
echo "port=$MYSQL_PORT_3306_TCP_PORT" >> /tmp/my.conf
echo "user=root" >> /tmp/my.conf
echo "password=$MYSQL_ENV_MYSQL_ROOT_PASSWORD" >> /tmp/my.conf
# hope that mysql has started
echo "Waiting for mySQL (up to $MYSQL_SLEEP seconds)"
wait
echo "mySQL staging"
ls -alh /tmp/staging.sql
cat $sql | cpipe -vw -b 8192 | mysql --defaults-file=/tmp/my.conf
# Mark as staged
mv staging/* staged/
rm -f $sql
echo "mySQL staging finished"