Powershell script returns control before backup complete

PowerShell script exchange

Powershell script returns control before backup complete

Veeam Logoby ronjack » Wed Dec 01, 2010 7:46 am

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?
ronjack
Lurker
 
Posts: 2
Liked: never
Joined: Sat Oct 31, 2009 2:47 am
Full Name: Ron Jack

Re: Powershell script returns control before backup complete

Veeam Logoby Alexey D. » Wed Dec 01, 2010 11:08 am

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!
Alexey D.
 

Re: Powershell script returns control before backup complete

Veeam Logoby abartok2283 » Wed Dec 01, 2010 4:09 pm

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:
abartok2283
Novice
 
Posts: 3
Liked: never
Joined: Sun Feb 28, 2010 3:09 pm
Full Name: Alexander Bartok

Re: Powershell script returns control before backup complete

Veeam Logoby schaffeb » Wed Dec 01, 2010 6:43 pm

There are known issues with Start-VBRJob:

viewtopic.php?f=2&t=5508&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.
schaffeb
Enthusiast
 
Posts: 50
Liked: never
Joined: Tue Apr 14, 2009 10:44 pm
Full Name: Ben S

Re: Powershell script returns control before backup complete

Veeam Logoby ronjack » Thu Dec 02, 2010 1:45 am

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;
ronjack
Lurker
 
Posts: 2
Liked: never
Joined: Sat Oct 31, 2009 2:47 am
Full Name: Ron Jack


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests