-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathyb-voyager-docker
executable file
·164 lines (144 loc) · 4.32 KB
/
yb-voyager-docker
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# set -x
argv=( "$@" )
if ! which docker > /dev/null
then
echo "Could not find docker! Please install docker before proceeeding."
exit 1
fi
if [[ $OSTYPE == 'darwin'* ]]
then
platform="--platform=linux/amd64"
fi
i=0
exported_vars=""
volume_mappings=""
# Define an array of environment variable names to capture
variables=("BETA_FAST_DATA_EXPORT"
"SOURCE_DB_PASSWORD"
"TARGET_DB_PASSWORD"
"SOURCE_REPLICA_DB_PASSWORD"
"YB_VOYAGER_SEND_DIAGNOSTICS"
"YB_MASTER_PORT"
"YB_TSERVER_PORT"
"QUEUE_SEGMENT_MAX_BYTES"
"NUM_EVENT_CHANNELS"
"EVENT_CHANNEL_SIZE"
"MAX_EVENTS_PER_BATCH"
"MAX_INTERVAL_BETWEEN_BATCHES"
"CONTROL_PLANE_TYPE"
"YUGABYTED_DB_CONN_STRING")
volume_dirs=("--export-dir"
"--backup-dir"
"--move-to"
"--source-ssl-cert"
"--source-ssl-key"
"--source-ssl-root-cert"
"--table-list-file-path"
"--exclude-table-list-file-path"
"--assessment-metadata-dir"
"--assessment-report-path")
# Loop through the array and capture the environment variables
for var_name in "${variables[@]}"; do
var=$(env | grep -E "$var_name")
if [[ -n "$var" ]]; then
exported_vars="${exported_vars} -e $var"
fi
done
exported_vars="${exported_vars} -e ORACLE_HOME=/usr/lib/oracle/21/client64 -e LD_LIBRARY_PATH=/usr/lib/oracle/21/client64/lib -e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/usr/lib/oracle/21/client64/bin"
map_host_path_inside_container() {
flag_name=$1
dir_path=$2
# If flag_name is "" then we have to extract it from argv
if [[ $flag_name == "" ]]
then
flag_name=${argv[${i}]}
j=$(( $i + 1))
argv[${j}]=$(realpath "${argv[${j}]}")
dir_path=${argv[${j}]}
fi
volume_name="voyager-${flag_name}"
# handle file paths. If the path is a file, then the target path should be the directory of the file.
if [[ -f $dir_path ]]
then
dir_path=$(dirname "$dir_path")
fi
# If the OS is macOS
if [[ $OSTYPE == 'darwin'* ]]
then
docker volume rm $volume_name > /dev/null 2>&1
docker volume create --driver local --opt type=none --opt device="${dir_path}" --opt o=bind $volume_name > /dev/null 2>&1
volume_mappings="${volume_mappings} -v ${volume_name}:${dir_path}"
else
volume_mappings="${volume_mappings} -v ${dir_path}:${dir_path}"
fi
}
while [ $i -lt $# ]
do
v=${argv[${i}]}
if [[ ${v} == "-e" ]]
then
v="--export-dir"
fi
# if v is present in volume_dirs array
if [[ " ${volume_dirs[@]} " =~ " ${v} " ]]
then
map_host_path_inside_container
i=$(( $i + 1))
continue
fi
if [[ ${argv[${i}]} == "--data-dir" ]]
then
j=$(( $i + 1))
data_dir=${argv[${j}]}
# If the data-dir is an S3 bucket
if [[ $data_dir == 's3://'* ]]
then
# Capture exported variables for aws
for var in $(env | grep -E '^AWS_')
do
exported_vars="${exported_vars} -e $var"
done
s3_vol="-v ${HOME}/.aws:/root/.aws"
elif [[ $data_dir == 'gs://'* ]]
then
# map gcp credentials directory
gcp_vol="-v ${HOME}/.config/gcloud:/root/.config/gcloud"
elif [[ $data_dir == 'https://'* ]]
then
# map azure credentials directory
azure_vol="-v ${HOME}/.azure:/root/.azure"
for var in $(env | grep -E '^AZURE_')
do
exported_vars="${exported_vars} -e $var"
done
else
# If the data-dir is not an S3 bucket
data_dir=$(realpath "$data_dir")
map_host_path_inside_container "data-dir" "${data_dir}"
fi
fi
# If the flag is --oracle-tns-alias then find the exported variable TNS_ADMIN and map it to the container. --oracle-tns-alias flag will be passed as it is.
if [[ ${argv[${i}]} == "--oracle-tns-alias" ]]
then
if [ -n "$TNS_ADMIN" ]; then
tns_admin="$TNS_ADMIN"
else
tns_admin="${ORACLE_HOME}/network/admin"
fi
wallet_dir=$(sed -n 's|(DIRECTORY\s*=\s*"\([^"]*\)")|\1|p' ${tns_admin}/sqlnet.ora | xargs)
tns_admin=$(realpath "$tns_admin")
wallet_dir=$(realpath "$wallet_dir")
map_host_path_inside_container "oracle-tns-alias" "${tns_admin}"
map_host_path_inside_container "oracle-wallet-dir" "${wallet_dir}"
exported_vars="${exported_vars} -e TNS_ADMIN=${tns_admin}"
fi
i=$(( $i + 1))
done
if [ -t 1 ]
then
tty="-it"
fi
dockerCmd="docker run ${exported_vars} ${tty} ${gcp_vol} ${s3_vol} ${azure_vol} ${volume_mappings} --pid=host --network=host --rm --privileged ${platform} yugabytedb/yb-voyager yb-voyager ${argv[*]}"
# echo $dockerCmd
$dockerCmd