PowerShell script exchange
Post Reply
saintdle
Veeam Vanguard
Posts: 81
Liked: 15 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 » Jan 14, 2015 11:33 pm

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
Various other stuff
Personal Technical Blog - www.educationalcentre.co.uk

saintdle
Veeam Vanguard
Posts: 81
Liked: 15 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 » Jan 15, 2015 6:59 am

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
Various other stuff
Personal Technical Blog - www.educationalcentre.co.uk

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 » Jun 02, 2015 9:04 am

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: 16901
Liked: 1438 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 » Jun 02, 2015 10:51 am

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 » Jun 02, 2015 1:54 pm

My repository is configured on a different server

veremin
Product Manager
Posts: 16901
Liked: 1438 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 » Jun 02, 2015 2:05 pm

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 » Jun 02, 2015 2:13 pm

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: 16901
Liked: 1438 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 » Jun 02, 2015 2:22 pm

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 » Jun 02, 2015 2:48 pm

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: 16901
Liked: 1438 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 » Jun 03, 2015 9:16 am

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 » Jun 05, 2015 8:04 am

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: 16901
Liked: 1438 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 » Jun 05, 2015 5:46 pm

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 » Jun 11, 2015 11:25 am

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: 16901
Liked: 1438 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 » Jun 18, 2015 9:14 am

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 » Sep 21, 2015 1:22 pm

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 » Jan 07, 2016 5:31 pm

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: 16901
Liked: 1438 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 » Jan 08, 2016 12:52 pm

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
Novice
Posts: 9
Liked: 3 times
Joined: May 10, 2016 12:05 pm
Full Name: JEllermann
Contact:

[MERGED] Powershell script for validating backup jobs (teste

Post by jhellermann » 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)

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


JEllermann

veremin
Product Manager
Posts: 16901
Liked: 1438 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 » Jan 19, 2017 12:51 pm

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
Novice
Posts: 9
Liked: 3 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 » Feb 14, 2017 1:01 pm

Good idea
JEllermann

veremin
Product Manager
Posts: 16901
Liked: 1438 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 » Feb 18, 2017 10:57 am

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

Feel free to reach us, should other help be needed.

Tecbil
Influencer
Posts: 19
Liked: 2 times
Joined: Apr 08, 2016 6:20 am
Full Name: Fabio Di Taranto
Contact:

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

Post by Tecbil » Feb 04, 2019 7:46 am 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
Novice
Posts: 9
Liked: 3 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 » Feb 18, 2019 8:52 am

Nice to hear
JEllermann

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests