forked from GeorgesAlkhouri/virtuoso-import-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit_dump.sh
142 lines (112 loc) · 3.21 KB
/
git_dump.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
set -o nounset
${DLD_DEV:=}
[[ ! -z "$DLD_DEV" ]] && set -x #conditional debug output
dt=$(date '+%d/%m/%Y %H:%M:%S')
# http://docs.openlinksw.com/virtuoso/rdfperfdumpandreloadgraphs/
# Definition of the isql connection to Virtuoso
bin="isql-vt"
host="virtuoso"
port=1111
user="dba"
password=${DBA_PASSWORD}
export_dir="${VIRTUOSO_DATA_DIR}"
# Wrap the execution of isql commands to receive the return code and output
run_virtuoso_cmd () {
VIRT_OUTPUT=`echo "$1" | "$bin" -H "$host" -S "$port" -U "$user" -P "$password" 2>&1`
VIRT_RETCODE=$?
if [[ $VIRT_RETCODE -eq 0 ]]; then
echo "$VIRT_OUTPUT" | tail -n+5 | perl -pe 's|^SQL> ||g'
return 0
else
echo -e "[ERROR] running the these commands in virtuoso:\n$1\nerror code: $VIRT_RETCODE\noutput:"
echo "$VIRT_OUTPUT"
let 'ret = VIRT_RETCODE + 128'
return $ret
fi
}
# Check if the virtuoso is up and running
# This is needed during the bootstrapping process in a docker setup
test_connection () {
if [[ -z $1 ]]; then
echo "[ERROR] missing argument: retry attempts"
exit 1
fi
t=$1
run_virtuoso_cmd 'status();'
while [[ $? -ne 0 ]] ;
do
echo -n "."
sleep 1
echo $t
let "t=$t-1"
if [ $t -eq 0 ]
then
echo "timeout"
return 2
fi
run_virtuoso_cmd 'status();'
done
}
cd "$export_dir"
echo "[INFO] waiting for store to come online"
: ${CONNECTION_ATTEMPTS:=60}
test_connection "${CONNECTION_ATTEMPTS}"
if [ $? -eq 2 ]; then
echo "[ERROR] store not reachable"
exit 1
fi
# Give some more seconds to the virtuoso to really accept updates
sleep 3
echo "[INFO] $dt Starting dump process...";
# clean working dir
rm -rf $export_dir/*
mkdir $export_dir/tmp
# First define the procedure
command=`cat ../dump_one_graph.virtuoso>&1`
run_virtuoso_cmd "$command"
# Now use it to dump
run_virtuoso_cmd "dump_one_graph('${GRAPH_URI}', '${export_dir}/data_', 1000000000);"
echo "[INFO] dump done;"
# Sorting of triples
for file in *.ttl*; do
cat $file | LC_ALL=C sort -u > $export_dir/tmp/$file
done
# Create dir if not existing
if [ -d "$GIT_DIRECTORY" ]; then
:
else
### Control will jump here if $DIR does NOT exists ###
mkdir -p $GIT_DIRECTORY
fi
# Setup of git
cd $GIT_DIRECTORY
git config --global user.email "$GIT_EMAIL"
git config --global user.name "$GIT_NAME"
chmod 600 /root/.ssh/id_rsa
# Check if valid repository - if not clone
lines=`git status | wc -l`
lines=$(($lines + 1))
if [ $lines -lt 3 ]; then
echo "[INFO] Repository is not a git directory. Clone now"
rm -rf $GIT_DIRECTORY/*
rm -rf $GIT_DIRECTORY/.git
git clone $GIT_REPO $GIT_DIRECTORY
else
echo "[INFO] Repository update ..."
git pull
fi
echo "[INFO] git repo now up to date. Copy now files and create a commit."
cp $export_dir/tmp/* $GIT_DIRECTORY/
rm -rf $export_dir/tmp
# Check if files changed
lines=`git status | grep .ttl | wc -l`
lines=$(($lines + 1))
if [ $lines -lt 2 ]; then
echo "[INFO] Repository needs no update. Abort."
exit
fi
git add .
git commit -am "Automatic commit message from virtuoso-import-docker: Update of repository at $dt"
git push
echo "[INFO] Exit."