PowerShell script exchange
Post Reply
Palmero
Influencer
Posts: 12
Liked: 1 time
Joined: Jul 12, 2021 6:30 pm
Full Name: Juan Palmero
Contact:

How to get Used Space from Repository

Post by Palmero »

Hello,

I have a number of S3-compatible repositories that reside on a Cloudian storage array. I'd like to put together a PS script that reports on used space.

On my Veeam console under Backup Repositories I see several "buckets" that show the "Used Space" for each bucket.

Any suggestions on which PS command to use?

Thank you.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to get Used Space from Repository

Post by oleg.feoktistov »

Hi Juan,

Does the method below reflect the actual used size for your s3 compatible repos?

Code: Select all

$repo = Get-VBRObjectStorageRepository -Type AmazonS3Compatible
[Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices($repo.Id)
Thanks,
Oleg
Palmero
Influencer
Posts: 12
Liked: 1 time
Joined: Jul 12, 2021 6:30 pm
Full Name: Juan Palmero
Contact:

Re: How to get Used Space from Repository

Post by Palmero »

Hi Oleg,

First of all, I really appreciate your taking the time to help. Here is additional information; I'm fairly new to Veeam, recently installed, it is functional, but I'm still in the process of configuration. I have a Cloudian array that is S3 compatible, and used for immutable backups as a scale out repository (SOBR).

The first statement works. It returns an array of the repositories. Here is an example of one of them:

Code: Select all

AmazonS3Folder            : PRD
ServicePoint              : https://s3-west.mydomain.intranet
BackupImmutabilityEnabled : True
ImmutabilityPeriod        : 15
Type                      : AmazonS3Compatible
UseGatewayServer          : False
GatewayServer             :
SizeLimitEnabled          : False
SizeLimit                 : 10240
Id                        : 45eb2fc1-0418-4475-94be-f6846fec2832
Name                      : bkup_rep-object-cloudian_veeam.prd
Description               : Cloudian S3 - veeam.prd
On the console, under "Backup Infrastructure" "Backup Repositories" I see that this specific bucket has used 33TB.

Code: Select all

Name				    Type	   Capacity Free  Used   Description
bkup_rep-object-cloudian_veeam.prd  S3-Compatible     N/A    N/A  33TB 	Cloudian S3 - veeam.prd
However, the second command throws an error:

Code: Select all

PS > Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices($repo.Id)
Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices : The term
'Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:1
+ Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeBy ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Veeam.Backup.Co...edSizeByIndices:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Again, thank you.
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: How to get Used Space from Repository

Post by soncscy »

Hey Juan,

Check your syntax, you dropped a "[" character at the start :)

Oleg is calling .NET methods here with Powershell Reflections, and you just missed the opening bracket.

Edit: oh! sorry Juan, actually you did nothing wrong :) Oleg just had a copying error it looks and his code got truncated.

Change it to:

Code: Select all

[Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices($repo.Id)
and see if it works.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to get Used Space from Repository

Post by oleg.feoktistov »

Hey Juan,

Harvey is right, my bad. I had "[" truncated for some reason, sorry for that.
Fixed it in my initial script.

Please have a look.

Oleg
Palmero
Influencer
Posts: 12
Liked: 1 time
Joined: Jul 12, 2021 6:30 pm
Full Name: Juan Palmero
Contact:

Re: How to get Used Space from Repository

Post by Palmero »

Unfortunately still getting an error.

Code: Select all

PS C:\> [Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices($repo.Id)
Cannot convert argument "repositoryId", with value: "System.Object[]", for "CalcArchiveRepositoryUsedSizeByIndices" to
type "System.Guid": "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Guid"."
At line:1 char:1
+ [Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeB ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

PS C:\>
In case it makes a difference, note that I'm using the power shell environment launched from the Veeam console while logged into the backup server itself.

Thank you.
Juan.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to get Used Space from Repository

Post by oleg.feoktistov »

It looks like you have an array of repositories held in $repo, and CalcArchiveRepositoryUsedSizeByIndices() method receives a single object only.
You need to explicitly choose one repo you would like to get this info for:

Code: Select all

# Option 1. By name
$repo = Get-VBRObjectStorageRepository -Type AmazonS3Compatible -Name 'bkup_rep-object-cloudian_veeam.prd'
[Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices($repo.Id)

# Option 2. By index
$repo = Get-VBRObjectStorageRepository -Type AmazonS3Compatible
[Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices($repo[0].Id)
or loop through each repo if you want to get used space property for all of them:

Code: Select all

$repos = Get-VBRObjectStorageRepository -Type AmazonS3Compatible
foreach ($repo in $repos) {
  $usedSpace = [Veeam.Backup.Core.CBackupRepository]::CalcArchiveRepositoryUsedSizeByIndices($repo.Id)
  $repo | select Name, Description, @{n='UsedSpace';e={$usedSpace}}
}
Thanks!
Palmero
Influencer
Posts: 12
Liked: 1 time
Joined: Jul 12, 2021 6:30 pm
Full Name: Juan Palmero
Contact:

Re: How to get Used Space from Repository

Post by Palmero »

Hi Oleg,

I don't know how I missed the fact that it returns an array. It's now working with the the foreach loop.

Really appreciate yours and everyone else's help!

Now all I need is to do is figure out how to launch the script as a scheduled task from one of the servers that we use to schedule such reports. I'm finding out that when launching from a remote server I first need to connect to my Veeam server using Connect-VBRServer. However, this command requires server name, port and credentials. Is there a way to run remotely within the context of a service account without providing the credentials in clear text?

Thanks again.
Palmero
Influencer
Posts: 12
Liked: 1 time
Joined: Jul 12, 2021 6:30 pm
Full Name: Juan Palmero
Contact:

Re: How to get Used Space from Repository

Post by Palmero »

One question, you used CalcArchiveRepositoryUsedSizeByIndices. Is there documentation or some list of what other methods are exposed? I would also like to get total TB capacity on my Cloudian to perform some calculations.

Thanks again.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to get Used Space from Repository

Post by oleg.feoktistov »

Hey Juan,
Is there a way to run remotely within the context of a service account without providing the credentials in clear text?
You could save VBR server's credentials to credentials manager on the server where VBR console is installed, get them and pass to connect cmdlet.
Is there documentation or some list of what other methods are exposed?
.NET classes and methods is rather unofficial way to interact with VBR resources. We usually provide those as a workaround if something is not yet covered with our Powershell API. All you see in the Powershell documentation is, in contrast, and thus supported.
If you want to dig into .NET, a good way to begin with would be to explore an output of different cmdlets with Show-Object cmdlet from PowershellCookbook module.
A more advanced way would be to use any .NET assembly decompiler to read .NET assembly members and search through them.
I would also like to get total TB capacity on my Cloudian to perform some calculations.
If you are talking about the Capacity like reflected in VBR console, in powershell it is reflected in SizeLimit property of your S3 compatible repo:

Code: Select all

$s3 = Get-VBRObjectStorageRepository -Name 'repo' -Type AmazonS3Compatible
$s3.SizeLimit
Hope it helps,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests