In order maintain the backup policies for my company I have had to create pre and post job Powershell scripts for our Veeam jobs.
The pre job script scans the repository for the latest VBK & VBM files, adds them to an Object then dumps that object into the FileBackupToTape jobs. This works great and the backups run fine, however in the process of modifying the job file selections the script somehow also seems to clear out a couple of advanced options, namely post job notifications and Job scripts. Obviously this means that the we don't receive the post job completion mails and the post job scripts don't run.
I do have an active case for this, as I believe it to be a bug, but I thought I would post the script here and see what the community here thought. (obfuscated data in a couple of variables)
Code: Select all
<#
Powershell job seelction script for Veeam Backup
Created by Mark Miller
30/6/2015
#>
add-pssnapin VeeamPSSnapin
$NewFileSelection = @()
$CopyJobs = @()
$JobNamepart = @()
$fileSelection = @()
$Size = 0
$dir = "\\<servername>\d$\Backups" # One script per respoitory
$path = "d:\Backups"
$Server = Get-VBRServer | Where {$_.Name -eq "<servername>"} # Gets the servername
$VBRJob = Get-VBRtapeJob | ? {$_.name -eq "Monthly File Backup Repository 1"} # Select target Backup to Tap job
$mailTo = "<destination mail address>"
$mailFrom = "<Source mail address>"
$smtpServer = "<mail server>"
$Subject = "Monthly Veeam Backup to Tape of Repository 1"
$filetypes = @("*.vbk","*.vbm")
$jobFolders = Get-ChildItem -Recurse -path $dir | ?{ $_.PSIsContainer }
foreach ($f in $jobFolders){
foreach ($ft in $filetypes){
$latestVBK = Get-ChildItem -path $f.FullName -filter $ft | Sort-Object LastAccessTime -Descending | select-object -first 1
if ($latestVBK -ne $null){
$fileSelection += ($latestVBK.FullName).Replace($dir,$path)
$size += $latestVBK.Length
}
}
}
foreach ($fs in $fileSelection){
$newfileselection += New-VBRFiletoTapeObject -Server $server -Path $fs #Build file selection list
if ($fs -like "*copy*"){
$JobNamepart += $fs.Split("\")[2]
}
}
$JobNamepart = $JobNamepart | sort -Unique
$s = "{0:N2}" -f ($size / 1tb)
$data = $NewFileSelection.path + "Backup Size (TB): $s" | fl | Out-String
Send-MailMessage -From $mailFrom -To $mailTo -Subject "Monthly File Backup Repository 1 Script" -SmtpServer $smtpServer $Data
Set-VBRFileToTapeJob -Job $VBRJob.ID -Object $NewFileSelection # Writes selection list to target job
Disable-VBRJob -Job $JobNamepart