PowerShell script exchange
Post Reply
tomcec
Novice
Posts: 4
Liked: never
Joined: Feb 20, 2012 11:00 am
Full Name: Tommaso Cecchi
Contact:

Repository size

Post by tomcec »

Hello, we are using V6 (w/ patch 3) and we are trying to understand how to extract information about how much free space in repositories is left.
We are using Windows repositories and we tried with:

get-vbrbackuprepository

but for how deep we may drill down the tree of methods and properties we have not seen a way to extract this info.
Can anyone give us some hint?

Thanks so much,
Tommaso
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Repository size

Post by ThomasMc »

This is the cmdlet I use for the vPC Army Report that you can't tweak to your needs

Code: Select all

function Get-vPCRepoInfo {
[CmdletBinding()]
	param (
		[Parameter(Position=0, ValueFromPipeline=$true)]
		[PSObject[]]$Repository
		)
	Begin {
		$outputAry = @()
		[Reflection.Assembly]::LoadFile("C:\Program Files\Veeam\Backup and Replication\Veeam.Backup.Common.dll") | Out-Null
		function Build-Object {param($name, $path, $free, $total)
			$repoObj = New-Object -TypeName PSObject -Property @{
					Target = $name
					storepath = $path
					StorageFree = [Math]::Round([Decimal]$free/1GB,2)
					StorageTotal = [Math]::Round([Decimal]$total/1GB,2)
					FreePercentage = [Math]::Round(($free/$total)*100)
				}
			return $repoObj
		}
	}
	Process {
		foreach ($r in $Repository) {
			if ($r.GetType().Name -eq [String]) {
				$r = Get-VBRBackupRepository -Name $r
			}
			if ($r.Type -eq "WinLocal") {
				$Server = $r.GetHost()
				$FileCommander = [Veeam.Backup.Core.CRemoteWinFileCommander]::Create($Server.Info)
				$storage = $FileCommander.GetDrives([ref]$null) | ?{$_.Name -eq $r.Path.Substring(0,3)}
				$outputObj = Build-Object $r.Name $r.Path $storage.FreeSpace $storage.TotalSpace
			}
			elseif ($r.Type -eq "LinuxLocal") {
				$Server = $r.GetHost()
				$FileCommander = new-object Veeam.Backup.Core.CSshFileCommander $server.info
				$storage = $FileCommander.FindDirInfo($r.Path)
				$outputObj = Build-Object $r.Name $r.Path $storage.FreeSpace $storage.TotalSize
			}
			elseif ($r.Type -eq "CifsShare") {
				$fso = New-Object -Com Scripting.FileSystemObject
				$storage = $fso.GetDrive($r.Path)
				$outputObj = Build-Object $r.Name $r.Path $storage.AvailableSpace $storage.TotalSize
			}
			$outputAry = $outputAry + $outputObj
		}
	}
	End {
		$outputAry
	}
}
Usage:

Code: Select all

Get-VBRBackupRepository -Name "My Repo" | Get-vPCRepoInfo
Sample Output:

Code: Select all

storepath      : E:\Backups
FreePercentage : 63
StorageTotal   : 824.00
StorageFree    : 522.05
Target         : My Repo
tomcec
Novice
Posts: 4
Liked: never
Joined: Feb 20, 2012 11:00 am
Full Name: Tommaso Cecchi
Contact:

Re: Repository size

Post by tomcec »

ThomasMc wrote:This is the cmdlet I use for the vPC Army Report that you can't tweak to your needs
Thomas, thanks for your immediate and quick reply. Works perfectly for me. I'll just try to convert the output in a sort of csv format (not actually a guru in powershell so ... it could take a while) and post it here.

Thanks again,
Tommaso
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Repository size

Post by ThomasMc »

You could do this

Code: Select all

#Save output to CSV
Get-VBRBackupRepository -Name "My Repo" | Get-vPCRepoInfo | Export-Csv C:\Test.csv -NoTypeInformation
#Open the file with default viewer
Invoke-Expression C:\Test.csv
wasawatt
Lurker
Posts: 2
Liked: never
Joined: Jul 16, 2016 3:13 pm
Full Name: Wasawatt
Contact:

Re: Repository size

Post by wasawatt »

Hi Thomas,
I try to follow you and I use Veeam BR9. on Windows Server 2008R2 with Powershell v4.
but unfortunately I got this error for about 'Create' method of "[Veeam.Backup.Core.CRemoteWinFileCommander]".

Code: Select all

----------------------------------------
Method invocation failed because [Veeam.Backup.Core.CRemoteWinFileCommander]
does not contain a method named 'Create'.
At line:28 char:13
+             $FileCommander =
[Veeam.Backup.Core.CRemoteWinFileCommander]::Create ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

You cannot call a method on a null-valued expression.
At line:29 char:13
+             $storage = $FileCommander.GetDrives([ref]$null) | ?{$_.Name -eq
$r.P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Attempted to divide by zero.
At line:11 char:10
                                           
-------------------------------------------
could you or everyone guide me to fix this issue.

regards and Thank you,
Wasawatt
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Repository size

Post by veremin »

The workaround provided above used unsupported and undocumented approach that has ceased to exist already.

What information are you trying to get? Repository utilization? Don't you have a Veeam ONE deployed by any chance?

Thanks.
wasawatt
Lurker
Posts: 2
Liked: never
Joined: Jul 16, 2016 3:13 pm
Full Name: Wasawatt
Contact:

Re: Repository size

Post by wasawatt »

Hi,
I need to check to size of VM is fit with repository before create job. due to I integrate with VMware and need to create some logic to check.

for Veeam ONE i am not deploy it. I use on;y Veeam Backup & Replicate and Enterprise Manager.

Regards,
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Repository size

Post by veremin »

You can use this tool to get general idea on how much space will be occupied on a repository. Thanks.
Post Reply

Who is online

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