I am tasked with retrieving information about a given Azure Backup Vault, and whether the backup(s) are successful or unsuccessful. If successful, I must record how much data has been backed up through a PowerShell function.
I was able to find a command that gave me the backup date(s) and the progress of each backup; however, I was not able to find a command or a set of commands that told me how much data has been backed up for each.
This is the function I have so far, it only gives me the list of backup jobs:
Function Get-AzBackupInfo
{
$nameList = (Get-AzRecoveryServicesVault).Name
$resourceGroupList = (Get-AzRecoveryServicesVault).ResourceGroupName
$hostname = hostname
for ($i = 0; $i -lt $nameList.Length; $i++)
{
if ($resourceGroupList[$i] -match $hostname)
{
$var = Get-AzRecoveryServicesVault -Name $nameList[$i] -ResourceGroupName $resourceGroupList[$i]
$jobList = Get-AzRecoveryServicesBackupJob -VaultId $var.ID
}
}
$jobList
}
Are there any modifications / additions I can make to this function that will give me the amounts of data (in GB) that have been backed up?
I am tasked with retrieving information about a given Azure Backup Vault, and whether the backup(s) are successful or unsuccessful. If successful, I must record how much data has been backed up through a PowerShell function.
I was able to find a command that gave me the backup date(s) and the progress of each backup; however, I was not able to find a command or a set of commands that told me how much data has been backed up for each.
This is the function I have so far, it only gives me the list of backup jobs:
Function Get-AzBackupInfo
{
$nameList = (Get-AzRecoveryServicesVault).Name
$resourceGroupList = (Get-AzRecoveryServicesVault).ResourceGroupName
$hostname = hostname
for ($i = 0; $i -lt $nameList.Length; $i++)
{
if ($resourceGroupList[$i] -match $hostname)
{
$var = Get-AzRecoveryServicesVault -Name $nameList[$i] -ResourceGroupName $resourceGroupList[$i]
$jobList = Get-AzRecoveryServicesBackupJob -VaultId $var.ID
}
}
$jobList
}
Are there any modifications / additions I can make to this function that will give me the amounts of data (in GB) that have been backed up?
Share Improve this question edited Mar 21 at 18:16 mimi m asked Mar 21 at 18:12 mimi mmimi m 311 silver badge5 bronze badges 1- 1 Add Get-AzRecoveryServicesBackupJobDetails to fetch BackupSizeInBytes and convert it to GB. @mimim – Vinay B Commented Mar 25 at 3:09
1 Answer
Reset to default 1How to Retrieve Amount of Storage Backed up (in GB) by Azure?
You can use the below PowerShell script which fetches the usage of Azure recovery vault.
Script:
$subscriptionId = "xxxx"
$resourceGroupName = "xx"
$vaultName = "vxxxd"
$apiVersion = "2024-10-01"
$uri = "https://management.azure/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.RecoveryServices/vaults/$vaultName/usages?api-version=$apiVersion"
$accessToken = (Get-AzAccessToken -ResourceUrl "https://management.azure").Token
# Call the API
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers @{ Authorization = "Bearer $accessToken" }
# Convert Byte values to GB
$convertedResponse = $response.value | ForEach-Object {
if ($_.unit -eq "Bytes") {
$_.currentValue = "{0:N2} GB" -f ($_.currentValue / 1GB)
}
$_
}
# Display the results
$convertedResponse | Format-Table -AutoSize
The above script retrieves the usage details of an Azure Recovery Services vault by calling the Azure REST API. It authenticates using Get-AzAccessToken
, fetches the usage details via Invoke-RestMethod
, and converts byte values to GB for readability before displaying them in a table.
Output:
Reference:
- Usages - List By Vaults - REST API (Azure Recovery Services) | Microsoft Learn
- How to obtain the total amount of Backup storage in GB or TB with a script - Microsoft Q&A by TP.