-
Notifications
You must be signed in to change notification settings - Fork 1
/
brr-flip
executable file
·78 lines (64 loc) · 1.45 KB
/
brr-flip
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
#!/usr/bin/env bash
#
# Synopsis:
# Flip an active blob request log file for a particular schema.
# Usage:
# brr-flip <schema>
# brr-flip setcore
# See:
# flip-tail.c
# Exit Status:
# 0 all active brr files have been flipped
# 1 unknown error
# See:
# flip-tail.c
#
PROG=$(basename $0)
SCHEMA=
log()
{
MSG=$@
test -n "$SCHEMA" && MSG="$SCHEMA: $MSG"
echo "$(date +'%Y/%m/%d %H:%M:%S'): $PROG: $MSG"
}
WARN()
{
log "WARN: $@" >&2
}
die()
{
log "ERROR: $@" >&2
exit 2
}
leave()
{
log 'good bye, cruel world'
}
test $# = 1 || die 'wrong number of arguments'
SCHEMA=$1
log 'hello, world'
trap leave EXIT
test -n "$SETSPACE_ROOT" ||
die "environment variable not defined: SETSPACE_ROOT"
log "SETSPACE_ROOT=$SETSPACE_ROOT"
cd $SETSPACE_ROOT || die "cd $SETSPACE_ROOT failed"
. etc/profile
SCHEMA_ROOT=$SETSPACE_ROOT/schema/$SCHEMA
test -d $SCHEMA_ROOT || die "schema dir does not exist: $SCHEMA_ROOT"
SPOOL=$SCHEMA_ROOT/spool
if [ ! -e $SPOOL ]; then
WARN "no spool directory: $SPOOL"
WARN 'doing nothing'
exit 0
fi
cd $SPOOL || die "cd $SPOOL failed: exit status=$?"
log 'finding active blob request log files ...'
find . -maxdepth 1 -name '*.brr' -type f |
grep -v '[-][0-9][0-9]*.*[.]brr$' |
while read BRR; do
NEW_BRR=$(basename $BRR .brr)-$(date +%s).brr
log "flip $BRR -> $NEW_BRR"
flip-tail file $BRR $NEW_BRR ||
die "flip-tail file $BRR $NEW_BRR failed: exit status=$?"
log "$NEW_BRR: $(wc -l $NEW_BRR | awk '{print $1}') records"
done