PowerShell script exchange
Post Reply
ronjack
Lurker
Posts: 2
Liked: never
Joined: Oct 31, 2009 2:47 am
Full Name: Ron Jack
Contact:

Powershell script returns control before backup complete

Post by ronjack »

I have an issue with Veeam 5 powershell scripts. We run Backup Exec to copy the Veeam backup files to tape and are using BE policies to maintain a GFS tape rotation. As part of the policy jobs a precommand is run to launch a powershell script.

The BE batch file is as follows

powershell.exe c:\scripts\runjob3.ps1

The power shell script is as follows

Code: Select all

Add-PSSnapin VeeamPSSnapIn
Get-VBRJob | where {$_.name -eq "POMS"} | Start-VBRJob
All was well in Veeam version 4 with the nice and straight forward powershell commands but have had to resort to the above to get the powershell script to run.

The problem however is that poweshell passes back control to the batch file before the Veeam job is complete, this allows the copy to tape to start and then Veeam detects a file in use conflict and fails.

Does anyone know how to get around this?
Alexey D.

Re: Powershell script returns control before backup complete

Post by Alexey D. »

Hello Ron,

This is strange, because the behaviour you've described shows up only when calling the function with "--runasync" key.
And I don't see this key in your script. Please contact our support team and provide all the logs. Thanks!
abartok2283
Novice
Posts: 3
Liked: never
Joined: Feb 28, 2010 3:09 pm
Full Name: Alexander Bartok
Contact:

Re: Powershell script returns control before backup complete

Post by abartok2283 »

I can confirm this. I'm starting backup jobs in series with the same command and they all get started up at the same time :evil:
schaffeb
Enthusiast
Posts: 50
Liked: never
Joined: Apr 14, 2009 10:44 pm
Full Name: Ben S
Contact:

Re: Powershell script returns control before backup complete

Post by schaffeb »

There are known issues with Start-VBRJob:

http://www.veeam.com/forums/viewtopic.p ... 08&start=0

There's a solution using the async switch in that thread, I took that and made my own variation.. Here's a truncated version, I put a fair amount of logging in normally:

Please use at your own risk, I cannot assume any liability if this code messes something up in your environment.

Code: Select all

$backup_job = get-vbrjob | where-object {$_.name -like "xxxxxxxx"}
foreach ($job in $backup_job)
            {
            start-vbrjob $job -runasync
                        while ($job.isstopped() -ne "true")
                                    {
                                    Start-Sleep -s 10                                 
                                    }
            }
Hopefully this function will get fixed in the 5.0.1 release.
ronjack
Lurker
Posts: 2
Liked: never
Joined: Oct 31, 2009 2:47 am
Full Name: Ron Jack
Contact:

Re: Powershell script returns control before backup complete

Post by ronjack »

Thanks all for you input, I rewrote the scripts as follows (found this in another post) and will test this tonight. The test job ran ok with this script.

Code: Select all

Add-PSSnapin VeeamPSSnapIn
$job = Get-VBRJob | where {$_.name -eq "ProjectBackup"};
$check = Start-VBRJob $job -runasync;
$job_id= $check.id;
While ($check.State -ne "Stopped")
{
$check=Get-VBRBackupSession | where {$_.id -eq $job_id };
Start-Sleep -s 10;
}
$result=Get-VBRBackupSession | where {$_.id -eq $job_id };
echo $result;
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest