PowerShell script veeam backup files to tape

PowerShell script exchange

PowerShell script veeam backup files to tape

Veeam Logoby hagepat » Mon Oct 01, 2012 12:01 pm

Hi all,

I have a problem with my powershell script writing veeam backup files to tape software.
If the job completes with status "success" then scripts starts and writes to tape. But if the job status is "warning" then nothing happens.
Can somebody helps me with that because I no powershell expert.

Here's my script:

# Remoting must be enabled on the BackupExec Server
# And user must have access to complete task on Veeam and BE

if ((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null) {
Add-PsSnapin VeeamPSSnapIn
}

$veeamJobName = "test"
$backupExecJob = "veeam2tape"
$backupExecSvr = "MGMT01"
$backupExecPath = "C:\Program Files\Symantec\Backup Exec"

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -eq "Success") {
$latestOib = Get-VBRBackup | ?{$_.JobName -eq $veeamJobName} | Get-VBRRestorePoint | Sort CreationTime -Descending | Select -First 1
$latestOib
$storage = $latestOib.GetStorage()
$storage.FilePath

$file = Get-Item $storage.FilePath
if ($file.Attributes -band ([System.IO.FileAttributes]::Archive)) {
Invoke-Command -ComputerName $backupExecSvr -ScriptBlock {
param (
[PSObject]$storage,
[PsObject]$file,
[String]$backupExecJob,
[String]$backupExecPath
)

& "$backupExecPath\bemcmd.exe" -o2 -j:$backupExecJob -s:$storage.FilePath -m Tapes-Weekdays -r -w
$file.Attributes = 'Archive'
} -ArgumentList $storage, $file, $backupExecJob, $backupExecPath
}
}

Kind regards,

Patrick Hagen
hagepat
Veeam ProPartner
 
Posts: 15
Liked: never
Joined: Tue Aug 31, 2010 1:17 pm

Re: PowerShell script veeam backup files to tape

Veeam Logoby pizzim13 » Fri Oct 12, 2012 1:50 am

Pat,
Your issue is with line
Code: Select all
if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -eq "Success") {

This line is only true when GetLastResult() equals "Success". It should look like
Code: Select all
if (Get-VBRJob -name $veeamJobName | Where-Object {$_.getlastresult() -eq "Success" -or $_.getlastresult() -eq "Warning"})
pizzim13
Enthusiast
 
Posts: 86
Liked: 6 times
Joined: Thu Apr 21, 2011 7:37 pm

Re: PowerShell script veeam backup files to tape

Veeam Logoby rhnb » Tue Oct 16, 2012 10:40 am

Or you could use...

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -ne "Failed") {
...
rhnb
Enthusiast
 
Posts: 81
Liked: 2 times
Joined: Wed Jan 27, 2010 2:25 pm
Full Name: Allan Nelson

Re: PowerShell script veeam backup files to tape

Veeam Logoby pizzim13 » Tue Oct 16, 2012 1:22 pm

rhnb wrote:Or you could use...

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -ne "Failed") {
...


This will retrieve jobs that are currently running, which have a .getlastresult() of "None"
pizzim13
Enthusiast
 
Posts: 86
Liked: 6 times
Joined: Thu Apr 21, 2011 7:37 pm

Re: PowerShell script veeam backup files to tape

Veeam Logoby rhnb » Thu Oct 18, 2012 1:23 pm

But only for the job matching $veeamJobName, and as it's a post job script running for that job, ie the jobs finished, it'll retrieve the results that haven't failed won't it?
It seems to be working fine for me and I've been using it for several months.

I take your point that if it's NOT running as a post-job script ie running independently then yes, it would return a 'currently running' result.
rhnb
Enthusiast
 
Posts: 81
Liked: 2 times
Joined: Wed Jan 27, 2010 2:25 pm
Full Name: Allan Nelson


Return to PowerShell



Who is online

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