forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta-transfer-tools.sh
executable file
·91 lines (79 loc) · 2.05 KB
/
meta-transfer-tools.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
#! /bin/bash
#
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
#
src=
dst=
metaDirName=
configs=
function usage {
Usage="this tool is a simple wrapper to scp to copy local folder of metad to another (remote)place \n \
it afford 4 options: \n \
1. -f (from) local metad dir \n \
2. -t (to) remote destination \n \
3. -u (update) any configs need to be changed \n \
different configs should be separated by ':' \n \
each config has to be the form of "local_ip=172.0.0.1" \n \
\n \
for example \n \
./meta-transfer-tools.sh -f /path-to-src/metad1 -t bob@172.0.0.1:/path-to-dst -u local_ip=172.0.0.1:port=10086 \n \
"
echo -e $Usage
}
while getopts ":hf:t:u:" opt; do
case $opt in
h)
usage
exit 0
;;
f)
echo "trying to copy metad from: " $OPTARG
src=$OPTARG
metaDirName=${OPTARG##*/}
;;
t)
echo "trying to copy metad to: " $OPTARG
dst=$OPTARG
;;
u)
echo "-u: " $OPTARG
configs=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG"
usage
exit 1
;;
esac
done
if [[ ! -d ${src} ]]; then
echo "${src} does not exist or not a folder"
exit 1
fi
configSurfix=/etc/nebula-metad.conf
if [[ ! -f ${src}${configSurfix} ]]; then
echo "${src}${configSurfix} does not exist"
exit 1
fi
tmpConfigFile=nebula-metad.conf.bak
cp ${src}${configSurfix} ${tmpConfigFile}
if [[ -z $configs ]]; then
echo no configs need to replace
else
echo going to parse configs: $configs
array=(${configs//:/ })
for var in ${array[@]}
do
key=${var%=*}
val=${var#*=}
sed -iE "s/--${key}.*$/--${key}=${val}/" ${tmpConfigFile}
done
fi
echo "trying to copy metad from $src to $dst"
set -x
scp -r $src $dst
scp $tmpConfigFile $dst/$metaDirName$configSurfix
set +x
rm $tmpConfigFile*