PowerShell script exchange
Post Reply
widmerkarl
Expert
Posts: 122
Liked: 29 times
Joined: Jan 06, 2015 10:03 am
Full Name: Karl Widmer
Location: Switzerland
Contact:

Tape Handling with script / script partial working

Post by widmerkarl »

Hello folks

First of all i know that there are many posts about Veeam Tape and scripting. I followed some of them and picked out what i needed to create a script that should work.

Well, that's it, it should work. When i execute it manually, the script does what's expected. When it's executed right within the tape job (Options => Advanced => Advanced => Run the following script before the job) it does not work. At least i see that when i check the running backup the next morning, Veeam is waiting for tape. Then i execute the script manually, and poof, the tape goes in the correct media pool and the job uses the inserted tape to write data.

I execute a batch script with the following code in it:

Code: Select all

powershell.exe C:\Library\Scriptlib\pretape.ps1
The batch script fires up Powershell and then this code will be executed:

Code: Select all

Add-PSSnapin VeeamPSSnapin
Get-VBRTapeDrive -Name "Tape0" | Start-VBRTapeInventory
$tape = Get-VBRTapeMedium
Move-VBRTapeMedium -Medium $tape -MediaPool "TapePool" -Confirm:$false
This script is perhaps not the best one, but at least it works when executed manually. What i have to check is the media stuff. With every execution of this script the powershell output list will be longer and tells me that this and that tape is already in the specific media pool.

I have also to find out why it's not executed at the job runtime. I now created a task in Windows task scheduler and will see tomorrow if that works.

My customer has about 20 tapes. For each weekday a tape and this for about four weeks (monday 1, monday 2 and so on). When we switched from Backup Exec to Veeam i had similar issues. But then i deleted all the tapes with HP Library & Tape tools, and Veeam took every tape without any issue or scripting.

Now the tapes are once rotated completely and now Veeam does not accept the tapes without manual handling or automated via script.

Does any one of you have an idea why the script is not executed at job runtime? And how can this script be improved?

Thank you very much!
Karl Widmer
IT System Engineer

vExpert 2017-2024
VMware VCP-DCV 2023 / VCA6-DCV / VCA5-DCV / VCA5-Cloud / VMUG Leader
Former Veeam Vanguard / VMCE v9 / VMTSP v9 / VMSP v9
Personal blog: https://www.driftar.ch
Twitter: @widmerkarl
foggy
Veeam Software
Posts: 21138
Liked: 2141 times
Joined: Jul 11, 2011 10:22 am
Full Name: Alexander Fogelson
Contact:

Re: Tape Handling with script / script partial working

Post by foggy »

Karl, please review this thread for possible reasons of why the script doesn't run.
widmerkarl
Expert
Posts: 122
Liked: 29 times
Joined: Jan 06, 2015 10:03 am
Full Name: Karl Widmer
Location: Switzerland
Contact:

Re: Tape Handling with script / script partial working

Post by widmerkarl »

Hello foggy,

Thanks for the input. Indeed i did some checks which i saw in the thread you mentioned (permissions etc.).

- Veeam services are configured to run with user account "domain\administrator"
- I can't add the domain administrator to local administrator group since the veeam backup server is a second domain controller
- I checked the Veeam logs and can find entries that the script has been executed successfully:

Code: Select all

[22.02.2016 10:06:57] <01> Info     Running pre-job script
[22.02.2016 10:06:57] <01> Info     Executing custom command 'C:\Library\Scriptlib\pretape.cmd', arguments ''
[22.02.2016 10:07:01] <01> Info     Pre-job script completed successfully
But as i mentioned Veeam goes in the state "waiting tape" until i execute the script manually.

As i wrote above i added a task now in Windows task scheduler and will come back tomorrow with an update.
Karl Widmer
IT System Engineer

vExpert 2017-2024
VMware VCP-DCV 2023 / VCA6-DCV / VCA5-DCV / VCA5-Cloud / VMUG Leader
Former Veeam Vanguard / VMCE v9 / VMTSP v9 / VMSP v9
Personal blog: https://www.driftar.ch
Twitter: @widmerkarl
widmerkarl
Expert
Posts: 122
Liked: 29 times
Joined: Jan 06, 2015 10:03 am
Full Name: Karl Widmer
Location: Switzerland
Contact:

Re: Tape Handling with script / script partial working

Post by widmerkarl »

Hello everyone

Long time ago since i had this issue. And i don't really like to dig out old threads. But today we found a possible solution and i think that this hint will perhaps help someone.

Code: Select all

Add-PSSnapin VeeamPSSnapin
Get-VBRTapeDrive -Name "Tape0" | Start-VBRTapeInventory -Wait
$tape = Get-VBRTapeMedium -Drive "Tape0"
Erase-VBRTapeMedium -Medium $tape -Wait
Move-VBRTapeMedium -Medium $tape -MediaPool "Free" -Confirm:$false
The script above does the following:

1) it loads the Veeam powershell snappin.
2) it gets the tape drive "tape0" and does an inventory. It waits for the next steps until inventory is done.
3) It writes the content of the tape drive (literarily the name of the tape) in the variable "$tape".
4) the script then erases the tape with the variable "$tape" (quick erase) and waits until this step is done.
5) the script then moves the tape to the Veeam media pool "Free".

You will have to check the settings within the manually created media pool, that the media pool adds free tapes automatically from the free media pool in case, additional capazity is needed.
Karl Widmer
IT System Engineer

vExpert 2017-2024
VMware VCP-DCV 2023 / VCA6-DCV / VCA5-DCV / VCA5-Cloud / VMUG Leader
Former Veeam Vanguard / VMCE v9 / VMTSP v9 / VMSP v9
Personal blog: https://www.driftar.ch
Twitter: @widmerkarl
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Tape Handling with script / script partial working

Post by veremin »

Is the last line really necessary? The erased tape should be automatically placed in free media pool, if remember that correctly. Thanks.
widmerkarl
Expert
Posts: 122
Liked: 29 times
Joined: Jan 06, 2015 10:03 am
Full Name: Karl Widmer
Location: Switzerland
Contact:

Re: Tape Handling with script / script partial working

Post by widmerkarl »

Hi Vladminir,

We tested it without it, but then nothing happend. After running the script there was just a empty tape in the drive.

Of course the tape we tested was member of an existing media pool. So it stayed there empty in this specific media pool, until we added the last line.

We will test it the next few days. Perhaps the last line can be removed, when the tape IS member of an existing media pool, but leave the line if the tape is NOT a member of an existing media pool.
Karl Widmer
IT System Engineer

vExpert 2017-2024
VMware VCP-DCV 2023 / VCA6-DCV / VCA5-DCV / VCA5-Cloud / VMUG Leader
Former Veeam Vanguard / VMCE v9 / VMTSP v9 / VMSP v9
Personal blog: https://www.driftar.ch
Twitter: @widmerkarl
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Tape Handling with script / script partial working

Post by veremin »

We tested it without it, but then nothing happend. After running the script there was just a empty tape in the drive.
After having thought about it for a little while, I can confirm that the last line is indeed necessary. A tape that used to belong to some media pool, not including pre-defined ones, will stay in this media pool after erase operation.

Thus, keep the last line as is.

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests