Skip to content

Commit b4e67bc

Browse files
authored
Merge pull request #102358 from dcurwin/stop-afs-ps
Stop AFS backup in Powershell
2 parents ebfd4fe + cd54a4d commit b4e67bc

File tree

4 files changed

+223
-148
lines changed

4 files changed

+223
-148
lines changed

articles/backup/backup-azure-afs-automation.md

Lines changed: 4 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: Back up and restore Azure Files with PowerShell
3-
description: In this article, learn how to back up and restore Azure Files using the Azure Backup service and PowerShell.
2+
title: Back up Azure Files with PowerShell
3+
description: In this article, learn how to back up Azure Files using the Azure Backup service and PowerShell.
44
ms.topic: conceptual
55
ms.date: 08/20/2019
66
---
77

8-
# Back up and restore Azure Files with PowerShell
8+
# Back up Azure Files with PowerShell
99

10-
This article describes how to use Azure PowerShell to back up and recover an Azure Files file share using an [Azure Backup](backup-overview.md) Recovery Services vault.
10+
This article describes how to use Azure PowerShell to back up an Azure Files file share using an [Azure Backup](backup-overview.md) Recovery Services vault.
1111

1212
This article explains how to:
1313

@@ -17,8 +17,6 @@ This article explains how to:
1717
> * Create a Recovery Services vault.
1818
> * Configure backup for an Azure file share.
1919
> * Run a backup job.
20-
> * Restore a backed up Azure file share, or an individual file from a share.
21-
> * Monitor backup and restore jobs.
2220
2321
## Before you start
2422

@@ -270,148 +268,6 @@ On-demand backups can be used to retain your snapshots for 10 years. Schedulers
270268

