PowerShell script exchange
Post Reply
saintdle
Veeam Vanguard
Posts: 103
Liked: 17 times
Joined: Aug 05, 2014 1:13 pm
Full Name: Dean lewis
Contact:

Backup Validator - PS Script to run against all backups

Post by saintdle »

After finding the backup validator tool,

Myself and a Friend wrote a powershell script that runs this tool against all the backup jobs, produces a HTML file and then emails this to a given recipient,

It's by no way perfect, and took us a late night to get working, but it works.

You can then setup a task schedule to run this as and when you need it.

I hope someone out there finds it useful

Code: Select all

#Set the Output file location
$VeeamOutputFile = c:\Powershell\VMe-$jobname-$date.html

#Set the sending email address and destination address
$SenderAddr = Veeam@Company.co.uk
$DestinationAddr = User@Company.co.uk

#Set the email server
$SMTPServer = mail.company.co.uk

######################################
#Do not edit anything below this line#
######################################

Add-PSSnapIn VeeamPSSNapin
$date = (Get-Date).AddDays(-1).ToString('dd-MM-yyyy')
set-location "C:\Program Files\Veeam\Backup and Replication\Backup"
$jobs = get-vbrjob
foreach ($job in $jobs)
{
$jobname = $job.name

#This is to display the Job Names in the console for troubleshooting
write-output $jobname

#Runs the exe file with the necessary parameters 
.\veeam.backup.validator.exe /backup:"$jobname" /format:html /report:"$VeeamOutputFile"

#Set the location of the output file
$JobFile = $VeeamOutputFile

#Sends the output files to a recipient
send-mailmessage -from "<$SenderAddr>" -to "<$DestinationAddr>" -subject "Veeam Validation Report for $jobname" -body "Report Attached." -Attachments "$JobFile" -priority High -dno onSuccess, onFailure -smtpServer $SMTPServer
}
Technical Architect
Veeam Certified Architect
Veeam Vanguard
  • Personal Technical Blog - www.veducate.co.uk
  • Twitter - @saintdle
saintdle
Veeam Vanguard
Posts: 103
Liked: 17 times
Joined: Aug 05, 2014 1:13 pm
Full Name: Dean lewis
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by saintdle »

I missed off the quotes for the variables, the below should be working now

Code: Select all

#Set the Output file location
$VeeamOutputFile = "c:\Powershell\VeeamValidation-$jobname-$date.html"

#Set the sending email address and destination address
$SenderAddr = "Veeam@Company.co.uk"
$DestinationAddr = "User@Company.co.uk"

#Set the email server
$SMTPServer = "mail.company.co.uk"

######################################
#Do not edit anything below this line#
######################################

Add-PSSnapIn VeeamPSSNapin
$date = (Get-Date).AddDays(-1).ToString('dd-MM-yyyy')
set-location "C:\Program Files\Veeam\Backup and Replication\Backup"
$jobs = get-vbrjob
foreach ($job in $jobs)
{
$jobname = $job.name

#This is to display the Job Names in the console for troubleshooting
write-output $jobname

#Runs the exe file with the necessary parameters 
.\veeam.backup.validator.exe /backup:"$jobname" /format:html /report:"$VeeamOutputFile"

#Set the location of the output file
$JobFile = $VeeamOutputFile

#Sends the output files to a recipient
send-mailmessage -from "<$SenderAddr>" -to "<$DestinationAddr>" -subject "Veeam Validation Report for $jobname" -body "Report Attached." -Attachments "$JobFile" -priority High -dno onSuccess, onFailure -smtpServer $SMTPServer
}
Technical Architect
Veeam Certified Architect
Veeam Vanguard
  • Personal Technical Blog - www.veducate.co.uk
  • Twitter - @saintdle
mobin.qasim
Enthusiast
Posts: 58
Liked: 1 time
Joined: Jun 19, 2013 7:23 pm
Full Name: Mobin Qasim
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mobin.qasim »

Hi Guys,

I'm using Veeam v7.0.0.871.

Has anyone made this script working? I tried to run it but I'm getting following errors.

Set-Location : Cannot find path 'C:\Program Files\Veeam\Backup and Replication\Backup' because it does not exist.
At C:\backup\veeamvalidation.ps1:17 char:13
+ set-location <<<< "C:\Program Files\Veeam\Backup and Replication\Backup"
+ CategoryInfo : ObjectNotFound: (C:\Program File...lication\Backup:String) [Set-Location], ItemNotFoundE
xception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Backup Job Test
The term '.\veeam.backup.validator.exe' is not recognized as the name of a cmdlet, function, script file, or operable p
rogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\backup\veeamvalidation.ps1:27 char:29
+ .\veeam.backup.validator.exe <<<< /backup:"$jobname" /format:html /report:"$VeeamOutputFile"
+ CategoryInfo : ObjectNotFound: (.\veeam.backup.validator.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Send-MailMessage : Could not find file 'C:\Powershell\VeeamValidation--.html'.
At C:\backup\veeamvalidation.ps1:33 char:17
+ send-mailmessage <<<< -from "<$SenderAddr>" -to "<$DestinationAddr>" -subject "Veeam Validation Report for $jobname"
-body "Report Attached." -Attachments "$JobFile" -priority High -dno onSuccess, onFailure -smtpServer $SMTPServer
+ CategoryInfo : NotSpecified: (:) [Send-MailMessage], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage


I can't see path C:\Program Files\Veeam\Backup and Replication\Backup and I tried to change it to C:\ProgramData\Veeam\Backup but still no luck.

Can someone please guide me how to fix this? Veeam.Backup.Validation run fine manually but I want to add Post Script after each backup job finishes. Please help.

Regards,

Mobin
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

What's the exact path to your repository?
mobin.qasim
Enthusiast
Posts: 58
Liked: 1 time
Joined: Jun 19, 2013 7:23 pm
Full Name: Mobin Qasim
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mobin.qasim »

My repository is configured on a different server
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

Sorry for confusion, the right question should have been - in which directory VB&R is located?

The line below suggests clearly that software is installed in non-default directory, and the script fails due to that.
Cannot find path 'C:\Program Files\Veeam\Backup and Replication\Backup' because it does not exist.
Thanks.
mobin.qasim
Enthusiast
Posts: 58
Liked: 1 time
Joined: Jun 19, 2013 7:23 pm
Full Name: Mobin Qasim
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mobin.qasim »

VB&R is installed on the following location :

C:\Program Files\Veeam\Backup and Replication

I can't find the Backup folder mentioned in the script as "'C:\Program Files\Veeam\Backup and Replication\Backup". If script is looking for the backup job names then those are located in "C:\ProgramData\Veeam\Backup"

Regards
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

It looks for the directory where validator tool is present. Typically, it's C:\Program Files\Veeam\Backup and Replication\Backup.

Can you just search the C:\ disk and see where veeam.backup.validator.exe is located? This directory should be then specified in set-location commandlet.

Thanks.
mobin.qasim
Enthusiast
Posts: 58
Liked: 1 time
Joined: Jun 19, 2013 7:23 pm
Full Name: Mobin Qasim
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mobin.qasim »

veeam.backup.validator.exe is located on this location C:\Program Files\Veeam\Backup and Replication and I've already tried to change the set-location path to C:\Program Files\Veeam\Backup and Replication but I was getting the following error:

Invalid command line: unknown argument "format:html". Use /? for more information.
Send-MailMessage : Could not find file 'C:\Powershell\VeeamValidation--.html'.
At C:\Users\mobin.qasim\Desktop\veeam.ps1:33 char:17
+ send-mailmessage <<<< -from "<$SenderAddr>" -to "<$DestinationAddr>" -subject "Veeam Validation Report for $jobname"
-body "Report Attached." -Attachments "$JobFile" -priority High -dno onSuccess, onFailure -smtpServer $SMTPServer
+ CategoryInfo : NotSpecified: (:) [Send-MailMessage], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.SendMailMessage


Any further help please

Thanks
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

Which product version are you using? If you execute the tool via either command line or PowerShell and use /? to open a help section, will there be a mention of usage /format:html parameter?
mobin.qasim
Enthusiast
Posts: 58
Liked: 1 time
Joined: Jun 19, 2013 7:23 pm
Full Name: Mobin Qasim
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mobin.qasim »

I'm using Veeam v7.0 and following scripts is working fine for me per Backup Job. But I was more interested in the above script due to email notification.
$NameOfBackup = "'Backup Job Servers'"
$filepath= 'C:\Validation Logs\'+$NameOfBackup+'_'+("{0:yyyy-MM-dd_HH.mm.ss}" -f (get-date))+'.txt'
$tool='"C:\Program Files\Veeam\Backup and Replication\Veeam.Backup.Validator.exe"'
$Parameter = "/backup:$NameOfBackup"
Invoke-Expression "& $tool $Parameter"
New-Item -Path $filepath -ItemType file
Move-Item C:\ProgramData\Veeam\Backup\Util.VmBackupValidate.log $filepath -force
p.s there is nothing related to usage of /format:html parameter when I run /?

Cheers
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

I cannot check that at the moment. But it might happen that /format:html parameter has been to backup verificator tool in the newer product version (which is sort of confirmed by the fact that /? doesn't return anything regarding that parameter).

Thus, I suggest you to upgrade to version 8 and see whether it solves the problem.

Thanks.
mobin.qasim
Enthusiast
Posts: 58
Liked: 1 time
Joined: Jun 19, 2013 7:23 pm
Full Name: Mobin Qasim
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mobin.qasim »

Hi Thanks for the reply. I'll upgrade to version 8 and see how it works.
I've one question: I'm using following script as Veeam post job activity on a couple of jobs.
$NameOfBackup = "'Backup Job Servers'"
$filepath= 'C:\Validation Logs\'+$NameOfBackup+'_'+("{0:yyyy-MM-dd_HH.mm.ss}" -f (get-date))+'.txt'
$tool='"C:\Program Files\Veeam\Backup and Replication\Veeam.Backup.Validator.exe"'
$Parameter = "/backup:$NameOfBackup"
Invoke-Expression "& $tool $Parameter"
New-Item -Path $filepath -ItemType file
Move-Item C:\ProgramData\Veeam\Backup\Util.VmBackupValidate.log $filepath -force
When logs are created under C:\Validation Logs , it has previous jobs information in the log files as well, and sometimes even logs have other jobs validation details in there. Following string Move-Item C:\ProgramData\Veeam\Backup\Util.VmBackupValidate.log $filepath -force is not moving the correct Util.VmBackupValidate.log when validation complete.

Could you please help me I can have the correct validation logs details.

Regards,

Mobin
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

What path you're specifying as $filepath variable?
mobin.qasim
Enthusiast
Posts: 58
Liked: 1 time
Joined: Jun 19, 2013 7:23 pm
Full Name: Mobin Qasim
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mobin.qasim »

Hi,

I'm specifying $filepath as mentioned:

" $filepath= 'C:\Validation Logs\'+$NameOfBackup+'_'+("{0:yyyy-MM-dd_HH.mm.ss}" -f (get-date))+'.txt'"

I ended up ignoring all other details of other backup jobs and taking only the results at the bottom of the log file which shows successful or failed for the correct Backup Job.


Cheers
mcsmithSOP
Enthusiast
Posts: 42
Liked: 2 times
Joined: May 31, 2015 3:26 pm
Full Name: Jason
Location: Regina, SK, CAD
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by mcsmithSOP »

This tool is failing on all the VMs in the job due to "VM is unavailable".

Veeam B&R is installed on one server (veeam), and the repository is stored on a different server (vmbr-pri). I'm assuming that the issue is because the Storage Path in the report is "F:\Backups\Debian\Debian2016-01-06T223135.vib".

That is the correct path on the repo (vmbr-pri) but obviously does not exist on the B&R server (veeam) where the tool is installed.

I ran a SureBackup on a couple of the VMs yesterday, so I know that they work and are valid (or at least, they were yesterday afternoon).

I'd like to run this validator tool more frequently that the SureBackup jobs, since I don't want to run SureBackup jobs during week days, so help getting the path correct would be appreciated.

Edit to add: Running Veeam 8.0 Update 3. B&R is on WS2012R2 and the repo is on WS2008R2
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

I'm assuming that the issue is because the Storage Path in the report is "F:\Backups\Debian\Debian2016-01-06T223135.vib".
Correct. You might share the given location, and it to a backup server as a mapped drive, so that, validator tool has access to backup files.

Though, be aware that validator is not a replacement of Surebackup, since мalidator tests whether the backup file itself was modified/corrupted after being created, while SureBackup ensures that VMs in it are actually recoverable.

Thanks.
jhellermann
Influencer
Posts: 24
Liked: 4 times
Joined: May 10, 2016 12:05 pm
Full Name: JEllermann
Contact:

[MERGED] Powershell script for validating backup jobs (teste

Post by jhellermann »

With this Powershell Script you can check a backup job.
Simply enter your job-name, mailserver, email, path and save it.
Test it with right mouse button, execute with powershell.
The job starts and checks the last backups of all VMs in the job.
Set Task in Task Scheduler, done.
Instead of /: backup you can also use /:file, but you must then change the parameters as
documented for the veeam.backup.validator.exe


Code: Select all


###########################################################################################################

$EMAILFROM = "veeamserver@blimblam.de"
$EMAILTO = "ToniMaroni@blimblam.de"
#$EMAILBCC = ""
#$EMAILCC = ""
$EMAILSUBJECT = "Backup-Validation"
$EMAILATTACHMENT = "D:\VeeamPowerShell\PShellLogs\BackupJob-Windows-Client.html"
$SmtpServer = "xxx.xxx.xxx.xxx"


###########################################################################################################

Add-PSSnapIn VeeamPSSNapin
set-location "C:\Program Files\Veeam\Backup and Replication\Backup"



.\Veeam.Backup.Validator.exe /backup:"BackupJob-Windows-Client" /format:html /report:"D:\VeeamPowerShell\PShellLogs\BackupJob-Windows-Client.html"

##################################################################################################################################################################################

$MESSAGE = new-object System.Net.Mail.MailMessage
$MESSAGE.From = $EMAILFROM
$MESSAGE.To.Add($EMAILTO)
#$MESSAGE.CC.Add($EMAILCC)
#$MESSAGE.Bcc.Add($EMAILBCC)
$MESSAGE.IsBodyHtml = $FALSE
$MESSAGE.Subject = $EMAILSUBJECT
$attach = new-object Net.Mail.Attachment($EMAILATTACHMENT)
$MESSAGE.Attachments.Add($attach)
$MESSAGE.body = $EMAILBODY
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.EnableSsl = $FALSE
#$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“username“, “password“);
$SMTPClient.Send($MESSAGE)

###########################################################################################


JEllermann
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

Thanks for sharing the script. I'd probably assign location to a variable and let user define it, as installation directory might vary:

Code: Select all

$Location = "C:\Program Files\Veeam\Backup and Replication\Backup" # Change it, if the product is installed in non-default directory
################################################################################################################
Add-PSSnapIn VeeamPSSNapin
set-location $Location
Thanks.
jhellermann
Influencer
Posts: 24
Liked: 4 times
Joined: May 10, 2016 12:05 pm
Full Name: JEllermann
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by jhellermann »

Good idea
JEllermann
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by veremin »

You're welcome. Glad to hear that you've found my input useful.

Feel free to reach us, should other help be needed.
Tecbil
Enthusiast
Posts: 31
Liked: 3 times
Joined: Apr 08, 2016 6:20 am
Contact:

Re: [MERGED] Powershell script for validating backup jobs (teste

Post by Tecbil » 1 person likes this post

jhellermann wrote: Jan 19, 2017 12:01 pm With this Powershell Script you can check a backup job.
Simply enter your job-name, mailserver, email, path and save it.
Test it with right mouse button, execute with powershell.
The job starts and checks the last backups of all VMs in the job.
Set Task in Task Scheduler, done.
Instead of /: backup you can also use /:file, but you must then change the parameters as
documented for the veeam.backup.validator.exe


Code: Select all


###########################################################################################################

$EMAILFROM = "veeamserver@blimblam.de"
$EMAILTO = "ToniMaroni@blimblam.de"
#$EMAILBCC = ""
#$EMAILCC = ""
$EMAILSUBJECT = "Backup-Validation"
$EMAILATTACHMENT = "D:\VeeamPowerShell\PShellLogs\BackupJob-Windows-Client.html"
$SmtpServer = "xxx.xxx.xxx.xxx"


###########################################################################################################

Add-PSSnapIn VeeamPSSNapin
set-location "C:\Program Files\Veeam\Backup and Replication\Backup"



.\Veeam.Backup.Validator.exe /backup:"BackupJob-Windows-Client" /format:html /report:"D:\VeeamPowerShell\PShellLogs\BackupJob-Windows-Client.html"

##################################################################################################################################################################################

$MESSAGE = new-object System.Net.Mail.MailMessage
$MESSAGE.From = $EMAILFROM
$MESSAGE.To.Add($EMAILTO)
#$MESSAGE.CC.Add($EMAILCC)
#$MESSAGE.Bcc.Add($EMAILBCC)
$MESSAGE.IsBodyHtml = $FALSE
$MESSAGE.Subject = $EMAILSUBJECT
$attach = new-object Net.Mail.Attachment($EMAILATTACHMENT)
$MESSAGE.Attachments.Add($attach)
$MESSAGE.body = $EMAILBODY
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.EnableSsl = $FALSE
#$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“username“, “password“);
$SMTPClient.Send($MESSAGE)

###########################################################################################


Thanks a lot dude. Exactly what I was looking for and it works like a charm.
jhellermann
Influencer
Posts: 24
Liked: 4 times
Joined: May 10, 2016 12:05 pm
Full Name: JEllermann
Contact:

Re: Backup Validator - PS Script to run against all backups

Post by jhellermann »

Nice to hear
JEllermann
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests