-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathrestore_dlpx_metadata.sh
305 lines (204 loc) · 9.16 KB
/
restore_dlpx_metadata.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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#!/bin/bash
##############
# Author: Jatinder Luthra
# Pre-req: dxtoolkit
##############
engine_name=$1
backup_dir_name=$2
## Validating both arguments are passed ##
if [ $# -lt 2 ]; then
echo ""
echo "!!!! ERROR:: Pass both arguments, Delphix Engine Name and Backup Directory Name !!!!!"
echo""
echo "Example: ./import_metadata.sh <engineName> <backupDirectoryName>"
echo ""
exit 1
fi
###### change below variable values as per your environment #######
dxtoolkit_dir="/Users/jatinder.luthra/Desktop/Customers/BOA/dxtoolkit2"
backup_path="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/DR_backups"
env_config="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/env_config.csv"
db_config="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/db_config.csv"
# (Optional) Only required for 12c Multitenant VDBs using physical containers on target server
vdb_config="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/vdb_config.csv"
####
default_os_pwd="welcome123"
default_db_pwd="welcome123"
####### no changes required below this point ##########
import_date=$(date '+%m%d%Y-%H%M%S')
backup_dir="${backup_path}/${backup_dir_name}"
echo ""
echo "######################################################################################################################"
echo "############## Metadata Restore of engine, ${engine_name} started from directory, ${backup_dir} on ${import_date} ####"
echo "######################################################################################################################"
echo ""
##### Checking Engine Status #######
echo ""
echo "######### Checking Delphix Engine Status #########"
chk_status=`${dxtoolkit_dir}/dx_get_appliance -d ${engine_name}`
echo $chk_status > ${backup_dir}/status.txt
if [[ ${chk_status} =~ "Can't check session status" || ${chk_status} =~ "Can't find" ]]; then
echo "Either Delphix Engine, ${engine_name} is not up OR ${engine_name} entry not present in conf file"
exit 0
else
echo "Delphix Engine ${engine_name} is acessible. Proceeding with restore"
fi
###### Creating Users and Profiles #######
echo ""
echo "#######################################################################"
echo "######### Restoring Delphix Engine Users and Profiles Started #########"
echo "#######################################################################"
users_file=users.csv
profiles_file=profile.csv
users_dir=${backup_dir}/users
${dxtoolkit_dir}/dx_ctl_users -d ${engine_name} -file ${users_dir}/${users_file} -profile ${users_dir}/${profiles_file}
echo ""
echo "######### Restoring Delphix Engine Users and Profiles Finished #########"
#### switch to dxtoolkit directory ####
cd ${dxtoolkit_dir}
###### Creating environments #######
echo ""
echo "##################################################"
echo "######### Restoring Environments Started #########"
echo "##################################################"
env_dir=${backup_dir}/environments
env_res_file=${env_dir}/backup_env.sh
##### Update the correct passwords for OS users before restoring environments#####
##### Validate env_config.csv file resides in backupDir/environments directory #####
INPUT=${env_config}
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read envName osUser pwd
do
sed -r -i "/(-envname \"$envName\") .*(-username \"$osUser\")/s/-password $default_os_pwd/-password $pwd/g" ${env_res_file}
echo "################"
done < $INPUT
IFS=$OLDIFS
### Restoring environments from final file ###
${env_res_file}
echo ""
echo "###################################################"
echo "######### Restoring Environments Finished #########"
echo "###################################################"
###### Creating dSources #######
echo ""
echo "##################################################"
echo "########## Restoring dSources Started #############"
echo "##################################################"
db_dir=${backup_dir}/db_objects
db_res_file=${db_dir}/backup_metadata_dsource.sh
##### Update the correct passwords for DB users before restoring database #####
##### Validate db_config.csv file resides in backupDir/db_objects directory #####
INPUT=${db_config}
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read dSource envName dbUser pwd
do
sed -r -i "/(-dsourcename \"$dSource\") .*(-sourceenv \"$envName\") .*(-dbuser $dbUser)/s/-password $default_db_pwd/-password $pwd/g" ${db_res_file}
sed -r -i "/(-dsourcename \"$dSource\") .*(-sourceenv \"$envName\") .*(-cdbuser \"$dbUser\")/s/-cdbpass $default_db_pwd/-cdbpass $pwd/g" ${db_res_file}
done < $INPUT
IFS=$OLDIFS
### Restoring dSource from final file ###
${db_res_file}
echo ""
echo "##################################################"
echo "########### Restoring dSources Finished ##########"
echo "##################################################"
###### Restore VDB Config Templates #######
echo ""
echo "###############################################################"
echo "########## Restoring VDB Config Templates Started #############"
echo "###############################################################"
template_dir=${backup_dir}/config_templates
FILES=${template_dir}/*
for template in $FILES
do
echo "## Restoring VDB Config template, ${template} ##"
${dxtoolkit_dir}/dx_ctl_template -d ${engine_name} -import -filename "${template}"
done
echo ""
echo "#################################################################"
echo "########## Restoring VDB Config Templates Finished #############"
echo "#################################################################"
###### Restore Hook Templates #######
echo ""
echo "###############################################################"
echo "########## Restoring Hook Templates Started #############"
echo "###############################################################"
hooks_dir=${backup_dir}/hook_templates
${dxtoolkit_dir}/dx_ctl_op_template -d ${engine_name} -importHook -indir ${hooks_dir}
echo ""
echo "#################################################################"
echo "########## Restoring Hook Templates Finished #############"
echo "#################################################################"
###### Creating VDBs #######
echo ""
echo "##################################################"
echo "########## Restoring VDBs Started #############"
echo "##################################################"
db_dir=${backup_dir}/db_objects
vdb_res_file=${db_dir}/backup_metadata_vdb.sh
### For VDBs using physical container###
INPUT=${vdb_config}
### If file exists append the physical container credentials with the VDB creation command ###
if test -f "$INPUT"; then
echo "VDB Config File, ${vdb_config} exists"
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read cdbName envName cdbuser cdbpwd
do
sed -r -i "/(-environment \"$envName\") .*(-cdb $cdbName)/s/$/ -cdbuser \"$cdbuser\" -cdbpass \"$cdbpwd\"/" ${vdb_res_file}
done < $INPUT
IFS=$OLDIFS
else
echo "VDB Config File, ${vdb_config} doesn't exists"
fi
### Restoring VDBs from file ###
${vdb_res_file}
echo ""
echo "##################################################"
echo "########### Restoring VDBs Finished ##########"
echo "##################################################"
###### Restore Policies #######
echo ""
echo "###################################################"
echo "########## Restoring Policies Started #############"
echo "###################################################"
policy_dir=${backup_dir}/policies
policy_file=policy.mapping
## Create custom policies
${dxtoolkit_dir}/dx_ctl_policy -d ${engine_name} -import -indir ${policy_dir}
## Update default policies
${dxtoolkit_dir}/dx_ctl_policy -d ${engine_name} -update -indir ${policy_dir}
## Apply policies on objects
${dxtoolkit_dir}/dx_ctl_policy -d ${engine_name} -mapping ${policy_dir}/${policy_file}
echo ""
echo "####################################################"
echo "########## Restoring Policies Finished #############"
echo "#####################################################"
###### Restore Self Service Objects #######
echo ""
echo "###################################################"
echo "########## Restoring Self Service Started #############"
echo "###################################################"
ss_dir=${backup_dir}/ss_objects
temp_res_file=${ss_dir}/backup_selfservice_templates.sh
cont_res_file=${ss_dir}/backup_selfservice_containers.sh
####### Restoring Templates #####
${temp_res_file}
####### Restoring Containers #####
${cont_res_file}
echo ""
echo "####################################################"
echo "########## Restoring Self Service Finished #############"
echo "#####################################################"
echo ""
echo "#####################################################################################################################################"
echo "######### Metadata Restore of engine, ${engine_name} finished from directory, ${backup_dir} on $(date '+%m%d%Y-%H%M%S') ############"
echo "## Check backup files under directory, ${backup_dir} ##"
echo "#####################################################################################################################################"
echo ""
exit 0