forked from acceldata-io/kudu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkudu-backup
More file actions
89 lines (76 loc) · 2.93 KB
/
kudu-backup
File metadata and controls
89 lines (76 loc) · 2.93 KB
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
#!/bin/sh
#Licensed to the Apache Software Foundation (ASF) under one
#or more contributor license agreements. See the NOTICE file
#distributed with this work for additional information
#regarding copyright ownership. The ASF licenses this file
#to you under the Apache License, Version 2.0 (the
#"License"); you may not use this file except in compliance
#with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing,
#software distributed under the License is distributed on an
#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#KIND, either express or implied. See the License for the
#specific language governing permissions and limitations
#under the License.
OP=$(echo "$1" | tr '[:upper:]' '[:lower:]')
shift
if ! command -v spark-submit >/dev/null; then
printf "'spark-submit' not found\n" >&2
printf "Spark 3 is required to backup or restore Kudu tables\n" >&2
exit 1
fi
if ! command -v kudu >/dev/null; then
printf "'kudu' not available in PATH\n" >&2
printf "Run this script on a machine with kudu installed\n" >&2
exit 1
fi
if [ "$USER" != "kudu" ]; then
printf "Backing up tables must be done as the kudu user\n." >&2
printf "Your user is: '%s'\n" "$USER" >&2
exit 1
fi
if [ "$OP" != "backup" ] && [ "$OP" != "restore" ]; then
printf "Invalid option '%s'. Valid options are 'backup' or 'restore'\n" "$OP" >&2
printf "Either 'backup' or 'restore' must be the first argument when calling %s\n" "$0" >&2
exit 1
fi
OVERRIDE_PATH=false
for arg in "$@"; do
if [ "$arg" = "--rootPath" ]; then
OVERRIDE_PATH=true
break
fi
done
if ! "$OVERRIDE_PATH"; then
BACKUP_PATH="--rootPath hdfs:///kudu_backups"
fi
JARS=$(find /usr/odp/"$(odp-select --version)"/kudu/ -name "kudu-backup*.jar" | grep -E "^/usr/odp/$(odp-select --version)/kudu/jars/kudu-backup[[:digit:]]+_[[:digit:]]+\.[[:digit:]]+-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(-all)?.jar$")
NUM_JARS=$( printf "%s" "$JARS" | wc -w)
if [ "$NUM_JARS" -eq 0 ]; then
printf "No jars found\n" >&2
exit 1
elif [ "$NUM_JARS" -eq 1 ]; then
JAR=$JARS
elif [ "$NUM_JARS" -gt 1 ]; then
for jar in $JARS; do
JAR="$jar"
if printf "%s" "$jar" | grep -F "\-all.jar"; then
break
fi
done
fi
if [ -f /etc/kudu/conf/master.conf ]; then
MASTERS=$(awk -F= '$1 ~ "--master_addresses" {print $2}' /etc/kudu/conf/master.conf)
else
printf "/etc/kudu/conf/master.conf not found. Is Kudu installed?\n" >&2
exit 1
fi
#BACKUP_PATH has been left unquoted so that if it's empty, it will not be passed
if [ "$OP" = "backup" ]; then
spark-submit --class org.apache.kudu.backup.KuduBackup "$JAR" --kuduMasterAddresses "$MASTERS" $BACKUP_PATH "$@"
elif [ "$OP" = "restore" ]; then
spark-submit --class org.apache.kudu.backup.KuduRestore "$JAR" --kuduMasterAddresses "$MASTERS" $BACKUP_PATH "$@"
fi