-
Notifications
You must be signed in to change notification settings - Fork 4
/
zdb-hook.sh
executable file
·88 lines (72 loc) · 2.13 KB
/
zdb-hook.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
#!/bin/sh
set -ex
prefix="${ZDBFS_PREFIX:-/}"
action="$1"
instance="$2"
zstorconf="${prefix}/etc/zstor-default.toml"
zstorbin="${prefix}/bin/zstor"
zstorindex="${prefix}/data/index"
zstordata="${prefix}/data/data"
if [ "$action" = "close" ]; then
for namespace in `ls $zstordata`; do
if [ "${namespace}" = "zdbfs-temp" ]; then
continue
fi
indexdir="$zstorindex/$namespace"
datadir="$zstordata/$namespace"
lastactive="`ls $indexdir | grep -v zdb-namespace | cut -d'i' -f2 | sort -n | tail -n 1`"
datafile="$datadir/d$lastactive"
indexfile="$indexdir/i$lastactive"
${zstorbin} -c ${zstorconf} store -s --file "$datafile"
${zstorbin} -c ${zstorconf} store -s --file "$indexfile"
done
exit 0
fi
if [ "$action" = "ready" ]; then
${zstorbin} -c ${zstorconf} test
exit $?
fi
if [ "$action" = "namespace-created" ] || [ "$action" = "namespace-updated" ]; then
if [ "$3" = "zdbfs-temp" ]; then
# skipping temporary namespace
exit 0
fi
file="$zstorindex/$3/zdb-namespace"
# backup zdb-namespace file
${zstorbin} -c ${zstorconf} store -s --file "$file"
exit 0
fi
if [ "$action" = "jump-index" ]; then
namespace=$(basename $(dirname $3))
if [ "${namespace}" = "zdbfs-temp" ]; then
# skipping temporary namespace
exit 0
fi
tmpdir=$(mktemp -p /tmp -d zdb.hook.tmp.XXXXXXXX)
dirbase=$(dirname $3)
# upload dirty index files
for dirty in $5; do
file=$(printf "i%d" $dirty)
cp ${dirbase}/${file} ${tmpdir}/
done
cp "$3" ${tmpdir}/
nice ${zstorbin} -c ${zstorconf} store -s -d -f ${tmpdir} -k ${dirbase} &
exit 0
fi
if [ "$action" = "jump-data" ]; then
namespace=$(basename $(dirname $3))
if [ "${namespace}" = "zdbfs-temp" ]; then
# skipping temporary namespace
exit 0
fi
# backup data file
nice ${zstorbin} -c ${zstorconf} store -s --file "$3"
exit 0
fi
if [ "$action" = "missing-data" ]; then
# restore missing data file
${zstorbin} -c ${zstorconf} retrieve --file "$3"
exit $?
fi
# unknown action
exit 1