Manage Azure file share backups with PowerShell
This article describes how to use Azure PowerShell to manage and monitor the Azure file shares that are backed up by the Azure Backup service.
Warning
Make sure the PowerShell version is upgraded to the minimum version for 'Az.RecoveryServices 2.6.0' for AFS backups. For more details, refer to the section outlining the requirement for this change.
Modify the protection policy
To change the policy used for backing up the Azure file share, use Enable-AzRecoveryServicesBackupProtection. Specify the relevant backup item and the new backup policy.
The following example changes the testAzureFS protection policy from dailyafs to monthlyafs.
$monthlyafsPol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "monthlyafs"
$afsContainer = Get-AzRecoveryServicesBackupContainer -FriendlyName "testStorageAcct" -ContainerType AzureStorage
$afsBkpItem = Get-AzRecoveryServicesBackupItem -Container $afsContainer -WorkloadType AzureFiles -Name "testAzureFS"
Enable-AzRecoveryServicesBackupProtection -Item $afsBkpItem -Policy $monthlyafsPol
Track backup and restore jobs
On-demand backup and restore operations return a job along with an ID, as shown when you run an on-demand backup. Use the Get-AzRecoveryServicesBackupJobDetails cmdlet to track the job progress and details.
$job = Get-AzRecoveryServicesBackupJob -JobId 00000000-6c46-496e-980a-3740ccb2ad75 -VaultId $vaultID
$job | fl
IsCancellable : False
IsRetriable : False
ErrorDetails : {Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.AzureFileShareJobErrorInfo}
ActivityId : 00000000-5b71-4d73-9465-8a4a91f13a36
JobId : 00000000-6c46-496e-980a-3740ccb2ad75
Operation : Restore
Status : Failed
WorkloadName : testAFS
StartTime : 12/10/2018 9:56:38 AM
EndTime : 12/10/2018 11:03:03 AM
Duration : 01:06:24.4660027
BackupManagementType : AzureStorage
$job.ErrorDetails
ErrorCode ErrorMessage Recommendations
--------- ------------ ---------------
1073871825 Azure Backup encountered an internal error. Wait for a few minutes and then try the operation again. If the issue persists, please contact Microsoft support.
Stop protection on a file share
There are two ways to stop protecting Azure file shares:
- Stop all future backup jobs and delete all recovery points
- Stop all future backup jobs but leave the recovery points
There may be a cost associated with leaving the recovery points in storage, as the underlying snapshots created by Azure Backup will be retained. However, the benefit of leaving the recovery points is you can restore the file share later, if desired. For information about the cost of leaving the recovery points, see the pricing details. If you choose to delete all recovery points, you can't restore the file share.
Stop protection and retain recovery points
To stop protection while retaining data, use the Disable-AzRecoveryServicesBackupProtection cmdlet.
The following example stops protection for the afsfileshare file share but retains all recovery points:
$vaultID = Get-AzRecoveryServicesVault -ResourceGroupName "afstesting" -Name "afstest" | select -ExpandProperty ID
$bkpItem = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureStorage -WorkloadType AzureFiles -Name "afsfileshare" -VaultId $vaultID
Disable-AzRecoveryServicesBackupProtection -Item $bkpItem -VaultId $vaultID
WorkloadName Operation Status StartTime EndTime JobID
------------ --------- ------ --------- ------- -----
afsfileshare DisableBackup Completed 1/26/2020 2:43:59 PM 1/26/2020 2:44:21 PM 98d9f8a1-54f2-4d85-8433-c32eafbd793f
The Job ID attribute in the output corresponds to the Job ID of the job that's created by the backup service for your “stop protection” operation. To track the status of the job, use the Get-AzRecoveryServicesBackupJob cmdlet.
Stop protection without retaining recovery points
To stop protection without retaining recovery points, use the Disable-AzRecoveryServicesBackupProtection cmdlet and add the -RemoveRecoveryPoints parameter.
The following example stops protection for the afsfileshare file share without retaining recovery points:
$vaultID = Get-AzRecoveryServicesVault -ResourceGroupName "afstesting" -Name "afstest" | select -ExpandProperty ID
$bkpItem = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureStorage -WorkloadType AzureFiles -Name "afsfileshare" -VaultId $vaultID
Disable-AzRecoveryServicesBackupProtection -Item $bkpItem -VaultId $vaultID -RemoveRecoveryPoints
WorkloadName Operation Status StartTime EndTime JobID
------------ --------- ------ --------- ------- -----
afsfileshare DeleteBackupData Completed 1/26/2020 2:50:57 PM 1/26/2020 2:51:39 PM b1a61c0b-548a-4687-9d15-9db1cc5bcc85
Next steps
Learn about managing Azure file share backups in the Azure portal.