none
Can anyone please suggest how we can restore a file share backup item with powershell RRS feed

  • Question

  • I am trying to restore the Azure File Share backup item to an alternate location I am getting this error in the final line


       

    $vault = Get-AzRecoveryServicesVault -ResourceGroupName "Resource Group Name" -Name "Vault Name"
    Set-AzRecoveryServicesVaultContext -Vault $vault
    $Container = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureStorage" -Status "Registered" -FriendlyName "StorageAccountName" -VaultId $vault.ID
    $BackupItem = Get-AzRecoveryServicesBackupItem -Container $Container -WorkloadType AzureFiles -VaultId $vault.ID
    # $RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem
    $StartDate = (Get-Date).AddDays(-3)
    $EndDate = Get-Date
    $RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartDate $StartDate.ToUniversalTime() -EndDate $EndDate.ToUniversalTime() -VaultId $vault.ID
    $RestoreJob = Restore-AzRecoveryServicesBackupItem -RecoveryPoint $RP[1] -ResolveConflict "Overwrite" -TargetStorageAccountName "azrw" -TargetFileShareName "testdb" -StorageAccountResourceGroupName "Resource Group Name"  -VaultId $vault.ID -VaultLocation $vault.Location

    Restore-AzRecoveryServicesBackupItem : Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.

    https://docs.microsoft.com/en-us/powershell/module/az.recoveryservices/restore-azrecoveryservicesbackupitem?view=azps-2.6.0

    Here I don't find any examples related to Azure File Share. Can anyone please help.

    Thursday, August 29, 2019 2:27 PM

Answers

  • Try the following script

    --------------------------------

    #region: Declare variables 
        $rsvName = "xxxxxx"
        $storageAccountRgName = "xxxxxx"
        $storageAccountName = "xxxxxxx"
        $fileShareName = "xxxxxxxx"
    #endregion

    #region
        #Get recovery services vault and set it as default
        Get-AzureRmRecoveryServicesVault -Name $rsvName | Set-AzureRmRecoveryServicesVaultContext

        #Get Backup container
        $container = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureStorage -Status Registered -FriendlyName $storageAccountName

        #Get backup items
        $BackupItem = Get-AzureRmRecoveryServicesBackupItem -Container $container -WorkloadType AzureFiles

        #Select a Recovery Point
        $recoveryPoint = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $BackupItem | Out-GridView -Title "Select a recovery point to restore from" -PassThru

        #Restore to original location
        Restore-AzureRmRecoveryServicesBackupItem `
            -RecoveryPoint $recoveryPoint `
            -StorageAccountName $storageAccountName `
            -StorageAccountResourceGroupName $storageAccountRgName `
            -TargetFileShareName $fileShareName `
            -ResolveConflict Overwrite `
            -Verbose    
    #endregion

    • Proposed as answer by Rohan Islam Friday, August 30, 2019 8:39 AM
    • Marked as answer by Askwizard Tuesday, September 3, 2019 8:56 AM
    Friday, August 30, 2019 8:38 AM
  • This is another way of doing with Az module

    #Runbook created by Askwizard
    #region: Connect to Azure ==========>>
    $Thumbprint = ""
    $TenantId = ""
    $ApplicationId = ""
    Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId -ServicePrincipal
    #region: End Region ===========>>
    #region: Get the recovery services vault and make it as default
    $vault = Get-AzRecoveryServicesVault -ResourceGroupName "BKUP-RG" -Name "Backup-Vault"
    Set-AzRecoveryServicesVaultContext -Vault $vault
    #region: End Region
    #Get Backup Container
    $Container = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureStorage" -Status "Registered" -FriendlyName "azw" -VaultId $vault.ID
    #Get Backup Item
    $BackupItem = Get-AzRecoveryServicesBackupItem -Container $Container -WorkloadType AzureFiles -VaultId $vault.ID
    #Set the date
    $StartDate = (Get-Date).AddDays(-3)
    $EndDate = Get-Date
    #Get the recovery point of n-1
    $RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartDate $StartDate.ToUniversalTime() -EndDate $EndDate.ToUniversalTime() -VaultId $vault.ID
    #Restore the backup from the recovery point of n-1
    Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[1] -ResolveConflict "Overwrite" -TargetStorageAccountName azwstd -TargetFileShareName "database"

    • Marked as answer by Askwizard Tuesday, September 3, 2019 9:08 AM
    Tuesday, September 3, 2019 9:07 AM

All replies

  • Try the following script

    --------------------------------

    #region: Declare variables 
        $rsvName = "xxxxxx"
        $storageAccountRgName = "xxxxxx"
        $storageAccountName = "xxxxxxx"
        $fileShareName = "xxxxxxxx"
    #endregion

    #region
        #Get recovery services vault and set it as default
        Get-AzureRmRecoveryServicesVault -Name $rsvName | Set-AzureRmRecoveryServicesVaultContext

        #Get Backup container
        $container = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureStorage -Status Registered -FriendlyName $storageAccountName

        #Get backup items
        $BackupItem = Get-AzureRmRecoveryServicesBackupItem -Container $container -WorkloadType AzureFiles

        #Select a Recovery Point
        $recoveryPoint = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $BackupItem | Out-GridView -Title "Select a recovery point to restore from" -PassThru

        #Restore to original location
        Restore-AzureRmRecoveryServicesBackupItem `
            -RecoveryPoint $recoveryPoint `
            -StorageAccountName $storageAccountName `
            -StorageAccountResourceGroupName $storageAccountRgName `
            -TargetFileShareName $fileShareName `
            -ResolveConflict Overwrite `
            -Verbose    
    #endregion

    • Proposed as answer by Rohan Islam Friday, August 30, 2019 8:39 AM
    • Marked as answer by Askwizard Tuesday, September 3, 2019 8:56 AM
    Friday, August 30, 2019 8:38 AM
  • This is another way of doing with Az module

    #Runbook created by Askwizard
    #region: Connect to Azure ==========>>
    $Thumbprint = ""
    $TenantId = ""
    $ApplicationId = ""
    Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -Tenant $TenantId -ServicePrincipal
    #region: End Region ===========>>
    #region: Get the recovery services vault and make it as default
    $vault = Get-AzRecoveryServicesVault -ResourceGroupName "BKUP-RG" -Name "Backup-Vault"
    Set-AzRecoveryServicesVaultContext -Vault $vault
    #region: End Region
    #Get Backup Container
    $Container = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureStorage" -Status "Registered" -FriendlyName "azw" -VaultId $vault.ID
    #Get Backup Item
    $BackupItem = Get-AzRecoveryServicesBackupItem -Container $Container -WorkloadType AzureFiles -VaultId $vault.ID
    #Set the date
    $StartDate = (Get-Date).AddDays(-3)
    $EndDate = Get-Date
    #Get the recovery point of n-1
    $RP = Get-AzRecoveryServicesBackupRecoveryPoint -Item $BackupItem -StartDate $StartDate.ToUniversalTime() -EndDate $EndDate.ToUniversalTime() -VaultId $vault.ID
    #Restore the backup from the recovery point of n-1
    Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[1] -ResolveConflict "Overwrite" -TargetStorageAccountName azwstd -TargetFileShareName "database"

    • Marked as answer by Askwizard Tuesday, September 3, 2019 9:08 AM
    Tuesday, September 3, 2019 9:07 AM