Lab 12: Protect and recover your data¶
At a glance
- Time: about 75 minutes
- Region: Southeast Asia 3 (all resources)
- You create: 1 Ubuntu VM, 1 Recovery Services vault, 1 snapshot, 1 restored disk, 1 storage account
- Cost: a few cents in total, if you delete everything at the end
What you will learn¶
- What a Recovery Services vault is, and how a backup policy describes when to back up and how long to keep it.
- How to protect a VM disk with a snapshot, and how to restore it by swapping the OS disk.
- How to recover a file from an Azure Files snapshot.
- How to recover a deleted or overwritten blob with soft delete and versioning.
What is different in this environment
- You create the vault and a backup policy, but you don't back up anything to it. Backed-up data can't be deleted straight away: Azure keeps it for 14 days after you stop the backup, and the vault can't be deleted until that time is over. Your trainer shows a real VM backup as a demonstration.
- You restore the VM with a snapshot instead of a vault backup.
- There is no file and folder backup. That agent runs on Windows only, and your VMs run Ubuntu.
- Azure Site Recovery and Backup reports are not part of this lab.
- Storage uses locally-redundant storage (LRS).
Do not turn on backup
Several forms offer an Enable backup option, for the VM and for a file share. Leave it off in every form. In this environment, enabling backup is blocked with [LAB-P02-RESOURCE-TYPE], because backed-up data can't be deleted for 14 days. If a form shows that error for a backup step, the VM or share itself is still created. Check that it exists, and carry on.
Before you start¶
- You are signed in to the lab directory (Getting started).
- Your lab resource group is
rg-CLOUD-LAB-GRP-N. ReplaceNwith your group number. - Delete the resources from Lab 08 and Lab 11. Each group may have only 1 storage account and 1 vault, so delete your storage account from Lab 07 too.
Names used in this lab¶
| Resource | Name |
|---|---|
| Virtual machine | lab-vm1 |
| Recovery Services vault | rsv-grp-N |
| Backup policy | lab-vm-daily |
| Snapshot | lab-snap1 |
| Restored disk | lab-restored-disk |
| Storage account | stgrpN plus 5 random letters or digits |
| File share | lab-share |
| Blob container | lab-data |
Task 1: Create a VM to protect¶
- Search for Virtual machines and select Create → Azure virtual machine.
-
On Basics:
Setting Value Resource group rg-CLOUD-LAB-GRP-NVirtual machine name lab-vm1Region Southeast Asia 3 Availability options No infrastructure redundancy required Security type Standard Image Ubuntu Server 24.04 LTS - x64 Gen2 Size Standard_B1s Authentication type Password Username azureuserPassword the password your trainer gives you Public inbound ports None -
On Disks, set OS disk type to Standard SSD (locally-redundant storage).
- On Networking, create a new virtual network named
lab-vnetwith the defaults. Set Public IP to None and NIC network security group to None. Select Delete NIC when VM is deleted. - On Management, make sure Enable backup is not selected.
- On Monitoring, set Boot diagnostics to Disable.
- Select Review + create, then Create. Go on with Task 2 while it deploys.
Task 2: Create a vault and a backup policy¶
- Search for Recovery Services vaults and select + Create.
-
On Basics:
Setting Value Resource group rg-CLOUD-LAB-GRP-NVault name rsv-grp-NRegion Southeast Asia 3 -
On the Redundancy tab, select Locally-redundant storage and clear Cross Region Restore if it is shown. Take the defaults on the other tabs, then select Review + create and Create.
Why LRS
A vault stores copies of your backups. The default is geo-redundant, which keeps six copies and costs more. For a lab, three copies in one region are enough.
-
When it finishes, open the vault and look around:
- Overview: it has two parts, Backup and Site Recovery. You use neither today.
- Settings → Properties → Security settings → Update: check that soft delete is Enabled. Note the number of days. Don't change anything on this page.
-
Select Manage → Backup policies, then + Add. Choose Azure Virtual Machine and create a Standard policy:
Setting Value Policy name lab-vm-dailyFrequency Daily, at a time you choose Retain instant recovery snapshots for 2daysRetention of daily backup point 7days -
Select Create.
Two settings you can't take back
Setting the vault immutability to Locked, or setting soft delete to always-on, can never be undone, so the vault could never be deleted. Both are blocked here with [LAB-P18-VAULT-SECURITY]. Don't try them.
Think about it
The policy says how often to back up and how long to keep each copy. What would you choose for a database that changes every minute? What is the cost of keeping copies for a very long time?
Task 3: Restore a VM from a snapshot¶
A snapshot is a read-only copy of a disk at one moment. It isn't a vault backup, but you can use it to go back to that moment.
Put a file on the VM¶
- Open
lab-vm1. Check that Status is Running. - Under Operations, select Run command → RunShellScript.
-
Paste this script and select Run:
echo "This file is important" > /home/azureuser/important.txt ls -l /home/azureuser -
Check that the output lists
important.txt.
Take the snapshot¶
- On the VM, select Settings → Disks, then select the OS disk.
-
Select Create snapshot and set:
Setting Value Resource group rg-CLOUD-LAB-GRP-NName lab-snap1Region Southeast Asia 3 Snapshot type Incremental Storage type Standard HDD -
Select Review + create, then Create.
Standard HDD only
The default can be Premium SSD, which isn't allowed. The deployment is then blocked with
[LAB-P04B-SNAPSHOT].
Lose the file¶
-
Open Run command → RunShellScript again and run:
rm /home/azureuser/important.txt ls -l /home/azureuser -
Check that
important.txtis gone.
Restore from the snapshot¶
- Open the snapshot
lab-snap1and select Create disk. - Set the name to
lab-restored-disk, the Region to Southeast Asia 3, and the Disk SKU to Standard SSD (locally-redundant storage). Select Review + create, then Create. - Open
lab-vm1and select Stop. Wait until its status is Stopped (deallocated). - Select Settings → Disks → Swap OS disk. Choose
lab-restored-disk, type the VM name to confirm, and select OK. -
Select Start. When the VM is Running, wait a minute for the VM agent, then run again:
ls -l /home/azureuser -
Check that
important.txtis back.
Think about it
What did the snapshot not protect you from? Think about changes made after the snapshot, and about a snapshot that sits in the same resource group as the disk.
Task 4: Recover a file from an Azure Files snapshot¶
- Search for Storage accounts and select + Create.
-
On Basics:
Setting Value Resource group rg-CLOUD-LAB-GRP-NStorage account name stgrpNplus 5 random letters or digitsRegion Southeast Asia 3 Preferred storage type Azure Blob Storage or Azure Data Lake Storage Gen 2 Performance Standard Redundancy Locally-redundant storage (LRS) -
Take the defaults on the other tabs, including Data protection. Select Review + create, then Create.
- Open the storage account. Under Data storage, select File shares, then + File share.
- On Basics, set the name to
lab-share. Open the Backup tab and clear Enable backup. Select Review + create, then Create. - Open the share and select Upload. Upload any small file from your computer, for example a text file named
notes.txt. - In the share, select Operations → Snapshots → + Add snapshot. Select OK.
- Go back to Browse, select
notes.txtand select Delete. Check that the share is empty. - Go to Snapshots and open your snapshot. Select
notes.txt, then Restore. Choose Overwrite original file and select OK. - Go back to Browse and check that
notes.txtis back.
A share can also be undeleted
Under the storage account's Data protection page, soft delete for file shares is on. A deleted share stays recoverable for the number of days set there.
Task 5: Recover a blob¶
- In the storage account, open Data management → Data protection.
- Check that Enable soft delete for blobs is on, and set the days to
7. Select Enable versioning for blobs. Select Save. - Under Data storage, select Containers, then + Container. Name it
lab-dataand leave Anonymous access level at Private. Select Create. - Open the container and select Upload. Upload a small text file named
report.txt. - Edit
report.txton your computer, change its text, and upload it again with Overwrite if files already exist selected. - Select
report.txt, then the Versions tab. You should see two versions. Select the older one and choose Make current version. - Select
report.txtand select Delete. Confirm. - Select Show deleted blobs. Select the deleted
report.txtand select Undelete. - Check that
report.txtis back in the list.
Think about it
Soft delete and versions are stored in the same account as your data. What would protect you if the whole storage account was deleted?
Check your work¶
- The vault
rsv-grp-Nexists and has the policylab-vm-daily, and nothing is backed up to it. -
important.txtwas missing after you deleted it, and back after you swapped the OS disk. -
notes.txtwas restored from the file share snapshot. -
report.txtwas recovered from a version and from soft delete.
Clean up¶
- Delete the storage account.
- Delete the VM
lab-vm1. Make sure the OS disk and network interface are selected, so they are deleted too. - In your resource group, delete the remaining disks (the original OS disk and
lab-restored-disk), the snapshotlab-snap1, and the virtual networklab-vnet. - Open the vault
rsv-grp-Nand select Delete. Confirm with the vault name. - Check that your resource group is empty.
Key points¶
- A vault stores backups in Azure, and a policy sets the schedule and how long copies are kept. Create and plan before you protect anything.
- A snapshot is quick and cheap, but it lives next to the original. A vault keeps backups separate.
- Soft delete keeps deleted data for a while, and versions keep older copies of a blob. Together they protect against mistakes, but not against deleting the whole account.
- Backed-up data stays for 14 days after you stop the backup, so plan the clean-up of real backups.
- Immutability and always-on soft delete can't be undone. Use them only when you are sure.