Search for Repository with highest Free Space for Linux

PowerShell script exchange

Search for Repository with highest Free Space for Linux

Veeam Logoby jevao » Mon Jun 23, 2014 6:08 am

I use the following code, from an Andreas script "Add VM to Job/Create Job and Add VM",
which works great for Windows Backup repositories.
Unfortunately, we have mostly Linux Backup Repositories.
I have looked, but have not found code that will also work on Linux Repositories.
Is there a way to get "Freespace" from a Linux Repository?
Thanks for any help.

Code: Select all
#Search for the Repository with the highest free space.
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Search for the Repository with the highest free space"
$Repository1 = Get-VBRBackupRepository
$b = "0"
foreach ($RepositoryNames in $Repository1) {
$r = Get-VBRBackupRepository -name $RepositoryNames.name
$rServer = $r.GetHost()
$FileCommander = [Veeam.Backup.Core.CRemoteWinFileCommander]::Create($rServer.Info)
$storage = $FileCommander.GetDrives([ref]$null) | ?{$_.Name -eq $r.Path.Substring(0,3)}
$outputObj = [Math]::Round([Decimal]$storage.FreeSpace/1GB,0)
$ia = $RepositoryNames.name
If ($ia -eq "Default Backup Repository") {
$outputObj = 0
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Repository:" $ia "manually set to 0GB free space (disabled)"
} ELSE {}
$ib = $outputObj
$ActualDate = get-date -format u
write-host $ActualDate "Information: Repository: " $ia " with "$ib "GB free space"

if ($ib -ge $b) {
$b = $ib
$a = $ia
} ELSE {
}
}
$ActualDate = get-date -format u
write-host $ActualDate "Information: Selected Repository:" $a " with " $b "GB free space"
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby v.Eremin » Mon Jun 23, 2014 8:58 am

I'm wondering whether you have Veeam ONE deployed. It has predefined reports that provide up-to-date information about both Linux and Windows repositories; might be worth taking a look. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby jevao » Mon Jun 23, 2014 6:30 pm 1 person likes this post

Sorry. After posting before, I found the topic "Repository Size" with code from "ThomasMc" at powershell-f26/repository-size-t10674.html

Using his code, I was able to produce this solution. Thanks

Code: Select all
# Define Function

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
       }
}
#End of function Get-vPCRepoInfo



#Search for the Repository with the highest free space.
$ActualDate = get-date -format u
Write-host $ActualDate "Information: Search for the Repository with the highest free space"
$Repository1 = Get-VBRBackupRepository
$b = "0"
foreach ($RepositoryNames in $Repository1) {
$outputObjs = Get-VBRBackupRepository -name $RepositoryNames.name | Get-vPCRepoinfo
$outputObj = $outputObjs.StorageFree
$ia = $RepositoryNames.name
If ($ia -eq "Default Backup Repository") {
    $outputObj = 0
    $ActualDate = get-date -format u
    Write-host $ActualDate "Information: Repository:" $ia "manually set to 0GB free space (disabled)"
} ELSE {}
$ib = $outputObj
$ActualDate = get-date -format u
write-host $ActualDate "Information: Repository: " $ia " with "$ib "GB free space"

if ($ib -ge $b) {
$b = $ib
$a = $ia
} ELSE {
}
}
$ActualDate = get-date -format u
write-host $ActualDate "Information: Selected Repository:" $a " with " $b "GB free space"
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby v.Eremin » Tue Jun 24, 2014 9:08 am

I'm glad to hear that you've found the solution suiting your needs. Anyway, if you haven't done it yet, I would still recommend deploying Veeam ONE with all of its robust monitoring and reporting capabilities, such as Capacity Planning for Backup Repositories and others. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby jevao » Tue Jun 24, 2014 8:12 pm

I do have Veeam One, and it has been very helpful. The "Protected VMs" includes an "Unprotected VMs" report, that I still use to see which VMs are not being backed up. I also receive reports on "Datastore" usage and "Active Snapshots", etc. For anyone not doing powershell scripting, I recommend it.
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby v.Eremin » Tue Jun 24, 2014 8:44 pm

Just out of curiosity - why Veeam ONE doesn't work you in terms of monitoring/reporting on backup repositories. Or what information seems to be missing in the said pre-defined report or other views provided? May be, your feedback will help us to bridge the current gap. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby tsightler » Wed Jun 25, 2014 11:20 am

I'm interested as well but I'd guess that he's attempting to automate adding a VM automatically to a job and trying to pick the best available repo. Veeam One is great and all but it can't easily be used for instrumentation of automation workflows since it has no native API of it's own.
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby v.Eremin » Wed Jun 25, 2014 11:24 am

Veeam ONE used to have PowerShell module. The module sank into oblivion years ago, as not many people were interested in it. What a pity.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Search for Repository with highest Free Space for Linux

Veeam Logoby jevao » Wed Jun 25, 2014 2:01 pm

Both of you are correct. "Instrumentation of automation workflows" is the focus. I am hoping the benefits of automation far outweigh the efforts. Veeam One was very helpful when getting started. Powershell allows for automating workflows.
jevao
Enthusiast
 
Posts: 29
Liked: 3 times
Joined: Fri Oct 28, 2011 11:38 pm
Full Name: James Collison


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 2 guests