PowerShell script exchange
Post Reply
GuidoJ
Novice
Posts: 8
Liked: 1 time
Joined: May 12, 2015 8:47 am
Contact:

Move free tapes to free pool

Post by GuidoJ »

Hello everyone,
i have written a script that scans all tape pools for free media and moves them to the free pool.
What criteria do I have to use to find a free media? is expired is not always set to true.
I wanted to use:
IsExpired -eq 1 -and . IsLocked -eq 0 -and . ProtectedBySoftware -eq 0 -and . ProtectedByHardware -eq 0.

But there are media that have IsExpired = false but no ExpirationDate
Here is my script, but it doesn't find all free media....

cls
#define Media pools to process
#get all Veeam Media Pools with names in myPoolsToProcess
$myPools = Get-VBRTapeMediaPool | Where-Object { $_.name -notin "Free" }
foreach ($myPool in $myPools)
{
Write-Host "processing pool " $myPool.Name
$Medias = Get-VBRTapeMedium -MediaPool $myPool.Name | Where-Object {( $_.IsExpired -eq 1 -and $_.IsLocked -eq 0 -and $_.ProtectedBySoftware -eq 0 -and $_.ProtectedByHardware -eq 0)}

foreach ($Media in $Medias)
{
Write-Host "Prossesing media " $Media
Move-VBRTapeMedium -Medium $Media -MediaPool "Free" -Confirm:$false
}

soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Move free tapes to free pool

Post by soncscy »

Hi GuidoJ,

I think you need to define what you mean by "free" here :) That's your definition I suppose, not the one Veeam uses. Free media in Veeam just means any tape that has been marked as Free, so I suppose you mean tapes that have passed their expiration, yes?

> But there are media that have IsExpired = false but no ExpirationDate

Aha, this is because a tape hasn't been used yet so it doesn't have an expiration date.

I think define what you want specifically to get moved to the free media pool, and we can better help you.

By the way, for this part of your script:

Code: Select all

$myPools = Get-VBRTapeMediaPool | Where-Object { $_.name -notin "Free" }
Doesn't do what you think it does; in this case it works because it looks like Powershell is doing the 1:1 comparison on the Name string vs the string "Free", but this won't work the way you want in all situations, and using a more direct comparison is better.

You can simplify this a ton by just doing:

Code: Select all

$FreeMediaPool = Get-VBRTapeMediaPool -name "Free"
$Tapes = Get-VBRTapeMedium | Where-Object {$_.MediaPoolId -ne $($FreeMediaPool.Id)}
This saves you the MediaPool Loop by just grabbing the tapes only that aren't in the Free media pool
GuidoJ
Novice
Posts: 8
Liked: 1 time
Joined: May 12, 2015 8:47 am
Contact:

Re: Move free tapes to free pool

Post by GuidoJ »

Hi harvey,
thank you for the comments on the free pool, I have already included them.

Yes, by free I mean: have passed their expiration date.
I want to move all the tapes from the different pools to the free pool that have passed their expiration date.
And I'm not sure how to set up the powershell filter to select all the tapes that can be overwritten.
My filter unfortunately does not capture all of these tapes

Many Thanks,

Guido
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Move free tapes to free pool

Post by soncscy »

Hi GuidoJ ,

Sure, happy to help!

Back to your original condition then, can you maybe share some examples when IsExpired was not reliable for you?

> But there are media that have IsExpired = false but no ExpirationDate

I actually don't understand why this is an issue for your script; if IsExpired = false, then per your description that's not what you want so the tape should be skipped from the collection.

Maybe you can share some examples of tapes you think should have been grabbed and share the output of Get-VBRTapeMedium -Name 'name of the tape' and explain why you think it should be collected by your script.
GuidoJ
Novice
Posts: 8
Liked: 1 time
Joined: May 12, 2015 8:47 am
Contact:

Re: Move free tapes to free pool

Post by GuidoJ »

Hello Harvey,
here is an example, my script will not move this tape to the free pool, but there are no unexpired backups left on the tape.
ExpirationDate = empty and IsExpired = false / in the GUI the column "expires in" = "not defined"

PS Y:\> Get-VBRTapeMedium -name "BGN052L7"


Barcode : BGN052L7
BlockSize : 262144
HasBarcode : True
Free : 4487905280
Capacity : 5999999057920
Location : Slot
PreviousLibraryId :
PreviousMediaPoolId :
SequenceNumber : 9
ExpirationDate :
MediaPoolId : 0c3814f3-3f34-4e9b-a95f-ad42eae10b29
MediaSet : SAP 01 SQL Files RZII
LibraryId : b5316b51-7ed6-4268-b89a-f518ff725083
LastWriteTime : 7/9/2021 7:03:38 AM
IsFree : True
IsFull : False
IsLocked : False
IsRetired : False
IsExpired : False
ProtectedBySoftware : False
ProtectedByHardware : False
IsWorm : False
HasUndecryptedBackupSets : False
ReadCyclesNumber : 0
WriteCyclesNumber : 12
LoadCount : 148
CleaningCyclesLeft : 0
Id : e4990042-fd05-4bd3-9b0b-e100b84fa48d
Name : BGN052L7
Description :
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Move free tapes to free pool

Post by soncscy »

Hi GuidoJ!

Okay, I suppose this means this tape was maybe imported after being removed from catalog, or at some point it was set to never expire.

I think in fact this logic is correct; the tape is not expired because it doesn't have an expiration date known to Veeam.

I think if you catalog this tape, you'll see the ExpirationDate appear. Can you try this?

If so, then we can decide what to do; but this logic looks correct to me, I think it's just our idea here of "Expired" is different than the definition IsExpired references :( But try cataloging this tape and see if the Expired value appears. I think your script actually does what it wants, but you have some edge-cases that you need to decide what to do with.

For example, I'd just write some logic to catalog these tapes or manually mark these tapes as free regardless.
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests