Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a script to do metad folder scp #2532

Merged
merged 4 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ install(
COMPONENT
graph
)

install(
FILES
meta-transfer-tools.sh
PERMISSIONS
OWNER_EXECUTE OWNER_WRITE OWNER_READ
GROUP_EXECUTE GROUP_READ
WORLD_EXECUTE WORLD_READ
DESTINATION
scripts
COMPONENT
meta
)
86 changes: 86 additions & 0 deletions scripts/meta-transfer-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#! /bin/bash

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 seperated 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
liuyu85cn marked this conversation as resolved.
Show resolved Hide resolved
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*