Introduction
The purpose of this document is to describe the process to take automated on-demand snapshots for Azure File Share.
Snapshot for Azure File Share is now in General Availability. Previously, Azure File Share did not have any backup option. In case of the File Share getting deleted, there was no mechanism to recover the File Share and the data was lost. The File Share Snapshot helps organizations take on-demand snapshot backups of the existing File Share for restoring it later as and when required. This document describes automating this process.
Pre-requisites
- Subscription contributor
- Implementation Steps
Step 1. Search for Automation Account in the Resource Blade and open the Automation Account Service.
Step 2. Click on + Create to create a new Automation Account.
Step 3. Fill in the below details and click on Next.
Step 4. Select the System Assigned checkbox which will assign a System-assigned Managed Identity to this Automation account. Click on Next.
Step 5. Select Private Access which will enable us to create a Private Endpoint to this NFS Storage.
Step 6. Provide the Tags and click Review + Create to validate and create the Automation Account.
Step 7. Once the resource has been created, go to the resource, click on Runbooks à + Create a Runbook. This runbook is for creating new snapshots.
Step 8. Provide the Runbook Name, Type, Version, and Description, and click on Review + Create to create the Runbook.
Step 9. This will create the Runbook and open the playground to save our code. In the playground, save the below code.
Connect-AzAccount -Identity
$StorageAccounts = Get-AzStorageAccount
Write-Output $StorageAccounts
foreach ($sa in $StorageAccounts) {
$shares = $null
Write-Host "Looking for NFS shares in Storage Account: $($sa.StorageAccountName)"
$shares = Get-AzRmStorageShare -StorageAccountName $sa.StorageAccountName -ResourceGroupName $sa.ResourceGroupName -ErrorAction SilentlyContinue | ?{ $_.EnabledProtocols -eq "NFS" }
foreach ($nfsshare in $shares) {
Write-Host "*** Found NFS Share: $($nfsshare.Name)"
Write-Host "Creating Snapshot...`n"
New-AzRmStorageShare -StorageAccountName $sa.StorageAccountName -ResourceGroupName $sa.ResourceGroupName -Name $nfsshare.Name -Snapshot -ErrorAction Continue
}
if ($shares -ne $null) {
Get-AzRmStorageShare -StorageAccountName $sa.StorageAccountName -ResourceGroupName $sa.ResourceGroupName -IncludeSnapshot | ?{ $_.EnabledProtocols -eq "NFS" -and $_.SnapshotTime -ne $null } | Sort-Object SnapshotTime -Descending
}
}
Step 10. Click on Schedule click on + Add a schedule.
Step 11. Click on Schedule as shown in the snapshot below.
Step 12. Click on + Add a Schedule.
Step 13. Provide the schedule for the Automation account to execute the Runbook and click on Create to create a schedule.