-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsnapmirror_create
More file actions
executable file
·237 lines (211 loc) · 9.58 KB
/
snapmirror_create
File metadata and controls
executable file
·237 lines (211 loc) · 9.58 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/bash
#
################################################################################
# This script is used to create a SnapMirror relationship on a
# FSx for ONTAP file systems.
#
# It is dependent on the 'wf_utils' file that is included in this repo. That
# file contains the 'get_token' function that is used to obtain a valid
# access token that is needed to run the Workload Factory APIs. The file needs
# to either be in the command search path or in the current directory.
################################################################################
################################################################################
# This function just prints the usage of this script and exits the program.
################################################################################
usage() {
cat >&2 <<EOF
This script is used to create a SnapMirror relationship on a FSx for ONTAP file systems.
Usage: $(basename $0) -t refresh_token -a blueXP_account_ID [-l throttle] [-s schedule] \\
-C source_credentials_id -R source_aws_region -F source_fs_id [-Y source_type] -M source_svm_ID -N source_svm_name -V source_volume \\
-c destination_credentials_id -r destination_aws_region -f destination_fs_id [-y destination_type] -m destination_svm_ID -n destination_svm_name
Where: refresh_token - Is a refresh token used to obtain an access token needed
to run the Workload Factory APIs. You can obtain a refresh
token by going to https://services.cloud.netapp.com/refresh-token
blueXP_account_ID - is the BlueXP account ID. Run 'list_bluexp_accts' to get a
list of accounts you have access to
aws_region - is the AWS region where you want the list of FSx file system from.
throttle - is the network throughput limit during transfers (optional, defaults to 100 MiB/s. 0 means unlimited)
schedule - is the schedule to use for the SnapMirror relationship (optional, defaults to "hourly")
source_credentials_ID - is the Workload Factory credentials ID for the AWS account. Run
'list_credentials' to get a list of credentials you have access to
source_aws_region - is the AWS region of the source file system
source_fs_ID - is the file system ID of the FSx file system that is the source of the SnapMirror relationship
source_svm_ID - is the SVM ID on the source file system where you want the volume replicated from
source_svm_name - is the name of the SVM on the source file system where you want the volume replicated from
source_type - is the file system type of the source cluster. Either 'FSx' or 'on-prem' (optional, defaults to "FSx")
source_volume - is the name of the source volume to be mirrored
destination_credentials_ID - is the Workload Factory credentials ID for the AWS account. Run
'list_credentials' to get a list of credentials you have access to
destination_aws_region - is the AWS region where the destination file system is located
destination_fs_ID - is the AWS file system ID of the file system that is the destination of the relationship relationship
destination_svm_ID - is the SVM ID of the within destination file system where you want the volume replicated to
destination_svm_name - is the name of the SVM on the destination file system where you want the volume replicated to
destination_type - is the type of the destination file system. Either 'FSx' or 'on-prem' (optional, defaults to "FSx")
Instead of passing parameters on the command line, you can set the
following environment variables:
export REFRESH_TOKEN=<refresh_token>
export BLUEXP_ACCOUNT_ID=<blueXP_account_ID>
EOF
exit 1
}
################################################################################
# Main logic starts here.
################################################################################
tmpout=$(mktemp /tmp/create_mirror-out.XXXXXX)
tmperr=$(mktemp /tmp/create_mirror-err.XXXXXX)
trap 'rm -f $tmpout $tmperr' exit
SOURCE_TYPE="FSx"
DESTINATION_TYPE="FSx"
THROTTLE=102400 # 100 MiB/s
SCHEDULE="hourly"
while getopts "ht:a:l:s:C:R:F:Y:M:N:V:c:r:f:y:m:n:" opt; do
case $opt in
t) REFRESH_TOKEN="$OPTARG" ;;
a) BLUEXP_ACCOUNT_ID="$OPTARG" ;;
l) THROTTLE="$OPTARG" ;;
s) SCHEDULE="$OPTARG" ;;
c) DESTINATION_CREDENTIALS_ID="$OPTARG" ;;
r) DESTINATION_AWS_REGION="$OPTARG" ;;
f) DESTINATION_FS_ID="$OPTARG" ;;
y) DESTINATION_TYPE="$OPTARG" ;;
m) DESTINATION_SVM_ID="$OPTARG" ;;
n) DESTINATION_SVM_NAME="$OPTARG" ;;
F) SOURCE_FS_ID="$OPTARG" ;;
C) SOURCE_CREDENTIALS_ID="$OPTARG" ;;
R) SOURCE_AWS_REGION="$OPTARG" ;;
Y) SOURCE_TYPE="$OPTARG" ;;
M) SOURCE_SVM_ID="$OPTARG" ;;
N) SOURCE_SVM_NAME="$OPTARG" ;;
V) SOURCE_VOLUME="$OPTARG" ;;
*) usage ;;
esac
done
#
# Check if the required parameters are set.
missing_args=false
if [ -z "$REFRESH_TOKEN" ]; then
cat >&2 <<EOF
Error: A BlueXP refresh tokon is required to run this script.
Can you be obtain from this web page:
https://services.cloud.netapp.com/refresh-token
EOF
missing_args=true
fi
if [ -z "$BLUEXP_ACCOUNT_ID" ]; then
cat >&2 <<EOF
Error: A BlueXP account is required to run this script.
You can get the list of accounts you have access to by running the "list_bluexp_accts" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
missing_args=true
fi
if [[ -z "$DESTINATION_CREDENTIALS_ID" || -z "$SOURCE_CREDENTIALS_ID" ]]; then
cat >&2 <<EOF
Error: The source and destination Workload Factory credentials IDs are required to run this script.
You can get the list of credentials you have access to by running the "list_credentials" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
missing_args=true
fi
if [[ -z "$DESTINATION_AWS_REGION" || -z "$SOURCE_AWS_REGION" ]]; then
cat >&2 <<EOF
Error: The source and destination AWS regions are required to run this script.
EOF
missing_args=true
fi
if [[ -z "$DESTINATION_FS_ID" || -z "$SOURCE_FS_ID" ]]; then
cat >&2 <<EOF
Error: The source and destination FSx file system IDs are required to run this script.
You can get the list of file systems you have access to by running the "list_filesystems" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
missing_args=true
fi
if [[ -z "$SOURCE_SVM_ID" || -z "$DESTINATION_SVM_ID" || -z "$SOURCE_SVM_NAME" || -z "$DESTINATION_SVM_NAME" ]]; then
cat >&2 <<EOF
Error: The source and destination SVM IDs and SVM Names are required to run this script.
You can get the list of svm IDs by running the "list_svms" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
missing_args=true
fi
if [ -z "$SOURCE_VOLUME" ]; then
cat >&2 <<EOF
Error: The source volume name is required to run this script.
You can get the list of volumes by running the "list_volumes" script
found in this GitHub repository: https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
missing_agrs=true
fi
if [ "$missing_args" != "false" ]; then
usage
fi
#
# Check that the parameters are valid.
case "$SOURCE_TYPE" in
"FSx") SOURCE_TYPE="FileSystem" ;;
"on-prem") SOURCE_TYPE="OnPrem" ;;
*) echo "Error: Invalid destination type '$SOURCE_TYPE'. Must be either 'FSx' or 'on-prem'." >&2
usage ;;
esac
case "$DESTINATION_TYPE" in
"FSx") DESTINATION_TYPE="FileSystem" ;;
"on-prem") DESTINATION_TYPE="OnPrem" ;;
*) echo "Error: Invalid destination type '$DESTINATION_TYPE'. Must be either 'FSx' or 'on-prem'." >&2
usage ;;
esac
#
# Source the wf_utils file.
wf_utils=$(command -v wf_utils)
if [ -z "$wf_utils" ]; then
if [ ! -x "./wf_utils" ]; then
cat >&2 <<EOF
Error: The 'wf_utils' script was not found in the current directory or in the command search path.
It is required to run this script. You can download it from:
https://github.com/NetApp/FSx-ONTAP-samples-scripts/tree/main/Management-Utilities/Workload-Factory-API-Samples
EOF
exit 1
else
wf_utils=./wf_utils
fi
fi
. "$wf_utils"
#
# Check that the required commands are available.
for cmd in jq curl; do
if ! command -v $cmd &> /dev/null; then
echo "Error: The required command '$cmd' was not found. Please install it." >&2
exit 1
fi
done
token=$(get_token)
if [ -z "$token" ]; then
echo "Error: Failed to obtain an access token. Exiting." >&2
exit 1
fi
run_curl POST "$token" "https://api.workloads.netapp.com/accounts/${BLUEXP_ACCOUNT_ID}/fsx/v2/replication" \
$tmpout $tmperr \
'{"source": {
"type":"'${SOURCE_TYPE}'",
"id":"'${SOURCE_FS_ID}'",
"credentialsId":"'${SOURCE_CREDENTIALS_ID}'",
"region":"'${SOURCE_AWS_REGION}'",
"volumes": [
{
"name":"'${SOURCE_VOLUME}'",
"svmName":"'${SOURCE_SVM_NAME}'",
"svmId":"'${SOURCE_SVM_ID}'"
}
]
},
"destination": {
"type":"'${DESTINATION_TYPE}'",
"id":"'${DESTINATION_FS_ID}'",
"credentialsId":"'${DESTINATION_CREDENTIALS_ID}'",
"region":"'${DESTINATION_AWS_REGION}'",
"svm": {"id":"'${DESTINATION_SVM_ID}'", "name":"'${DESTINATION_SVM_NAME}'"},
"volume": {"tieringPolicy": {"coolingPeriod": 2, "name": "AUTO"}}
},
"throttle":'${THROTTLE}',
"schedule": "'${SCHEDULE}'"
}'