Initial Commit
Created Repo with Scripts to get VPG ID and to take mysql zerto checkpoints
This commit is contained in:
@@ -0,0 +1,95 @@
|
|||||||
|
#################################################################
|
||||||
|
# ZVMEmailAlerts.ps1
|
||||||
|
#
|
||||||
|
# By Justin Paul, Zerto Technical Alliances Architect
|
||||||
|
# Contact info: jp@zerto.com
|
||||||
|
# Repo: https://www.github.com/recklessop/ZertoScripts
|
||||||
|
#
|
||||||
|
# This script looks for Alerts in ZVM in the "Warning" status and
|
||||||
|
# sends an email with relevant information to the administrator.
|
||||||
|
#
|
||||||
|
# For a list of warnings see this PDF
|
||||||
|
# http://s3.amazonaws.com/zertodownload_docs/Latest/Guide%20to%20Alarms,%20Alerts%20and%20Events.pdf
|
||||||
|
#
|
||||||
|
# Note this script is provided as-is and comes with no warranty.
|
||||||
|
# The author takes no responsability for dataloss or corruption of any kind.
|
||||||
|
# Also this script is not supported by Zerto Technical Support.
|
||||||
|
#
|
||||||
|
# With that said, the script only uses "GET" commands so you should be pretty safe.
|
||||||
|
#
|
||||||
|
#################################################################
|
||||||
|
|
||||||
|
################ Variables for your script ######################
|
||||||
|
|
||||||
|
$strZVMIP = "172.16.1.20"
|
||||||
|
$strZVMPort = "9669"
|
||||||
|
$strZVMUser = "administrator@vsphere.local"
|
||||||
|
$strZVMPwd = "myPassword"
|
||||||
|
$vpgName = "myVPG"
|
||||||
|
|
||||||
|
############### ignore self signed SSL ##########################
|
||||||
|
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
|
||||||
|
{
|
||||||
|
$certCallback = @"
|
||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
public class ServerCertificateValidationCallback
|
||||||
|
{
|
||||||
|
public static void Ignore()
|
||||||
|
{
|
||||||
|
if(ServicePointManager.ServerCertificateValidationCallback ==null)
|
||||||
|
{
|
||||||
|
ServicePointManager.ServerCertificateValidationCallback +=
|
||||||
|
delegate
|
||||||
|
(
|
||||||
|
Object obj,
|
||||||
|
X509Certificate certificate,
|
||||||
|
X509Chain chain,
|
||||||
|
SslPolicyErrors errors
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"@
|
||||||
|
Add-Type $certCallback
|
||||||
|
}
|
||||||
|
[ServerCertificateValidationCallback]::Ignore()
|
||||||
|
#################################################################
|
||||||
|
|
||||||
|
## Perform authentication so that Zerto APIs can run. Return a session identifier that needs tobe inserted in the header for subsequent requests.
|
||||||
|
function getxZertoSession ($userName, $password){
|
||||||
|
$baseURL = "https://" + $strZVMIP + ":" + $strZVMPort
|
||||||
|
$xZertoSessionURL = $baseURL +"/v1/session/add"
|
||||||
|
$authInfo = ("{0}:{1}" -f $userName,$password)
|
||||||
|
$authInfo = [System.Text.Encoding]::UTF8.GetBytes($authInfo)
|
||||||
|
$authInfo = [System.Convert]::ToBase64String($authInfo)
|
||||||
|
$headers = @{Authorization=("Basic {0}" -f $authInfo)}
|
||||||
|
$contentType = "application/json"
|
||||||
|
$xZertoSessionResponse = Invoke-WebRequest -Uri $xZertoSessionURL -Headers $headers -Method POST -Body $body -ContentType $contentType
|
||||||
|
#$xZertoSessionResponse = Invoke-WebRequest -Uri $xZertoSessionURL -Headers $headers -Body $body -Method POST
|
||||||
|
return $xZertoSessionResponse.headers.get_item("x-zerto-session")
|
||||||
|
}
|
||||||
|
|
||||||
|
#Extract x-zerto-session from the response, and add it to the actual API:
|
||||||
|
$xZertoSession = getxZertoSession $strZVMUser $strZVMPwd
|
||||||
|
$zertoSessionHeader = @{"x-zerto-session"=$xZertoSession}
|
||||||
|
$zertoSessionHeader_xml = @{"Accept"="application/xml"
|
||||||
|
"x-zerto-session"=$xZertoSession}
|
||||||
|
|
||||||
|
################ Your Script starts here #######################
|
||||||
|
#Invoke the Zerto API:
|
||||||
|
$peerListApiUrl = "https://" + $strZVMIP + ":"+$strZVMPort+"/v1/vpgs"
|
||||||
|
|
||||||
|
#Iterate with JSON:
|
||||||
|
$vpgListJSON = Invoke-RestMethod -Uri $peerListApiUrl -Headers $zertoSessionHeader
|
||||||
|
foreach ($vpg in $vpgListJSON){
|
||||||
|
if ( $vpg.VpgName -eq $vpgName ){
|
||||||
|
$vpg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
##End of script
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
##############################################################################
|
||||||
|
# ZertoMySQLCheckpoint.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 all MySQL tables and flush data to disk.
|
||||||
|
# 2.) Call Zerto REST API and insert a User defined Checkpoint
|
||||||
|
# 3.) Unlock the MySQL tables and resume normal operations
|
||||||
|
#
|
||||||
|
# You must provide the VPGID for the VPG that needs the checkpoint inserted.
|
||||||
|
# To get this information
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
##### Variables Replace with your information #####
|
||||||
|
ZVMIP="172.16.1.20"
|
||||||
|
ZVMPORT="9669"
|
||||||
|
ZVMUSER="administrator@vsphere.local"
|
||||||
|
ZVMPWD="mypassword"
|
||||||
|
VPGID="97b4b6be-5447-491b-bd10-be3600c91ff0"
|
||||||
|
MYSQLUSER="adminuser"
|
||||||
|
MYSQLPASSWORD="adminpassword"
|
||||||
|
|
||||||
|
##### Write Date Time to Log file #####
|
||||||
|
|
||||||
|
##### Login to Zerto REST API #####
|
||||||
|
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
|
||||||
|
|
||||||
|
##### Lock and Flush MySQL Databases #####
|
||||||
|
outputLock=$(mysql --user="${MYSQLUSER}" --password="${MYSQLPASSWORD}" --execute=' flush tables with read lock;' 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":"MySQL Quiesced Checkpoint"}' https://${ZVMIP}:${ZVMPORT}/v1/vpgs/"${VPGID}"/Checkpoints)
|
||||||
|
echo $responseHeader >> ZertoCheckpointInsert.log
|
||||||
|
|
||||||
|
##### Lock and Flush MySQL Databases #####
|
||||||
|
outputUnlock=$(mysql --user="${MYSQLUSER}" --password="${MYSQLPASSWORD}" --execute=' unlock tables;' 2>&1)
|
||||||
|
echo $outputUnlock >> ZertoCheckpointInsert.log
|
||||||
|
|
||||||
Reference in New Issue
Block a user