-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemon.sh
executable file
·48 lines (39 loc) · 1.94 KB
/
daemon.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
#!/bin/sh
/usr/bin/rsync --no-detach --daemon --config /etc/rsyncd.conf &
inotifywait -mr -e close_write --fromfile /app/wait-list.txt | while read DEST EVENT FILE
do
SERVICE=`echo $DEST | cut -d"/" -f3`
UUID=`echo $(basename "$DEST")`
case "$SERVICE" in
"zip")
UUID=`echo $(basename "$DEST")`
mkdir -p /data/parse/$UUID
unzip -o $DEST$FILE -d /data/parse/$UUID
;;
"parse")
mkdir -p /tmp/$UUID
mkdir -p /tmp/$UUID/sec
mkdir -p /tmp/$UUID/thi
if [ -d "/data/parse/$UUID/import_files" ]; then
mv /data/parse/$UUID/import_files /tmp/$UUID/
fi
myhost=$(echo $DB_HOST | cut -d ':' -f1)
myport=$(echo $DB_HOST | cut -d ':' -f2)
name=$(echo $UUID | sed -e "s/-/_/g")
mysql --host=$myhost --port=$myport -e "CREATE DATABASE IF NOT EXISTS $name CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql --host=$myhost --port=$myport --database=$name -e "source /app/schema.sql;"
xml2db -db $name -file /data/parse/$UUID/$FILE
db2file -db $name -path /tmp/$UUID -limit 500000 -pfile "out" -ptable "wp_"
COMPLETE=$?
if [ $COMPLETE -eq 0 ];then
QTY=`find /tmp/$UUID -name '*.sql' | wc -l`
find /tmp/$UUID/sec -name '*.sql' | while read FILE; do mv "$FILE" "$(echo "$FILE" | sed 's/sec\/out/secout/g')"; done
find /tmp/$UUID/thi -name '*.sql' | while read FILE; do mv "$FILE" "$(echo "$FILE" | sed 's/thi\/out/thiout/g')"; done
find /tmp/$UUID -name '*.sql' | while read FILE; do mv "$FILE" $(echo "$FILE" | sed "s/\.sql$/_$QTY.sql/g"); done
mysql --host=$myhost --port=$myport -e "DROP DATABASE IF EXISTS $name;"
rsync --inplace -av /tmp/$UUID rsync://storage:873/storage
fi
rm -rf /tmp/$UUID
;;
esac
done