-
Notifications
You must be signed in to change notification settings - Fork 44
/
hbase_flush_tables.sh
executable file
·68 lines (48 loc) · 1.59 KB
/
hbase_flush_tables.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
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2016-09-13 09:17:01 +0200 (Tue, 13 Sep 2016)
#
# https://github.com/HariSekhon/DevOps-Perl-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
DESCRIPTION="Script to flush HBase tables
Takes an optional regex selection, otherwise flushes all HBase tables
Uses HBase Shell which must be in the \$PATH
Written to flush OpenTSDB tables before shutdown as the bulk import tool is using Durability.SKIP_WAL
Tested on Hortonworks HDP 2.3 (HBase 1.1.2) and Apache HBase 1.0.3, 1.1.6, 1.2.1, 1.2.2
See https://github.com/HariSekhon/DevOps-Python-tools for a better Python version which uses the Thrift API
"
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
die(){
echo "$@"
exit 1
}
usage(){
die "${DESCRIPTION}usage: $0 [table_regex]
"
}
for x in "$@"; do
case "$x" in
-*) usage
;;
esac
done
regex="${1:-.*}"
output="$(hbase shell <<< 'list')"
tables="$(sed -n '/TABLE/,/row.*[[:space:]]in[[:space:]].*[[:space:]]seconds/p' <<< "$output" | sed '/^TABLE$/d ; $d')"
[ -z "$tables" ] && die "No Tables Found"
tables_to_flush="$(grep -E "$regex" <<< "$tables")"
[ -z "$tables_to_flush" ] && die "No Tables Found Matching the given regex '$regex'"
echo "Flushing the following tables:
$tables_to_flush
"
sed "s/^[[:space:]]*/flush '/; s/[[:space:]]*$/'/" <<< "$tables_to_flush" |
hbase shell