[PowerShell] analyze used repository space

  • 22 January 2021
  • 2 comments
  • 1104 views

Userlevel 7
Badge +13

Here I want to show how to query space in VBR Repositories with a few PowerShell snippets. These can be taken to check used space and compare this with restore points in VBR database. It can be used for larger environments to analyze repository space. I used these codes to analyze differences in size on the repositories at a customer.

First check: Restore points in database and compare them to allocated space on repository.

$VbrVMs = ((Get-VBRBackup  | Get-VBRRestorePoint)  |select vmname, @{N="Job"; E={$_.getsourcejob().name }}, @{N="Repo"; E={$_.getrepository().name }} , @{N="size"; E={$_.getstorage().stats.BackupSize }}) 

 

The output of this one-liner should be the same as properties of disk backups.

 

When total over all this corresponds to used space on repository volumes, everything is OK. If not, a problem can exist.

Second Check: You can check each physical file with Veeam known files in DB. I used this script (http://sebastiaan.tempels.eu/2017/05/05/veeam-orphaned-files/) to start with. This script is limited to local data. To use it for distributed environments, you can start with the following snippets.

To get all repository files as XML, you can run.

$result = @()
$dirs = (Get-ChildItem path_to_repo).fullname
foreach ($dir in $dirs) {
    $temp = @()
    $temp = Get-ChildItem -Path $dir -Depth 2 -file | select FullName, pschildname, length, creationtime, lastaccesstime
    $result += $temp
}
$result | Export-Clixml -Path C:\path_to_xml.xml

Build array of Veeam files in DB with absolute path. I did not find another way as querying SQL server directly.

$vbrdata=@(); $Source=@(); 
$Source  = Import-Clixml -Path C:\path_to_xml.xml
$SOR = Get-VBRBackupRepository -name repo_name -ScaleOut | Get-VBRRepositoryExtent
$data = Get-VBRBackup  | Get-VBRRestorePoint
foreach ($d in $data){
    $extent = (Invoke-Sqlcmd -Query "SELECT [dependant_repo_id] FROM [VeeamBackup].[dbo].[Backup.ExtRepo.Storages] WHERE [storage_id] = '$($d.StorageId)';" -ServerInstance "sql_server_Instance").dependant_repo_id
    $base = ($SOR | ? {$_.id -eq $extent}).Repository.FriendlyPath
    $path = $base+"\"+$d.FindBackup().DirPath+"\"+$d.GetStorage().FilePath
    $vbrdata += $path
}

Compare physical files with files in DB. All files, not in DB

$Orphant = @()
foreach ($s in $Source){
    if ($vbrdata -notcontains $s.fullname){
        $Orphant += $s
    }
}

$Orphant should now contain all filesystem files, not known by Veeam as restore points. Notice: With these snippets, DB-transaction logs are also in the list (*.vlb).


2 comments

Userlevel 7
Badge +17

:grin: very nice script.

I was working on a similar script because we were talking about this in another thread…

My problem in the last days was the copare of the files in the repo with the entries in the VEEAM DB. So now you solved my problem...

Userlevel 7
Badge +13

:grin: very nice script.

I was working on a similar script because we were talking about this in another thread…

My problem in the last days was the copare of the files in the repo with the entries in the VEEAM DB. So now you solved my problem...

was a pleasure to be able to help you!

Comment