271269
If you are looking for sample scripts, you can refer to the sample script on GitHub (<https://github.com/Azure-Samples/Use-PowerShell-for-long-term-retention-of-Azure-Files-Backup>) using Azure Automation runbook that enables you to schedule backups on a periodic basis and retain them even up to 10 years.
272270

273-
### Modify the protection policy
274-
275-
To change the policy used for backing up the Azure file share, use [Enable-AzRecoveryServicesBackupProtection](https://docs.microsoft.com/powershell/module/az.recoveryservices/enable-azrecoveryservicesbackupprotection?view=azps-1.4.0). Specify the relevant backup item and the new backup policy.
276-
277-
The following example changes the **testAzureFS** protection policy from **dailyafs** to **monthlyafs**.
278-
279-
```powershell
280-
$monthlyafsPol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "monthlyafs"
281-
$afsContainer = Get-AzRecoveryServicesBackupContainer -FriendlyName "testStorageAcct" -ContainerType AzureStorage
282-
$afsBkpItem = Get-AzRecoveryServicesBackupItem -Container $afsContainer -WorkloadType AzureFiles -Name "testAzureFS"
283-
Enable-AzRecoveryServicesBackupProtection -Item $afsBkpItem -Policy $monthlyafsPol
284-
```
285-
286-
## Restore Azure file shares and files
287-
288-
You can restore an entire file share or specific files on the share. You can restore to the original location, or to an alternate location.
289-
290-
### Fetch recovery points
291-
292-
Use [Get-AzRecoveryServicesBackupRecoveryPoint](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackuprecoverypoint?view=azps-1.4.0) to list all recovery points for the backed-up item.
293-
294-
In the following script:
295-
296-
* The variable **$rp** is an array of recovery points for the selected backup item from the past seven days.
297-
* The array is sorted in reverse order of time with the latest recovery point at index **0**.
298-
* Use standard PowerShell array indexing to pick the recovery point.
299-
* In the example, **$rp[0]** selects the latest recovery point.
300-
301-
```powershell
302-
$startDate = (Get-Date).AddDays(-7)
303-
$endDate = Get-Date
304-
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $afsBkpItem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime()
305-
306-
$rp[0] | fl
307-
```
308-
309-
The output is similar to the following.
310-
311-
```powershell
312-
FileShareSnapshotUri : https://testStorageAcct.file.core.windows.net/testAzureFS?sharesnapshot=2018-11-20T00:31:04.00000
313-
00Z
314-
RecoveryPointType : FileSystemConsistent
315-
RecoveryPointTime : 11/20/2018 12:31:05 AM
316-
RecoveryPointId : 86593702401459
317-
ItemName : testAzureFS
318-
Id : /Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testVaultRG/providers/Micros oft.RecoveryServices/vaults/testVault/backupFabrics/Azure/protectionContainers/StorageContainer;storage;teststorageRG;testStorageAcct/protectedItems/AzureFileShare;testAzureFS/recoveryPoints/86593702401462
319-
WorkloadType : AzureFiles
320-
ContainerName : storage;teststorageRG;testStorageAcct
321-
ContainerType : AzureStorage
322-
BackupManagementType : AzureStorage
323-
```
324-
325-
After the relevant recovery point is selected, you restore the file share or file to the original location, or to an alternate location.
326-
327-
### Restore an Azure file share to an alternate location
328-
329-
Use the [Restore-AzRecoveryServicesBackupItem](https://docs.microsoft.com/powershell/module/az.recoveryservices/restore-azrecoveryservicesbackupitem?view=azps-1.4.0) to restore to the selected recovery point. Specify these parameters to identify the alternate location:
330-
331-
* **TargetStorageAccountName**: The storage account to which the backed-up content is restored. The target storage account must be in the same location as the vault.
332-
* **TargetFileShareName**: The file shares within the target storage account to which the backed-up content is restored.
333-
* **TargetFolder**: The folder under the file share to which data is restored. If the backed-up content is to be restored to a root folder, give the target folder values as an empty string.
334-
* **ResolveConflict**: Instruction if there's a conflict with the restored data. Accepts **Overwrite** or **Skip**.
335-
336-
Run the cmdlet with the parameters as follows:
337-
338-
```powershell
339-
Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -TargetStorageAccountName "TargetStorageAcct" -TargetFileShareName "DestAFS" -TargetFolder "testAzureFS_restored" -ResolveConflict Overwrite
340-
```
341-
342-
The command returns a job with an ID to be tracked, as shown in the following example.
343-
344-
```powershell
345-
WorkloadName Operation Status StartTime EndTime JobID
346-
------------ --------- ------ --------- ------- -----
347-
testAzureFS Restore InProgress 12/10/2018 9:56:38 AM 9fd34525-6c46-496e-980a-3740ccb2ad75
348-
```
349-
350-
### Restore an Azure file to an alternate location
351-
352-
Use the [Restore-AzRecoveryServicesBackupItem](https://docs.microsoft.com/powershell/module/az.recoveryservices/restore-azrecoveryservicesbackupitem?view=azps-1.4.0) to restore to the selected recovery point. Specify these parameters to identify the alternate location, and to uniquely identify the file you want to restore.
353-
354-
* **TargetStorageAccountName**: The storage account to which the backed-up content is restored. The target storage account must be in the same location as the vault.
355-
* **TargetFileShareName**: The file shares within the target storage account to which the backed-up content is restored.
356-
* **TargetFolder**: The folder under the file share to which data is restored. If the backed-up content is to be restored to a root folder, give the target folder values as an empty string.
357-
* **SourceFilePath**: The absolute path of the file, to be restored within the file share, as a string. This path is the same path used in the **Get-AzStorageFile** PowerShell cmdlet.
358-
* **SourceFileType**: Whether a directory or a file is selected. Accepts **Directory** or **File**.
359-
* **ResolveConflict**: Instruction if there's a conflict with the restored data. Accepts **Overwrite** or **Skip**.
360-
361-
The additional parameters (SourceFilePath and SourceFileType) are related only to the individual file you want to restore.
362-
363-
```powershell
364-
Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -TargetStorageAccountName "TargetStorageAcct" -TargetFileShareName "DestAFS" -TargetFolder "testAzureFS_restored" -SourceFileType File -SourceFilePath "TestDir/TestDoc.docx" -ResolveConflict Overwrite
365-
```
366-
367-
This command returns a job with an ID to be tracked, as shown in the previous section.
368-
369-
### Restore Azure file shares and files to the original location
370-
371-
When you restore to an original location, you don't need to specify destination- and target-related parameters. Only **ResolveConflict** must be provided.
372-
373-
#### Overwrite an Azure file share
374-
375-
```powershell
376-
Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -ResolveConflict Overwrite
377-
```
378-
379-
#### Overwrite an Azure file
380-
381-
```powershell
382-
Restore-AzRecoveryServicesBackupItem -RecoveryPoint $rp[0] -SourceFileType File -SourceFilePath "TestDir/TestDoc.docx" -ResolveConflict Overwrite
383-
```
384-
385-
## Track backup and restore jobs
386-
387-
On-demand backup and restore operations return a job along with an ID, as shown when you [ran an on-demand backup](#trigger-an-on-demand-backup). Use the [Get-AzRecoveryServicesBackupJobDetails](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupjob?view=azps-1.4.0) cmdlet to track the job progress and details.
388-
389-
```powershell
390-
$job = Get-AzRecoveryServicesBackupJob -JobId 00000000-6c46-496e-980a-3740ccb2ad75 -VaultId $vaultID
391-
392-
$job | fl
393-
394-
395-
IsCancellable : False
396-
IsRetriable : False
397-
ErrorDetails : {Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.AzureFileShareJobErrorInfo}
398-
ActivityId : 00000000-5b71-4d73-9465-8a4a91f13a36
399-
JobId : 00000000-6c46-496e-980a-3740ccb2ad75
400-
Operation : Restore
401-
Status : Failed
402-
WorkloadName : testAFS
403-
StartTime : 12/10/2018 9:56:38 AM
404-
EndTime : 12/10/2018 11:03:03 AM
405-
Duration : 01:06:24.4660027
406-
BackupManagementType : AzureStorage
407-
408-
$job.ErrorDetails
409-
410-
ErrorCode ErrorMessage Recommendations
411-
--------- ------------ ---------------
412-
1073871825 Microsoft 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.
413-
```
414-
415271
## Next steps
416272

417273
[Learn about](backup-afs.md) backing up Azure Files in the Azure portal.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Manage Azure file share backups with PowerShell
3+
description: Learn how to use PowerShell to manage and monitor Azure file shares backed up by the Azure Backup service.
4+
ms.topic: conceptual
5+
ms.date: 1/27/2020
6+
---
7+
8+
# Manage Azure file share backups with PowerShell
9+
10+
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.
11+
12+
## Modify the protection policy
13+
14+
To change the policy used for backing up the Azure file share, use [Enable-AzRecoveryServicesBackupProtection](https://docs.microsoft.com/powershell/module/az.recoveryservices/enable-azrecoveryservicesbackupprotection?view=azps-1.4.0). Specify the relevant backup item and the new backup policy.
15+
16+
The following example changes the **testAzureFS** protection policy from **dailyafs** to **monthlyafs**.
17+
18+
```powershell
19+
$monthlyafsPol = Get-AzRecoveryServicesBackupProtectionPolicy -Name "monthlyafs"
20+
$afsContainer = Get-AzRecoveryServicesBackupContainer -FriendlyName "testStorageAcct" -ContainerType AzureStorage
21+
$afsBkpItem = Get-AzRecoveryServicesBackupItem -Container $afsContainer -WorkloadType AzureFiles -Name "testAzureFS"
22+
Enable-AzRecoveryServicesBackupProtection -Item $afsBkpItem -Policy $monthlyafsPol
23+
```
24+
25+
## Track backup and restore jobs
26+
27+
On-demand backup and restore operations return a job along with an ID, as shown when you [run an on-demand backup](backup-azure-afs-automation.md#trigger-an-on-demand-backup). Use the [Get-AzRecoveryServicesBackupJobDetails](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupjob?view=azps-1.4.0) cmdlet to track the job progress and details.
28+
29+
```powershell
30+
$job = Get-AzRecoveryServicesBackupJob -JobId 00000000-6c46-496e-980a-3740ccb2ad75 -VaultId $vaultID
31+
32+
$job | fl
33+
34+
35+
IsCancellable : False
36+
IsRetriable : False
37+
ErrorDetails : {Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.AzureFileShareJobErrorInfo}
38+
ActivityId : 00000000-5b71-4d73-9465-8a4a91f13a36
39+
JobId : 00000000-6c46-496e-980a-3740ccb2ad75
40+
Operation : Restore
41+
Status : Failed
42+
WorkloadName : testAFS
43+
StartTime : 12/10/2018 9:56:38 AM
44+
EndTime : 12/10/2018 11:03:03 AM
45+
Duration : 01:06:24.4660027
46+
BackupManagementType : AzureStorage
47+
48+
$job.ErrorDetails
49+
50+
ErrorCode ErrorMessage Recommendations
51+
--------- ------------ ---------------
52+
1073871825 Microsoft 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.
53+
```
54+
55+
## Stop protection on a file share
56+
57+
There are two ways to stop protecting Azure file shares:
58+
59+
* Stop all future backup jobs and *delete* all recovery points
60+
* Stop all future backup jobs but *leave* the recovery points
61+
62+
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](https://azure.microsoft.com/pricing/details/storage/files/). If you choose to delete all recovery points, you can't restore the file share.
63+
64+
## Stop protection and retain recovery points
65+
66+
To stop protection while retaining data, use the [Disable-AzRecoveryServicesBackupProtection](https://docs.microsoft.com/powershell/module/az.recoveryservices/disable-azrecoveryservicesbackupprotection?view=azps-3.3.0) cmdlet.
67+
68+
The following example stops protection for the *afsfileshare* file share but retains all recovery points:
69+
70+
```powershell
71+
$vaultID = Get-AzRecoveryServicesVault -ResourceGroupName "afstesting" -Name "afstest" | select -ExpandProperty ID
72+
$bkpItem = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureStorage -WorkloadType AzureFiles -Name "afsfileshare" -VaultId $vaultID
73+
Disable-AzRecoveryServicesBackupProtection -Item $bkpItem -VaultId $vaultID
74+
```
75+
76+
```output
77+
WorkloadName Operation Status StartTime EndTime JobID
78+
------------ --------- ------ --------- ------- -----
79+
afsfileshare DisableBackup Completed 1/26/2020 2:43:59 PM 1/26/2020 2:44:21 PM 98d9f8a1-54f2-4d85-8433-c32eafbd793f
80+
```
81+
82+
The Job ID attribute in the output corresponds to the Job ID of the job that is created by the backup service for your “stop protection” operation. To track the status of the job, use the [Get-AzRecoveryServicesBackupJob](https://docs.microsoft.com/powershell/module/az.recoveryservices/get-azrecoveryservicesbackupjob?view=azps-3.3.0) cmdlet.
83+
84+
## Stop protection without retaining recovery points
85+
86+
To stop protection without retaining recovery points, use the [Disable-AzRecoveryServicesBackupProtection](https://docs.microsoft.com/powershell/module/az.recoveryservices/disable-azrecoveryservicesbackupprotection?view=azps-3.3.0) cmdlet and add the **-RemoveRecoveryPoints** parameter.
87+
88+
The following example stops protection for the *afsfileshare* file share without retaining recovery points:
89+
90+
```powershell
91+
$vaultID = Get-AzRecoveryServicesVault -ResourceGroupName "afstesting" -Name "afstest" | select -ExpandProperty ID
92+
$bkpItem = Get-AzRecoveryServicesBackupItem -BackupManagementType AzureStorage -WorkloadType AzureFiles -Name "afsfileshare" -VaultId $vaultID
93+
Disable-AzRecoveryServicesBackupProtection -Item $bkpItem -VaultId $vaultID -RemoveRecoveryPoints
94+
```
95+
96+
```output
97+
WorkloadName Operation Status StartTime EndTime JobID
98+
------------ --------- ------ --------- ------- -----
99+
afsfileshare DeleteBackupData Completed 1/26/2020 2:50:57 PM 1/26/2020 2:51:39 PM b1a61c0b-548a-4687-9d15-9db1cc5bcc85
100+
```
101+
102+
## Next steps
103+
104+
[Learn about](manage-afs-backup.md) managing Azure file share backups in the Azure portal.

0 commit comments

Comments
 (0)