Az Powershell mount drive with backed up data from MARS

Jan Vávra 251 Reputation points
2023-10-13T14:44:38.16+00:00

Hello.
By this script I can get to protected folders that I've selected in the MARS client to be backed up.

$vault = Get-AzRecoveryServicesVault -ResourceGroupName "REDACTED" -Name "REDACTED"
$Container = Get-AzRecoveryServicesBackupContainer -ContainerType Windows -BackupManagementType MAB -FriendlyName "REDACTED"
$BackupItems = Get-AzRecoveryServicesBackupItem -Container $Container -WorkloadType AzureVM -VaultId $vault.ID
foreach ($BackupItem in $BackupItems)
{
	$BackupItem | ft FriendlyName, LastBackupStatus, LastBackupTime
}

and output

FriendlyName LastBackupStatus LastBackupTime
------------ ---------------- --------------
C:\          Completed        13.10.2023 2:00:12
FriendlyName LastBackupStatus LastBackupTime
------------ ---------------- --------------
System State Failed           13.10.2023 14:23:01
FriendlyName LastBackupStatus LastBackupTime
------------ ---------------- --------------
E:\          Completed        13.10.2023 2:00:12

I'd like to automate a check that in the backup are particular files that is expected to be backed up.
Can I somehow attach by the PowerShell or az cli the fileshare that is created when this is done manually in the MARS client?

The listing of content of each $BackupItem would be sufficient but I've found any az powershell cmdlet for it.

Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
1,142 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,150 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 26,241 Reputation points Microsoft Employee
    2023-10-20T01:24:27.1133333+00:00

    Hi @Jan Vávra

    To attach the file share created when this is done manually in the MARS client, you can use the New-AzRecoveryServicesBackupProtectionPolicyObject cmdlet. This cmdlet creates a new backup protection policy object that can be used to configure backup protection for a workload. You can use this cmdlet to create a backup protection policy that includes the file share created in the MARS client.

    To list the contents of each backup item, you can use the Get-AzRecoveryServicesBackupRecoveryPoint cmdlet. This cmdlet gets the recovery points for a backup item. You can use this cmdlet to list the contents of each backup item.

    Here's an example script:

    $vault = Get-AzRecoveryServicesVault -ResourceGroupName "REDACTED" -Name "REDACTED"
    $Container = Get-AzRecoveryServicesBackupContainer -ContainerType Windows -BackupManagementType MAB -FriendlyName "REDACTED"
    $BackupItems = Get-AzRecoveryServicesBackupItem -Container $Container -WorkloadType AzureVM -VaultId $vault.ID
    foreach ($BackupItem in $BackupItems)
    {
        $BackupItem | ft FriendlyName, LastBackupStatus, LastBackupTime
    
        # Modify the script to include the specific files that you want to verify
        # Use the New-AzRecoveryServicesBackupProtectionPolicyObject cmdlet to create a backup protection policy that includes the file share created in the MARS client
        # Use the Get-AzRecoveryServicesBackupRecoveryPoint cmdlet to list the contents of each backup item
    }
    

    Comment down below if this doesn't work or you run into any issues.