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
-
- Veeam ProPartner
- Posts: 15
- Liked: never
- Joined: Aug 31, 2010 1:17 pm
- Contact:
-
- Enthusiast
- Posts: 94
- Liked: 6 times
- Joined: Apr 21, 2011 7:37 pm
- Contact:
Re: PowerShell script veeam backup files to tape
Pat,
Your issue is with line
This line is only true when GetLastResult() equals "Success". It should look like
Your issue is with line
Code: Select all
if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -eq "Success") {
Code: Select all
if (Get-VBRJob -name $veeamJobName | Where-Object {$_.getlastresult() -eq "Success" -or $_.getlastresult() -eq "Warning"})
-
- Enthusiast
- Posts: 81
- Liked: 2 times
- Joined: Jan 27, 2010 2:25 pm
- Full Name: Allan Nelson
- Contact:
Re: PowerShell script veeam backup files to tape
Or you could use...
if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -ne "Failed") {
...
if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -ne "Failed") {
...
-
- Enthusiast
- Posts: 94
- Liked: 6 times
- Joined: Apr 21, 2011 7:37 pm
- Contact:
Re: PowerShell script veeam backup files to tape
This will retrieve jobs that are currently running, which have a .getlastresult() of "None"rhnb wrote:Or you could use...
if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -ne "Failed") {
...
-
- Enthusiast
- Posts: 81
- Liked: 2 times
- Joined: Jan 27, 2010 2:25 pm
- Full Name: Allan Nelson
- Contact:
Re: PowerShell script veeam backup files to tape
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.
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.
Who is online
Users browsing this forum: No registered users and 8 guests