|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | + |
| 4 | +############## |
| 5 | +# Author: Jatinder Luthra |
| 6 | +# Pre-req: dxtoolkit |
| 7 | +############## |
| 8 | + |
| 9 | +engine_name=$1 |
| 10 | +backup_dir_name=$2 |
| 11 | + |
| 12 | +## Validating both arguments are passed ## |
| 13 | + |
| 14 | +if [ $# -lt 2 ]; then |
| 15 | + echo "" |
| 16 | + echo "!!!! ERROR:: Pass both arguments, Delphix Engine Name and Backup Directory Name !!!!!" |
| 17 | + echo"" |
| 18 | + echo "Example: ./import_metadata.sh <engineName> <backupDirectoryName>" |
| 19 | + echo "" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +###### change below variable values as per your environment ####### |
| 24 | + |
| 25 | +dxtoolkit_dir="/Users/jatinder.luthra/Desktop/Customers/BOA/dxtoolkit2" |
| 26 | + |
| 27 | +backup_path="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/DR_backups" |
| 28 | + |
| 29 | +env_config="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/env_config.csv" |
| 30 | + |
| 31 | +db_config="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/db_config.csv" |
| 32 | + |
| 33 | +# (Optional) Only required for 12c Multitenant VDBs using physical containers on target server |
| 34 | + |
| 35 | +vdb_config="/Users/jatinder.luthra/Desktop/Scripts/DR_Scripts/vdb_config.csv" |
| 36 | + |
| 37 | +#### |
| 38 | + |
| 39 | +default_os_pwd="welcome123" |
| 40 | + |
| 41 | +default_db_pwd="welcome123" |
| 42 | + |
| 43 | +####### no changes required below this point ########## |
| 44 | + |
| 45 | +import_date=$(date '+%m%d%Y-%H%M%S') |
| 46 | + |
| 47 | +backup_dir="${backup_path}/${backup_dir_name}" |
| 48 | + |
| 49 | +echo "" |
| 50 | +echo "######################################################################################################################" |
| 51 | +echo "############## Metadata Restore of engine, ${engine_name} started from directory, ${backup_dir} on ${import_date} ####" |
| 52 | +echo "######################################################################################################################" |
| 53 | +echo "" |
| 54 | + |
| 55 | +##### Checking Engine Status ####### |
| 56 | + |
| 57 | +echo "" |
| 58 | +echo "######### Checking Delphix Engine Status #########" |
| 59 | + |
| 60 | +chk_status=`${dxtoolkit_dir}/dx_get_appliance -d ${engine_name}` |
| 61 | +echo $chk_status > ${backup_dir}/status.txt |
| 62 | + |
| 63 | +if [[ ${chk_status} =~ "Can't check session status" || ${chk_status} =~ "Can't find" ]]; then |
| 64 | +echo "Either Delphix Engine, ${engine_name} is not up OR ${engine_name} entry not present in conf file" |
| 65 | +exit 0 |
| 66 | +else |
| 67 | +echo "Delphix Engine ${engine_name} is acessible. Proceeding with restore" |
| 68 | +fi |
| 69 | + |
| 70 | +###### Creating Users and Profiles ####### |
| 71 | + |
| 72 | +echo "" |
| 73 | +echo "#######################################################################" |
| 74 | +echo "######### Restoring Delphix Engine Users and Profiles Started #########" |
| 75 | +echo "#######################################################################" |
| 76 | + |
| 77 | + |
| 78 | +users_file=users.csv |
| 79 | +profiles_file=profile.csv |
| 80 | +users_dir=${backup_dir}/users |
| 81 | + |
| 82 | +${dxtoolkit_dir}/dx_ctl_users -d ${engine_name} -file ${users_dir}/${users_file} -profile ${users_dir}/${profiles_file} |
| 83 | + |
| 84 | +echo "" |
| 85 | +echo "######### Restoring Delphix Engine Users and Profiles Finished #########" |
| 86 | + |
| 87 | +#### switch to dxtoolkit directory #### |
| 88 | + |
| 89 | +cd ${dxtoolkit_dir} |
| 90 | + |
| 91 | +###### Creating environments ####### |
| 92 | + |
| 93 | +echo "" |
| 94 | +echo "##################################################" |
| 95 | +echo "######### Restoring Environments Started #########" |
| 96 | +echo "##################################################" |
| 97 | + |
| 98 | + |
| 99 | +env_dir=${backup_dir}/environments |
| 100 | +env_res_file=${env_dir}/backup_env.sh |
| 101 | + |
| 102 | +##### Update the correct passwords for OS users before restoring environments##### |
| 103 | +##### Validate env_config.csv file resides in backupDir/environments directory ##### |
| 104 | + |
| 105 | +INPUT=${env_config} |
| 106 | +OLDIFS=$IFS |
| 107 | +IFS=',' |
| 108 | +[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } |
| 109 | +while read envName osUser pwd |
| 110 | +do |
| 111 | + |
| 112 | +sed -r -i "/(-envname \"$envName\") .*(-username \"$osUser\")/s/-password $default_os_pwd/-password $pwd/g" ${env_res_file} |
| 113 | + |
| 114 | +echo "################" |
| 115 | +done < $INPUT |
| 116 | +IFS=$OLDIFS |
| 117 | + |
| 118 | +### Restoring environments from final file ### |
| 119 | +${env_res_file} |
| 120 | + |
| 121 | +echo "" |
| 122 | +echo "###################################################" |
| 123 | +echo "######### Restoring Environments Finished #########" |
| 124 | +echo "###################################################" |
| 125 | + |
| 126 | + |
| 127 | +###### Creating dSources ####### |
| 128 | + |
| 129 | +echo "" |
| 130 | +echo "##################################################" |
| 131 | +echo "########## Restoring dSources Started #############" |
| 132 | +echo "##################################################" |
| 133 | + |
| 134 | + |
| 135 | +db_dir=${backup_dir}/db_objects |
| 136 | +db_res_file=${db_dir}/backup_metadata_dsource.sh |
| 137 | + |
| 138 | +##### Update the correct passwords for DB users before restoring database ##### |
| 139 | +##### Validate db_config.csv file resides in backupDir/db_objects directory ##### |
| 140 | + |
| 141 | +INPUT=${db_config} |
| 142 | +OLDIFS=$IFS |
| 143 | +IFS=',' |
| 144 | +[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } |
| 145 | +while read dSource envName dbUser pwd |
| 146 | +do |
| 147 | + |
| 148 | +sed -r -i "/(-dsourcename \"$dSource\") .*(-sourceenv \"$envName\") .*(-dbuser $dbUser)/s/-password $default_db_pwd/-password $pwd/g" ${db_res_file} |
| 149 | + |
| 150 | +sed -r -i "/(-dsourcename \"$dSource\") .*(-sourceenv \"$envName\") .*(-cdbuser \"$dbUser\")/s/-cdbpass $default_db_pwd/-cdbpass $pwd/g" ${db_res_file} |
| 151 | + |
| 152 | +done < $INPUT |
| 153 | +IFS=$OLDIFS |
| 154 | + |
| 155 | +### Restoring dSource from final file ### |
| 156 | +${db_res_file} |
| 157 | + |
| 158 | +echo "" |
| 159 | +echo "##################################################" |
| 160 | +echo "########### Restoring dSources Finished ##########" |
| 161 | +echo "##################################################" |
| 162 | + |
| 163 | +###### Restore VDB Config Templates ####### |
| 164 | + |
| 165 | +echo "" |
| 166 | +echo "###############################################################" |
| 167 | +echo "########## Restoring VDB Config Templates Started #############" |
| 168 | +echo "###############################################################" |
| 169 | + |
| 170 | + |
| 171 | +template_dir=${backup_dir}/config_templates |
| 172 | + |
| 173 | +FILES=${template_dir}/* |
| 174 | +for template in $FILES |
| 175 | +do |
| 176 | + echo "## Restoring VDB Config template, ${template} ##" |
| 177 | + |
| 178 | + ${dxtoolkit_dir}/dx_ctl_template -d ${engine_name} -import -filename "${template}" |
| 179 | +done |
| 180 | + |
| 181 | +echo "" |
| 182 | +echo "#################################################################" |
| 183 | +echo "########## Restoring VDB Config Templates Finished #############" |
| 184 | +echo "#################################################################" |
| 185 | + |
| 186 | +###### Restore Hook Templates ####### |
| 187 | + |
| 188 | +echo "" |
| 189 | +echo "###############################################################" |
| 190 | +echo "########## Restoring Hook Templates Started #############" |
| 191 | +echo "###############################################################" |
| 192 | + |
| 193 | + |
| 194 | +hooks_dir=${backup_dir}/hook_templates |
| 195 | + |
| 196 | +${dxtoolkit_dir}/dx_ctl_op_template -d ${engine_name} -importHook -indir ${hooks_dir} |
| 197 | + |
| 198 | +echo "" |
| 199 | +echo "#################################################################" |
| 200 | +echo "########## Restoring Hook Templates Finished #############" |
| 201 | +echo "#################################################################" |
| 202 | + |
| 203 | +###### Creating VDBs ####### |
| 204 | + |
| 205 | +echo "" |
| 206 | +echo "##################################################" |
| 207 | +echo "########## Restoring VDBs Started #############" |
| 208 | +echo "##################################################" |
| 209 | + |
| 210 | + |
| 211 | +db_dir=${backup_dir}/db_objects |
| 212 | +vdb_res_file=${db_dir}/backup_metadata_vdb.sh |
| 213 | + |
| 214 | + |
| 215 | +### For VDBs using physical container### |
| 216 | + |
| 217 | +INPUT=${vdb_config} |
| 218 | + |
| 219 | +### If file exists append the physical container credentials with the VDB creation command ### |
| 220 | + |
| 221 | +if test -f "$INPUT"; then |
| 222 | + echo "VDB Config File, ${vdb_config} exists" |
| 223 | + OLDIFS=$IFS |
| 224 | + IFS=',' |
| 225 | + [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } |
| 226 | + while read cdbName envName cdbuser cdbpwd |
| 227 | + do |
| 228 | + |
| 229 | + sed -r -i "/(-environment \"$envName\") .*(-cdb $cdbName)/s/$/ -cdbuser \"$cdbuser\" -cdbpass \"$cdbpwd\"/" ${vdb_res_file} |
| 230 | + |
| 231 | + done < $INPUT |
| 232 | + IFS=$OLDIFS |
| 233 | + else |
| 234 | + echo "VDB Config File, ${vdb_config} doesn't exists" |
| 235 | +fi |
| 236 | + |
| 237 | +### Restoring VDBs from file ### |
| 238 | +${vdb_res_file} |
| 239 | + |
| 240 | +echo "" |
| 241 | +echo "##################################################" |
| 242 | +echo "########### Restoring VDBs Finished ##########" |
| 243 | +echo "##################################################" |
| 244 | + |
| 245 | +###### Restore Policies ####### |
| 246 | + |
| 247 | +echo "" |
| 248 | +echo "###################################################" |
| 249 | +echo "########## Restoring Policies Started #############" |
| 250 | +echo "###################################################" |
| 251 | + |
| 252 | + |
| 253 | +policy_dir=${backup_dir}/policies |
| 254 | +policy_file=policy.mapping |
| 255 | + |
| 256 | +## Create custom policies |
| 257 | + |
| 258 | +${dxtoolkit_dir}/dx_ctl_policy -d ${engine_name} -import -indir ${policy_dir} |
| 259 | + |
| 260 | +## Update default policies |
| 261 | + |
| 262 | +${dxtoolkit_dir}/dx_ctl_policy -d ${engine_name} -update -indir ${policy_dir} |
| 263 | + |
| 264 | +## Apply policies on objects |
| 265 | + |
| 266 | +${dxtoolkit_dir}/dx_ctl_policy -d ${engine_name} -mapping ${policy_dir}/${policy_file} |
| 267 | + |
| 268 | +echo "" |
| 269 | +echo "####################################################" |
| 270 | +echo "########## Restoring Policies Finished #############" |
| 271 | +echo "#####################################################" |
| 272 | + |
| 273 | +###### Restore Self Service Objects ####### |
| 274 | + |
| 275 | +echo "" |
| 276 | +echo "###################################################" |
| 277 | +echo "########## Restoring Self Service Started #############" |
| 278 | +echo "###################################################" |
| 279 | + |
| 280 | + |
| 281 | +ss_dir=${backup_dir}/ss_objects |
| 282 | + |
| 283 | +temp_res_file=${ss_dir}/backup_selfservice_templates.sh |
| 284 | +cont_res_file=${ss_dir}/backup_selfservice_containers.sh |
| 285 | + |
| 286 | +####### Restoring Templates ##### |
| 287 | + |
| 288 | +${temp_res_file} |
| 289 | + |
| 290 | +####### Restoring Containers ##### |
| 291 | + |
| 292 | +${cont_res_file} |
| 293 | + |
| 294 | +echo "" |
| 295 | +echo "####################################################" |
| 296 | +echo "########## Restoring Self Service Finished #############" |
| 297 | +echo "#####################################################" |
| 298 | + |
| 299 | +echo "" |
| 300 | +echo "#####################################################################################################################################" |
| 301 | +echo "######### Metadata Restore of engine, ${engine_name} finished from directory, ${backup_dir} on $(date '+%m%d%Y-%H%M%S') ############" |
| 302 | +echo "## Check backup files under directory, ${backup_dir} ##" |
| 303 | +echo "#####################################################################################################################################" |
| 304 | +echo "" |
| 305 | +exit 0 |
0 commit comments