PowerShell script exchange
Post Reply
MMiller69
Novice
Posts: 3
Liked: 1 time
Joined: May 19, 2014 9:12 am
Full Name: Mark Miller
Contact:

Pre job script seems to clear "Advanced" options on Job

Post by MMiller69 »

Hi

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

PTide
Product Manager
Posts: 6431
Liked: 729 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Pre job script seems to clear "Advanced" options on Job

Post by PTide »

Hi,

Such behaviour is unexpected. As reference says:
The parameters that you omit will remain unchanged.
Please open the case with support.

Thank you.
MMiller69
Novice
Posts: 3
Liked: 1 time
Joined: May 19, 2014 9:12 am
Full Name: Mark Miller
Contact:

Re: Pre job script seems to clear "Advanced" options on Job

Post by MMiller69 »

Hi

Exactly as I thought, which is why I opened a case with support, although it took a little bit of convincing for them to open one :)
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Pre job script seems to clear "Advanced" options on Job

Post by veremin »

I've just tested that, and it seems that the said commandlet resets advanced settings, indeed. Looks like a bug.

I've passed this information to the dev.team. So, thank you for the feedback; much appreciated.

Thanks.
MMiller69
Novice
Posts: 3
Liked: 1 time
Joined: May 19, 2014 9:12 am
Full Name: Mark Miller
Contact:

Re: Pre job script seems to clear "Advanced" options on Job

Post by MMiller69 » 1 person likes this post

Hi

Just had it confirmed now from support team & QA department that's this is indeed a bug, and that it will be fixed in v9.

However obviously this mean that at this time those of us on v8 will not be able to use the cmdlet in a pre-job script without messing up the advanced options. Hoping that some workaround can be produced.
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Pre job script seems to clear "Advanced" options on Job

Post by veremin »

As those advanced settings are not currently configurable via PowerShell, I don't think a workaround can be created that easily. Thanks.
winnt
Enthusiast
Posts: 29
Liked: 20 times
Joined: Apr 03, 2015 9:19 pm
Full Name: Jason D
Contact:

Re: Pre job script seems to clear "Advanced" options on Job

Post by winnt »

I have the same issue. Has anyone found a workaround? Thanks.
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Pre job script seems to clear "Advanced" options on Job

Post by veremin »

I've just checked and the said bug seems to be addressed in version 9. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests