I wanted to know how VEEAM determines if a script has an error, in order to fail the job (ie.. I don't want to process the node if preparation doesn't properly occur). Could I use an exit code, or do I have to create some sort of error message to output that VEEAM will see and consider the script as failed?
Here is my script as it currently stands. All is working properly and checking to be able to failover (including AlwaysOn Availability Groups), other than making sure it has a proper error report for VEEAM if the script isn't able to complete
Code: Select all
<#
Prep script for backing up WSFC nodes.
This script moves existing roles to the secondary server (if not already there), and stops the cluster node
This is required prep work for backing up cluster nodes, to ensure cluster is up during backups.
#>
param (
[string]$source = $(throw "-primary is required."),
[string]$destination = $(throw "-primary is required."),
[string]$cluster = $(throw "-primary is required.")
)
Import-Module FailoverClusters
Import-Module SQLPS -DisableNameChecking
#Determine if SQL Server is installed and running on cluster node
$Status = (Get-Service -ComputerName $source -Name MSSQLSERVER) | where-object {$_.Status -eq "Running"}
#If SQL Service is installed and running, attempt failover
if ($Status) {
#Check to ensure database is synchronized
$Synchronized = $TRUE
$isPrimary = $FALSE
do {
If ( Test-Path SQLSERVER:\sql\$source ) {
Get-ChildItem SQLSERVER:\sql\$source |
ForEach { # Instances
ForEach ( $AG in $_.AvailabilityGroups) {
#If this server is primary, ensure database is synchronized
if($AG.PrimaryReplicaServerName -eq $source)
{
$isPrimary = $TRUE
ForEach ( $db in $AG.DatabaseReplicaStates) {
if ($($db.SynchronizationState) -ne 'Synchronized' -and $db.AvailabilityReplicaServerName -eq $source) {
$Synchronized = $FALSE
break;
}
}
if(!$Synchronized) { break }
}
} # AvailabilityGroups
if(!$Synchronized) { break }
} # Instances
} # Test-Path
if(!$Synchronized) { Start-Sleep -s 10 }
} while (!$Synchronized)
#Check destination mode to make sure status is up - if not exit with Fail condition
if($(Get-ClusterNode $destination -cluster $cluster).State -ne 'Up') { exit 1 }
#Failover SQL
if ($isPrimary) {
try
{
echo $Synchronized
echo "failing over"
Switch-SqlAvailabilityGroup -Path SQLSERVER:\Sql\$destination\DEFAULT\AvailabilityGroups\sqlha
}
catch
{
#Exit with fail condition
exit 1
}
}
}
echo "suspending node"
Suspend-ClusterNode $source -Cluster $Cluster -Drain
Stop-ClusterNode $source -Cluster $Cluster