PowerShell script exchange
saintdle
Veeam Vanguard
Posts: 79
Liked: 14 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: 79
Liked: 14 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

v.eremin
Product Manager
Posts: 16226
Liked: 1323 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 v.eremin » 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

v.eremin
Product Manager
Posts: 16226
Liked: 1323 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 v.eremin » 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

v.eremin
Product Manager
Posts: 16226
Liked: 1323 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 v.eremin » 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

v.eremin
Product Manager
Posts: 16226
Liked: 1323 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 v.eremin » 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

v.eremin
Product Manager
Posts: 16226
Liked: 1323 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 v.eremin » 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

v.eremin
Product Manager
Posts: 16226
Liked: 1323 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 v.eremin » 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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests