PowerShell script exchange
Post Reply
dvdv
Novice
Posts: 4
Liked: 1 time
Joined: Jan 29, 2015 9:03 am
Full Name: Dennis
Contact:

Erase any tape that is inserted

Post by dvdv »

Hi,

I've been playing around with the following, but for some reason it doesn't work reliable.

Situation:
I want to perform a backup 2 disk (forever incremental) and when it's finished, it needs to be written to tape immediately.
The jobs themselves are configured in the correct manner and when the first one is done, the tape job kicks in nicely.

I have a script that runs at 6pm every day, and it should quick erase any tape that is inserted in the drive, so it can be used for the tapejob later that evening.
Script:
-----------------------------------------
Write-host “Prepare Tape for Veeam backup”
Add-PSSnapin -Name VeeamPSSnapin
Get-VBRTapeMedium | where {$_.location -like "Drive"} | Erase-VBRTapeMedium -confirm:$false
----------------------------------------
It seemed to have worked for a while, but yesterday and today the task scheduler reports that the job runned fine, but the tape is not erased.
As a result the data is added to the tape and it asks for another tape.

Could someone have a look at my script and tell me where to improve it?

Thanks!

Regards,

Dennis
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Erase any tape that is inserted

Post by veremin »

The script itself looks good. Will it work if you start it manually? Thanks.
dvdv
Novice
Posts: 4
Liked: 1 time
Joined: Jan 29, 2015 9:03 am
Full Name: Dennis
Contact:

Re: Erase any tape that is inserted

Post by dvdv »

Yes, when I started it manually all works fine.

I also re-scheduled it and let it run while I was watching, and (ofcourse...) it also ran fine again. ;-)
The tapes I'm using aren't new ones.
As a test I've tried to manually erase one of the tapes that 'didn't work', and guess what....once again no problem.

So I'm a bit confused now.....all things seems to be ok, they all work fine when done manually, but for some reason it just didn't work 2 times in a row.

Any suggestions?
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Erase any tape that is inserted

Post by veremin »

For me it sounds like problem lies outside of Veeam, as script does it job perfectly, if executed manually. I would double check accounts under which script is executed (manually, Scheduler), whether they are the same or have same permissions, etc. Thanks.
dvdv
Novice
Posts: 4
Liked: 1 time
Joined: Jan 29, 2015 9:03 am
Full Name: Dennis
Contact:

Re: Erase any tape that is inserted

Post by dvdv »

Ok, thanks for your reply.
Just wanted to check if the script was fine.
I'll investigate further.

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

Re: Erase any tape that is inserted

Post by veremin »

As long as manual execution of script doesn't produce any issues, you can be sure that there is nothing wrong with the code itself. Thanks.
dvdv
Novice
Posts: 4
Liked: 1 time
Joined: Jan 29, 2015 9:03 am
Full Name: Dennis
Contact:

Re: Erase any tape that is inserted

Post by dvdv » 1 person likes this post

'problem' found.

When you insert a tape and do not perform an inventory first, the script won't run, since the drive/Veeam doesn't know there is a tape inserted.
To solve it I added a line to perform an inventory first.
Now it's working perfectly.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Erase any tape that is inserted

Post by veremin »

Yep, having "Start-VBRTapeInventory -Library <>" line in the beginning of the script should do the trick, indeed. Glad to hear you've nailed it.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests