Skip to content

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).
Diagram: a disk snapshot restored by swapping the OS disk, an Azure Files share snapshot, blob soft delete and versions, and a Recovery Services vault with a backup policy where enabling backup is blocked.
Four ways to protect and recover data: snapshots, share snapshots, soft delete, and an empty vault with a policy. Select the diagram to open it full size.

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. Replace N with 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

  1. Search for Virtual machines and select Create → Azure virtual machine.
  2. On Basics:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Virtual machine name lab-vm1
    Region 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 azureuser
    Password the password your trainer gives you
    Public inbound ports None
  3. On Disks, set OS disk type to Standard SSD (locally-redundant storage).

  4. On Networking, create a new virtual network named lab-vnet with the defaults. Set Public IP to None and NIC network security group to None. Select Delete NIC when VM is deleted.
  5. On Management, make sure Enable backup is not selected.
  6. On Monitoring, set Boot diagnostics to Disable.
  7. Select Review + create, then Create. Go on with Task 2 while it deploys.

Task 2: Create a vault and a backup policy

  1. Search for Recovery Services vaults and select + Create.
  2. On Basics:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Vault name rsv-grp-N
    Region Southeast Asia 3
  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.

  4. 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.
  5. Select Manage → Backup policies, then + Add. Choose Azure Virtual Machine and create a Standard policy:

    Setting Value
    Policy name lab-vm-daily
    Frequency Daily, at a time you choose
    Retain instant recovery snapshots for 2 days
    Retention of daily backup point 7 days
  6. 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

  1. Open lab-vm1. Check that Status is Running.
  2. Under Operations, select Run command → RunShellScript.
  3. Paste this script and select Run:

    echo "This file is important" > /home/azureuser/important.txt
    ls -l /home/azureuser
    
  4. Check that the output lists important.txt.

Take the snapshot

  1. On the VM, select Settings → Disks, then select the OS disk.
  2. Select Create snapshot and set:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Name lab-snap1
    Region Southeast Asia 3
    Snapshot type Incremental
    Storage type Standard HDD
  3. 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

  1. Open Run command → RunShellScript again and run:

    rm /home/azureuser/important.txt
    ls -l /home/azureuser
    
  2. Check that important.txt is gone.

Restore from the snapshot

  1. Open the snapshot lab-snap1 and select Create disk.
  2. 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.
  3. Open lab-vm1 and select Stop. Wait until its status is Stopped (deallocated).
  4. Select Settings → Disks → Swap OS disk. Choose lab-restored-disk, type the VM name to confirm, and select OK.
  5. Select Start. When the VM is Running, wait a minute for the VM agent, then run again:

    ls -l /home/azureuser
    
  6. Check that important.txt is 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

  1. Search for Storage accounts and select + Create.
  2. On Basics:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Storage account name stgrpN plus 5 random letters or digits
    Region Southeast Asia 3
    Preferred storage type Azure Blob Storage or Azure Data Lake Storage Gen 2
    Performance Standard
    Redundancy Locally-redundant storage (LRS)
  3. Take the defaults on the other tabs, including Data protection. Select Review + create, then Create.

  4. Open the storage account. Under Data storage, select File shares, then + File share.
  5. On Basics, set the name to lab-share. Open the Backup tab and clear Enable backup. Select Review + create, then Create.
  6. Open the share and select Upload. Upload any small file from your computer, for example a text file named notes.txt.
  7. In the share, select Operations → Snapshots → + Add snapshot. Select OK.
  8. Go back to Browse, select notes.txt and select Delete. Check that the share is empty.
  9. Go to Snapshots and open your snapshot. Select notes.txt, then Restore. Choose Overwrite original file and select OK.
  10. Go back to Browse and check that notes.txt is 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

  1. In the storage account, open Data management → Data protection.
  2. Check that Enable soft delete for blobs is on, and set the days to 7. Select Enable versioning for blobs. Select Save.
  3. Under Data storage, select Containers, then + Container. Name it lab-data and leave Anonymous access level at Private. Select Create.
  4. Open the container and select Upload. Upload a small text file named report.txt.
  5. Edit report.txt on your computer, change its text, and upload it again with Overwrite if files already exist selected.
  6. Select report.txt, then the Versions tab. You should see two versions. Select the older one and choose Make current version.
  7. Select report.txt and select Delete. Confirm.
  8. Select Show deleted blobs. Select the deleted report.txt and select Undelete.
  9. Check that report.txt is 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-N exists and has the policy lab-vm-daily, and nothing is backed up to it.
  • important.txt was missing after you deleted it, and back after you swapped the OS disk.
  • notes.txt was restored from the file share snapshot.
  • report.txt was recovered from a version and from soft delete.

Clean up

  1. Delete the storage account.
  2. Delete the VM lab-vm1. Make sure the OS disk and network interface are selected, so they are deleted too.
  3. In your resource group, delete the remaining disks (the original OS disk and lab-restored-disk), the snapshot lab-snap1, and the virtual network lab-vnet.
  4. Open the vault rsv-grp-N and select Delete. Confirm with the vault name.
  5. 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.