From bf2ad2d5b1387acdad0aab344ceb18115863a75c Mon Sep 17 00:00:00 2001 From: Justin Paul Date: Fri, 4 May 2018 10:15:41 -0400 Subject: [PATCH] Create ZertoMongoCheckpoint.sh Version 2.0 of the MongoDB Zerto Checkpoint script. This version does not require any Powershell scripts. --- ZertoMongoCheckpoint.sh | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 ZertoMongoCheckpoint.sh diff --git a/ZertoMongoCheckpoint.sh b/ZertoMongoCheckpoint.sh new file mode 100644 index 0000000..bda1444 --- /dev/null +++ b/ZertoMongoCheckpoint.sh @@ -0,0 +1,48 @@ +#!/bin/bash +############################################################################## +# ZertoMongoCheckpoint.sh +# +# Created by Justin Paul, Tech Alliances Architect, Zerto +# Contact at jp@zerto.com or on Twitter at @recklessop +# +# This script does the following: +# 1.) Lock MongoDB and flush data to disk. +# 2.) Call Zerto REST API and insert a User defined Checkpoint +# 3.) Unlock the MongoDB and resume normal operations +# +# You must provide the VPGID for the VPG that needs the checkpoint inserted. +# To get this information +############################################################################## + +##### Variables ##### +ZVMIP="172.16.1.20" +ZVMPORT="9669" +ZVMUSER="administrator@vsphere.local" +ZVMPWD="mypassword" +VPGID="97b4b6be-5447-491b-bd10-be3600c91ff0" +MONGOUSER="admin" +MONGOPASSWORD="password" + +##### Insert Date and Time into the Log file ##### +echo "$(date)" > ZertoCheckpointInsert.log + +##### Login to Zerto REST API and check VPG name ##### +curl -k -D responseHeader -H "Content-Type: application/json" -H "Accept: application/json" --user $ZVMUSER:$ZVMPWD https://${ZVMIP}:${ZVMPORT}/v1/session/add -d "{\"AuthenticationMethod\":0}" +COOKIE=`cat responseHeader | grep x-zerto-session` +SESSION=$(echo "$COOKIE"|tr -d '\r') +echo "---------------------------------" > ZertoCheckpointInsert.log +echo $SESSION >> ZertoCheckpointInsert.log +echo "---------------------------------" >> ZertoCheckpointInsert.log +#VPGLIST=$(curl -k -H "${SESSION}" -H "Content-Type: application/json" -H "Accept: application/json" https://${ZVMIP}:${ZVMPORT}/v1/vpgs) + +##### Lock and Flush MySQL Databases ##### +outputLock=$(mongo -u ${MONGOUSER} -p ${MONGOPASSWORD} --authenticationDatabase admin --eval 'db.fsyncLock()' 2>&1) +echo $outputLock >> ZertoCheckpointInsert.log + +##### Insert Zerto User Checkpoint ##### +INSERTOUTPUT=$(curl -k -H "${SESSION}" -H "Content-Type: application/json" -H "Accept: application/json" -X POST -d '{"checkpointName":"MongoDB Quiesced Checkpoint"}' https://${ZVMIP}:${ZVMPORT}/v1/vpgs/"${VPGID}"/Checkpoints) +echo $responseHeader >> ZertoCheckpointInsert.log + +##### Lock and Flush MySQL Databases ##### +outputUnlock=$(mongo -u ${MONGOUSER} -p ${MONGOPASSWORD} --authenticationDatabase admin --eval 'db.fsyncUnlock()' 2>&1) +echo $outputUnlock >> ZertoCheckpointInsert.log