11#! /bin/sh
2- #
32# Copyright (c) 2018 by Delphix. All rights reserved.
4- #
5-
6- # #DEBUG## In Delphix debug.log
7- # set -x
8-
9- #
10- # Program Name ...
11- #
123PGM_NAME=' restore_stage.sh'
134
14- #
155# Load Library ...
16- #
176eval " ${DLPX_LIBRARY_SOURCE} "
18- result=` hey `
19- log " ------------------------- Start"
20- log " Library Loaded ... hey $result "
7+ result=` library_load `
8+ log " Start ${PGM_NAME} "
9+ log " Library Load Status: $result "
2110
2211who=` whoami`
2312log " whoami: $who "
@@ -29,23 +18,17 @@ log "awk: ${AWK}"
2918
3019DT=` date ' +%Y%m%d%H%M%S' `
3120
32- #
33- # Software Binaries ...
34- #
21+ # Software Binaries
3522INSTALL_BIN=" ${SOURCEBASEDIR} /bin"
3623log " Binaries: ${INSTALL_BIN} "
3724
38- #
39- # Ports ...
40- #
25+ # Ports
4126SOURCE_PORT=${SOURCEPORT}
4227TARGET_PORT=${STAGINGPORT}
4328log " Source Port: ${SOURCE_PORT} "
4429log " Staging Port: ${TARGET_PORT} "
4530
46- #
4731# Backup File Location ...
48- #
4932if [[ " ${BACKUP_PATH} " == " " ]]
5033then
5134 BKUP_FILE=" /tmp/dump_${SOURCE_PORT} .sql"
5437fi
5538log " Backup File: ${BKUP_FILE} "
5639
57- #
5840# Staging Connection for Install/Configuration ...
59- #
6041STAGINGPASS=` echo " '" ${STAGINGPASS} " '" `
6142
6243log " Staging Connection: ${STAGINGCONN} "
@@ -65,9 +46,7 @@ echo "${RESULTS}" | $DLPX_BIN_JQ --raw-output ".string"
6546STAGING_CONN=` echo " ${RESULTS} " | $DLPX_BIN_JQ --raw-output " .string" `
6647log " Staging Connection: ${STAGING_CONN} "
6748
68- #
6949# Replication Variables ...
70- #
7150log " ========= Replication Variables ==========="
7251log " Staging Host: ${STAGINGHOSTIP} "
7352MASTER_HOST=" ${SOURCEIP} "
@@ -78,9 +57,7 @@ MASTER_PORT="${SOURCEPORT}"
7857log " MASTER_PORT: ${MASTER_PORT} "
7958MASTER_PASS=" ${REPLICATION_PASS} "
8059
81- #
8260# Directory Paths ...
83- #
8461NEW_MOUNT_DIR=" ${STAGINGDATADIR} "
8562log " Staging Base Directory: ${NEW_MOUNT_DIR} "
8663
@@ -93,95 +70,56 @@ NEW_SERVER_ID="${STAGINGSERVERID}"
9370
9471# ##########################################################
9572# # On Staging Server ...
96-
9773# scp from source server the ${BKUP_FILE}
98-
99- #
10074# Get master log file and position ...
10175#
10276log " LogSync Enabled: ${LOGSYNC} "
10377if [[ " ${LOGSYNC} " == " true" ]]
10478then
105-
10679 # head ${BKUP_FILE} -n80 | grep "MASTER_LOG_POS"
10780 STR=$( head ${BKUP_FILE} -n80 | grep " MASTER_LOG_POS" )
108- # #echo "${STR}"
10981 BINLOG_FILENAME=` echo " ${STR} " | ${AWK} -F" =" ' {print $2}' | cut -d" ," -f1 | tr -d \' `
11082 BINLOG_POSITION=` echo " ${STR} " | ${AWK} -F" =" ' {print $3}' | cut -d" ;" -f1`
11183 log " BackupFile: ${BKUP_FILE} "
11284 log " MasterLogFile: ${BINLOG_FILENAME} "
11385 log " MasterLogPosition: ${BINLOG_POSITION} "
114-
11586fi
11687
117- #
11888# Create Initial Database ...
119- #
12089log " MySQL Version: ${MYSQLVER} "
121- # MYSQLVER="5.7.20"
122- # MYSQLVER="5.6.28-76.1"
123- # 10.1.32-MariaDB
124- # echo ${MYSQLVER:0:3}
125- # 5.6
126-
12790log " Source --basedir=${SOURCEBASEDIR} "
12891log " Source --datadir=${SOURCEDATADIR} "
92+ log " Creating Initial Database"
12993
130- #
131- # Change MySQL Database Tables ...
132- #
133- # log "Checking for Customer Initial Database ..."
134- # if [[ -f "${DLPX_TOOLKIT}/install_db.zip" ]]
135- # then
136- # log "Installing ${DLPX_TOOLKIT}/install_db.zip into ${NEW_MOUNT_DIR}"
137- # unzip ${DLPX_TOOLKIT}/install_db.zip -d ${NEW_MOUNT_DIR}
138- # else
139- # #die "Error: Missing Initial Database zip file ... ${DLPX_TOOLKIT}/install_db.zip"
140- # log "Missing Initial Database zip file ... ${DLPX_TOOLKIT}/install_db.zip"
141-
142- log " Creating Initial Database ..."
143-
144- #
145- # Create Initial Database 5.7 or later ...
146- #
147- log " Using mysqld --initialize ..."
148-
149- log " ${MYSQLD} /mysqld --initialize --user=mysql --datadir=${NEW_DATA_DIR} --log-error=${NEW_DATA_DIR} /mysqld.log"
150- ${MYSQLD} /mysqld --initialize --user=mysql --datadir=${NEW_DATA_DIR} --log-error=${NEW_DATA_DIR} /mysqld.log 1>> ${DEBUG_LOG} 2>&1
151-
152- PWD_LINE=` cat ${NEW_DATA_DIR} /mysqld.log | grep ' temporary password' `
153- # sudo grep 'temporary password' ${NEW_DATA_DIR}/mysqld.log`
154- # 2019-04-11T14:40:34.032576Z 1 [Note] A temporary password is generated for root@localhost: L0qXNZ8?C3Us
155- log " init temporary password: ${PWD_LINE} "
156-
157- TMP_PWD=` echo " ${PWD_LINE} " | ${AWK} -F" : " ' {print $2}' | xargs`
158- #
159- # These temporary passwords contain special characters so need to wrap in single / literal quotes ...
160- #
161- TMP_PWD=` echo " '" $TMP_PWD " '" `
162- log " Temporary Password: ${TMP_PWD} "
94+ # Create Initial Database 5.7 or later ...
95+ log " Using mysqld --initialize"
16396
164- log " Staging Connection: ${STAGINGCONN} "
165- RESULTS=$( buildConnectionString " ${STAGINGCONN} " " ${TMP_PWD} " " ${STAGINGPORT} " " ${STAGINGHOSTIP} " )
166- echo " ${RESULTS} " | $DLPX_BIN_JQ --raw-output " .string"
167- STAGING_CONN=` echo " ${RESULTS} " | $DLPX_BIN_JQ --raw-output " .string" `
168- log " Staging Connection: ${STAGING_CONN} "
97+ log " ${MYSQLD} /mysqld --initialize --user=mysql --datadir=${NEW_DATA_DIR} --log-error=${NEW_DATA_DIR} /mysqld.log"
98+ ${MYSQLD} /mysqld --initialize --user=mysql --datadir=${NEW_DATA_DIR} --log-error=${NEW_DATA_DIR} /mysqld.log 1>> ${DEBUG_LOG} 2>&1
16999
170- # fi # end if customer install_db.zip ...
100+ PWD_LINE=` cat ${NEW_DATA_DIR} /mysqld.log | grep ' temporary password' `
101+ # sudo grep 'temporary password' ${NEW_DATA_DIR}/mysqld.log`
102+ # 2019-04-11T14:40:34.032576Z 1 [Note] A temporary password is generated for root@localhost: L0qXNZ8?C3Us
103+ log " init temporary password: ${PWD_LINE} "
171104
105+ TMP_PWD=` echo " ${PWD_LINE} " | ${AWK} -F" : " ' {print $2}' | xargs`
106+ # These temporary passwords contain special characters so need to wrap in single / literal quotes ...
107+ TMP_PWD=` echo " '" $TMP_PWD " '" `
108+ log " Temporary Password: ${TMP_PWD} "
109+ log " Staging Connection: ${STAGINGCONN} "
110+ RESULTS=$( buildConnectionString " ${STAGINGCONN} " " ${TMP_PWD} " " ${STAGINGPORT} " " ${STAGINGHOSTIP} " )
111+ echo " ${RESULTS} " | $DLPX_BIN_JQ --raw-output " .string"
112+ STAGING_CONN=` echo " ${RESULTS} " | $DLPX_BIN_JQ --raw-output " .string" `
113+ log " Staging Connection: ${STAGING_CONN} "
172114log " Creation Results: ${RESULTS} "
173115
174116# ###########################################################
175- # #
176- log " Creating Staging Directories on NFS Mounted Path from Delphix ..."
177-
117+ log " Creating Staging Directories on NFS Mounted Path from Delphix"
178118mkdir -p ${NEW_DATA_DIR}
179119mkdir -p ${NEW_LOG_DIR}
180120mkdir -p ${NEW_TMP_DIR}
181121
182- #
183122# This snippet creates a config file if one has not been provided.
184- #
185123log " my.cnf file location > ${NEW_MY_CNF} "
186124
187125if [[ -f " ${DLPX_TOOLKIT} /my.cnf" ]]
@@ -220,15 +158,9 @@ log "my.cnf exists? ${CMD}"
220158
221159if [[ -f " ${NEW_MY_CNF} " ]]
222160then
223- #
224161 # Replace all tabs with spaces ...
225- #
226162 sed -i ' s/\t/ /g' ${NEW_MY_CNF}
227-
228- #
229163 # Update Parameters ...
230- #
231-
232164 log " Parameter port = $TARGET_PORT "
233165 CHK=` cat ${NEW_MY_CNF} | grep " ^port" `
234166 if [[ " ${CHK} " != " " ]]
238170 else
239171 echo " port = ${TARGET_PORT} " >> ${NEW_MY_CNF}
240172 fi
241-
242173 log " Parameter server-id = ${NEW_SERVER_ID} "
243174 CHK=` cat ${NEW_MY_CNF} | grep " ^server-id" `
244175 if [[ " ${CHK} " != " " ]]
@@ -640,5 +571,5 @@ export DLPX_LIBRARY_SOURCE=""
640571export REPLICATION_PASS=" "
641572export STAGINGPASS=" "
642573env | sort >> $DEBUG_LOG
643- log " ------------------------- End"
574+ log " <<< End"
644575exit 0
0 commit comments