Skip to main content

How to automate Veeam.Backup.Validator.exe powershel script V12


Link State
Forum|alt.badge.img+11

Hello everyone, as per my previous post.

How to atomate & schedule Veeam.Backup.Validator.exe | Veeam Community Resource Hub

 

I am proceeding as promised to update the schedulable veeam validator script. enjoiy 😁

##
# Veeam Backup Validator - v.2.0 18-10-2024
## USAGE:
## > veeam-BackupValidator2.ps1 <jobName> <serverName> <Switch>
#
# Switch:
# -noTicket -> does not send mail to your system ticketing\servicedesk after Validate is completed
#
# e.g.
# > veeam-BackupValidator2.ps1 ‘Yout-Job-name-01’ ‘Yout-Job-name-02’ -notTicket no mail
#
##
PARAM (
#	[string] $customer = "YOUR CUSTOMER NAME",
	[string] $jobName = '*',
	[string] $serverName = '*',
	[switch] $noTicket
	)

## -- Enter the customer name identifier here ($customer = "YOUR CUSTOMER NAME") --
$customer = "YOUR CUSTOMER NAME"
##

$email_infoTO = "youtmail@yourdomain.com"
$email_infoFrom = "$($env:COMPUTERNAME)@iyourdomain.com"
$email_infoServer = "your.smtp.com"
$email_subject = "[$customer] Backup Validation"
$logfolder = "$PSScriptRoot"

## ---- Function ----

Function LogWrite {
   Param ([string]$logString,
	[String] $type = "INFO",
	[bool] $savefile = $true
	)

	$foregroundColor = "white"
	if ($type -like "INFO")    {$foregroundColor = "white"}
	if ($type -like "ERROR")   {$foregroundColor = "red"}
	if ($type -like "WARNING") {$foregroundColor = "yellow"}
	if ($type -like "POSITIVE"){$foregroundColor = "green"}
	$date = get-date -Format HH:mm:ss
	$logString = "[$type][$date]: $logString" 
	if ($savefile){Add-content $mylogfile -value $logString}
	write-host $logString -ForegroundColor $foregroundColor
}

## ---- Main ----

If ($jobName -eq '*') {
	$backups = Get-VBRBackup
} else {
	$backups = Get-VBRBackup -Name $jobName
}

If ($serverName -ne '*') {
	$serverNameFull = "$jobName - $serverName"
} else {
	$serverNameFull = '*'
}

$startDate = $(Get-Date -UFormat "%m-%d-%Y_%H%M")
$OutputFile = "$logfolder\VeeamValidation_$startDate.html"
$mylogfile = "$logfolder\VeeamValidation_$startDate.log"
$serverNameError = $false

LogWrite "$startDate"
LogWrite "Job Name: $jobName"
LogWrite "Server Name: $serverName"
LogWrite "No Ticket switch: $noTicket"

if ($backups) {
	foreach ($backup in $backups) {
		$child_backups = $backup.FindChildBackups()  
		ForEach ($sub_child in $child_backups)  {
			$jobNameSubChild = $sub_child.name

			If (($serverNameFull -eq '*') -or ($serverNameFull -eq $jobNameSubChild)) {
				$id = $sub_child.Id
				$jobNameSubChild =  $jobNameSubChild -replace ' ',''
				$jobNameSubChild =  $jobNameSubChild -replace '\\','#'
				$tempFile = "$logfolder\Validation_$jobNameSubChild.html"

				LogWrite "Validation_$jobNameSubChild"

			#Launch validation
				Set-Location "C:\Program Files\Veeam\Backup and Replication\Backup\"
				$validateResult = "POSITIVE"
				$validateError = "OK"
				try { cmd.exe /c "Veeam.Backup.Validator.exe /backup:$id /report:$tempFile /format:html" }
				catch { $validateResult = "ERROR"
					$validateError = $_ }
				LogWrite "Validate -> $validateError" "$validateResult"
			} else {
				LogWrite "Server Name not Found" "ERROR"
				$serverNameError = $true
			}
		}
	}

	Set-Location $logfolder

	if ($serverNameError -eq $false) {
		Get-ChildItem "Validation_*.html" | sort | Get-Content | Set-Content $OutputFile
		$html = [string]$(Get-Content $OutputFile)

		if ($noTicket -eq $false) {
			$mailResult = "POSITIVE"
			$mailError = "OK"
			try { send-mailmessage -SmtpServer $email_infoServer -to $email_infoTO -from $email_infoFrom -subject $email_subject -body $html -BodyAsHtml -ErrorAction Stop }
			catch { $mailResult = "ERROR"
				$mailError = $_ }

			LogWrite "Mail Sent -> $mailError" "$mailResult"
		}

		$limit = (Get-Date).AddDays(-30)
		# Delete files
		LogWrite "Delete temp files"
		Get-ChildItem "Validation_*.html" | Remove-Item -Force
		# Delete files older than the $limit
		LogWrite "Delete files older than $limit"
		Get-ChildItem VeeamValidation*.html | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
		Get-ChildItem VeeamValidation_*.log | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
		LogWrite "File Removed"
	}
} else {
	LogWrite "Job Name not Found" "ERROR"
}

$endDate = $(Get-Date -uformat "%m-%d-%Y_%H:%M")
LogWrite "$endDate"
LogWrite "--------------------------------"

 

3 comments

Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • 8485 comments
  • November 8, 2024

Nice to see you put this out there as a way to validate backups.  I am going to take this for a test drive and see if we can incorporate it to our backup testing.  Thanks for sharing.


waqasali
Forum|alt.badge.img+3
  • Influencer
  • 198 comments
  • November 8, 2024
Chris.Childerhose wrote:

Nice to see you put this out there as a way to validate backups.  I am going to take this for a test drive and see if we can incorporate it to our backup testing.  Thanks for sharing.

 

Hi @Chris.Childerhose once testing done please share your findings with us defiantly i will try at my end.


waqasali
Forum|alt.badge.img+3
  • Influencer
  • 198 comments
  • November 8, 2024

Hi @Link State

 

your contributions to community are truly appreciated. Thank you! for sharing this I’ll keep this with me and if i got a chance to do some testing I’ll keep posted here as well.