PowerShell script exchange
Post Reply
namiko78
Expert
Posts: 117
Liked: 4 times
Joined: Mar 03, 2011 1:49 pm
Full Name: Steven Stirling
Contact:

Need script to check if a tape job is running please

Post by namiko78 »

I'd like to run a script on my main backup jobs, that check to see if a tape job is running, and if so, wait for that to complete. Does anyone know of any that already exists out there?

Thank you!
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Need script to check if a tape job is running please

Post by PTide »

Hi,

Please check this thread. You'll need to replace Get-VBRJob with Get-VBRTapeJob and $Job.GetLastState() -eq "Working" with $J.LastState -eq "Working"

Thank you.
veremin
Product Manager
Posts: 20411
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Need script to check if a tape job is running please

Post by veremin »

I didn't have a time to test it, but I think the following script should work fine:

Code: Select all

asnp VeeamPSSnapin
$TapeJob = Get-VBRTapeJob -name "Name of Tape Job"
if ($TapeJob.LastState -ne "Working"){exit}
else
{ 
    do
    {   
        Start-sleep -s 300 #5 minute waiting interval
        $TapeJob = Get-VBRTapeJob -name "Name of Tape Job"
    }
}while ($TapeJob.LastState -ne "Working")
Thanks.
namiko78
Expert
Posts: 117
Liked: 4 times
Joined: Mar 03, 2011 1:49 pm
Full Name: Steven Stirling
Contact:

Re: Need script to check if a tape job is running please

Post by namiko78 »

Thanks. I managed to manually install the powershell plugin, launched it from the top left menu, but there seems to be no get-vbrtapejob command.... do i have an old version? i'm running 8.0.0.2021 but i installed the powershell plugiun from the origional version before the patch.

Just noticed that when i launch the powershell from the left menu, i get a "no snapins have been registered for windows poershell version 4"
veremin
Product Manager
Posts: 20411
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Need script to check if a tape job is running please

Post by veremin »

What if you try to start a PowerShell outside of backup console and check whether VeeamPSSnapin has been registered successfully, using "Get-PSSnapin" (to be sure run PS as administrator)?
namiko78
Expert
Posts: 117
Liked: 4 times
Joined: Mar 03, 2011 1:49 pm
Full Name: Steven Stirling
Contact:

Re: Need script to check if a tape job is running please

Post by namiko78 »

get-pssnapin just gives me the 1, and it's the core one. nothing else.
veremin
Product Manager
Posts: 20411
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Need script to check if a tape job is running please

Post by veremin »

Can you try to re-install snap-in either manually, using Install-VeeamToolkit.ps1 script in "C:\Program Files\Veeam\Backup and Replication", or automatically through general setup wizard and see whether it helps?
namiko78
Expert
Posts: 117
Liked: 4 times
Joined: Mar 03, 2011 1:49 pm
Full Name: Steven Stirling
Contact:

Re: Need script to check if a tape job is running please

Post by namiko78 »

Tried both, didn't work :( The wizard didn't actually get very far because i have jobs running and it told me to disable them.
veremin
Product Manager
Posts: 20411
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Need script to check if a tape job is running please

Post by veremin »

Let's wait till there is a time window without running jobs and re-install snap-in at that time. Thanks.
WinstonWolf
Veteran
Posts: 284
Liked: 11 times
Joined: Jan 06, 2011 8:33 am
Contact:

[MERGED] Let the Backup Job wait on an running Tape Job

Post by WinstonWolf »

Hello ,

I need an Script who lets the Backup Job Waits when an Tape Job for this Files is running .

I have at the End of the Month an "big" Tape Job who Backups 30 Hours from Monday Morning at 03.00 . But on Monday Evening at 7 PM the Backup to Disk Job starts and when Merging begins the Backup To Disk Job Ends the Tape Job .

What i want is an Script who lets the backup to Disk Job waits till the "big" Backup to Tape Job is finished . It is ok when on Monday Evening no Backup to Disk Job runs .

Thanks
Michael
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Need script to check if a tape job is running please

Post by PTide »

Please check the script Vladimir has provided and feel free to request an assistance.

Thank you.
WinstonWolf
Veteran
Posts: 284
Liked: 11 times
Joined: Jan 06, 2011 8:33 am
Contact:

Re: Need script to check if a tape job is running please

Post by WinstonWolf »

Hello again ,

Im totally new on Veeam Scripting . What i need for Scripting from Veeam Side ?
How can i insert an Script in Veeam ?

Vladimir , How can Look the Script when i want to prevent an Backup to Disk Job to start when an Tape Job runs at this Time ?

Thanks for Help .

Michael
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Need script to check if a tape job is running please

Post by PTide »

What i need for Scripting from Veeam Side ?
How can i insert an Script in Veeam ?
You need to specify .ps1 file containing the script in Advanced settings of your job so that the script starts before the job.
How can Look the Script when i want to prevent an Backup to Disk Job to start when an Tape Job runs at this Time ?
This part of the script should prevent backup job from starting until tape job is finished:

Code: Select all

if ($TapeJob.LastState -ne "Working"){exit}
else
{
    do
    {   
        Start-sleep -s 300 #5 minute waiting interval
        $TapeJob = Get-VBRTapeJob -name "Name of Tape Job"
    }
}while ($TapeJob.LastState -ne "Working")
Thanks
veremin
Product Manager
Posts: 20411
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Need script to check if a tape job is running please

Post by veremin »

And don't forget to add our PS snap-in in the beginning of the script, so that PowerShell has access to VB&R related commandlets.

Code: Select all

Asnp VeeamPSSnapin
Thanks.
WinstonWolf
Veteran
Posts: 284
Liked: 11 times
Joined: Jan 06, 2011 8:33 am
Contact:

Re: Need script to check if a tape job is running please

Post by WinstonWolf »

Should i placed the script in the Tape Job Advanced Settings or in the Backup Job Advanced Settings ?
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Need script to check if a tape job is running please

Post by PTide »

You should place it in Backup Job Advanced settings
WinstonWolf
Veteran
Posts: 284
Liked: 11 times
Joined: Jan 06, 2011 8:33 am
Contact:

Re: Need script to check if a tape job is running please

Post by WinstonWolf »

Thanks i will try it in an Test
WinstonWolf
Veteran
Posts: 284
Liked: 11 times
Joined: Jan 06, 2011 8:33 am
Contact:

Re: Need script to check if a tape job is running please

Post by WinstonWolf »

Hello again ,
I become an Warning when the Job now starts :
03.06.2016 15:03:52 :: Error running pre-job script: The specified executable is not a valid application for this OS platform.
This is my Script :
running-monthly-FS-EXCH-SQL.ps1

And in this Script is this :

Asnp VeeamPSSnapin
if ($TapeJob.LastState -ne "Working"){exit}
else
{
do
{
Start-sleep -s 300 #5 minute waiting interval
$TapeJob = Get-VBRTapeJob -name "MONTHLY_FILE_EXCH-SQL-AD"
}
}while ($TapeJob.LastState -ne "Working")


But it dont work . What is wrong ?


Thanks
veremin
Product Manager
Posts: 20411
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Need script to check if a tape job is running please

Post by veremin »

It seems that you're trying to pass a PS script directly as a pre-job command. Thus, the error.

Use something similar instead:

Code: Select all

c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe <Path to your script>
Thanks.
WinstonWolf
Veteran
Posts: 284
Liked: 11 times
Joined: Jan 06, 2011 8:33 am
Contact:

Re: Need script to check if a tape job is running please

Post by WinstonWolf »

New Problem , The Powershell says that in the "while" loop is an keyword "while" or "until" missin .

Can everyone give me an working Script ? And please so that an powershell beginner can check it .
Thanks
veremin
Product Manager
Posts: 20411
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Need script to check if a tape job is running please

Post by veremin »

Try to place while portion inside the first braces and see whether it makes any diffence:

Code: Select all

    asnp VeeamPSSnapin
    $TapeJob = Get-VBRTapeJob -name "Name of Tape Job"
    if ($TapeJob.LastState -ne "Working"){exit}
    else
    {
        do
        {   
            Start-sleep -s 300 #5 minute waiting interval
            $TapeJob = Get-VBRTapeJob -name "Name of Tape Job"
        }while ($TapeJob.LastState -ne "Working")
    }
Thanks.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 16 guests