Sunday, 2 June 2024

How to Find and Remove Old Azure Snapshots

How to Find and Remove Old Azure Snapshots

If you have Azure snapshots in your account that are outdated, you can clean them up to lower your monthly cloud costs. In this guide, we'll show you how to find and delete these snapshots.


Snapshots of Azure virtual hard disks (VHD) are point-in-time copies of virtual machines that users can easily revert to when needed, in case of disaster or for troubleshooting purposes.

If you have a snapshot policy that creates them automatically and periodically, they are a convenient recovery option, but if you don’t keep tabs on unnecessary snapshots, the costs can add up. At the time of writing this, the storage costs for snapshots and images are billed at $0.05/GB per month based on the used portion of the disk for both standard options (LRS and ZRS). The premium offering is billed higher at $0.12/GB per month.

For example, if you are storing 1 TB of snapshot data across your organization, that’s an added $50 to your cloud bill each month. You can view your current amount by reviewing your Azure usage report.

In this guide, we’ll show you how to identify and remove old Azure snapshots so you can keep your Azure costs down.

Finding and Deleting Old Azure Snapshots

You can define what qualifies a snapshot as “old” depending on your situation. You can say anything older than 90 days for example. If you want to be cautious about deleting snapshots, you can adjust your soft delete settings to ensure that you can recover any snapshots you have recently deleted.

Using the Azure Portal

By using the Azure portal, you can manually review and delete old snapshots one at a time. Here's how:

1. Log into your Azure service to access old virtual machine (VM) snapshots and identify the number of days configured for each VM.

2. Go to the All resources blade in the Microsoft Azure portal.

3. From Type, select Snapshot to display only VM snapshots created (and charged) according to your initial service setups.

4. Right-click all old snapshots you want to delete, as shown below:

selecting snapshots to delete
Source: Azure Tutorial – Deleting Snapshots

5. Go to Overview to access the configuration details of your selected snapshots.

6. Check DATE CREATED to examine when your selected snapshots were created. Compare the snapshot age with the threshold age identified in Step 1. If the snapshot age is higher than your configured threshold, your verified resource can be considered outdated and should be removed.

7. In Delete Snapshot, confirm you want to remove (delete) your selected snapshot by clicking Yes, as shown below:

delete snapshot button
Source: Azure Tutorial – Deleting Snapshots

Do this for each snapshot you want to delete from your Azure service.

Using the Azure CLI

With the Azure CLI, it's a little easier since you can run a query to find all snapshots that were created before a certain date and then remove them. Here's how:

1. First, use this “az snapshot list” command with a JMESPath query to get a list of all the snapshots before a given date:

az snapshot list \    
--query "[?timeCreated <= '2022-01-01']"

2. Next, you can use this output to then delete each snapshot using the following “az snapshot delete” command:

az snapshot delete [--ids]                   
		   [--name]                   
		   [--resource-group]                   
		   [--subscription]

Just remember to ensure that you want to delete your selected snapshots. Re-provisioning new instances may incur extra charges if you need one or more of your deleted snapshots later on.

Clean Up Old Azure Snapshots Automatically with Blink

If you are creating snapshots automatically, you should have an automated method of cleanup. Otherwise, you’ll need to context-switch regularly just to click through the console or run commands.

With Blink, you can use this automation to identify old Azure snapshots and queue them for removal.

Blink Automation: Ensure Old Snapshots are Deleted If Not Required in Azure

Manage and use snapshots

 

Manage and use snapshots

In this article, learn how to create, use and manage snapshots in Azure App Configuration. Snapshot is a set of App Configuration settings stored in an immutable state.

Prerequisites

Add key-values to the App configuration store

In your App Configuration store, go to Operations > Configuration explorer and add the following key-values. Leave Content Type with its default value. For more information about how to add key-values to a store using the Azure portal or the CLI, go to Create a key-value.

KeyValueLabel
app2/bgcolorLight Graylabel2
app1/colorBlackNo label
app1/colorBluelabel1
app1/colorGreenlabel2
app1/colorYellowlabel3
app1/messageHellolabel1
app1/messageHi!label2
app2/messageGood morning!label1

Create a snapshot

Under Operations > Snapshots, select Create a new snapshot.

  1. Enter a snapshot name and optionally also add Tags.

  2. Under Choose the composition type, keep the default value Key (default).

    • With the Key composition type, if your store has identical keys with different labels, only the key-value specified in the last applicable filter is included in the snapshot. Identical key-values with other labels are left out of the snapshot.
    • With the Key-Label composition type, if your store has identical keys with different labels, all key-values with identical keys but different labels are included in the snapshot depending on the specified filters.
  3. Select Add filters to select the key-values for your snapshot. Filtering is done by selecting filters: EqualsStarts withAny of and All for keys and for labels. You can enter between one and three filters.

    1. Add the first filter:
      • Under Key, select Starts with and enter app1
      • Under Label, select Equals and select label2 from the drop-down menu.
    2. Add the second filter:
      • Under Key, select Starts with and enter app1
      • Under Label, select Equals and select label1 from the drop-down menu.
  4. If you archive a snapshot, by default, it will be retained for 30 days after archival. Optionally, under Recovery options, decrease the number of retention days the snapshot will be available after archival.

     

  5. Select Create to generate the snapshot. In this example, the created snapshot has Key composition type and below filters:

    • Keys that start with app1, with label2 label
    • Keys that start with app1, with label1 label.

    Screenshot of the Create form with data filled as above steps and Create button highlighted.

  6. Check the table to understand which key-values from the configuration store end up in the snapshot based on the provided parameters.

Create sample snapshots

To create sample snapshots and check how the snapshots feature work, use the snapshot sandbox. This sandbox contains sample data you can play with to better understand how snapshot's composition type and filters work.

  1. In Operations > Snapshots > Active snapshots, select Test in sandbox.
  2. Review the sample data and practice creating snapshots by filling out the form with a composition type and one or more filters.
  3. Select Create to generate the sample snapshot.
  4. Check out the snapshot result generated under Generated sample snapshot. The sample snapshot displays all keys that are included in the sample snapshot, according to your selection.

Use snapshots

You can select any number of snapshots for the application's configuration. Selecting a snapshot adds all of its key-values. Once added to a configuration, the key-values from snapshots are treated the same as any other key-value.

If you have an application using Azure App Configuration, you can update it with the following sample code to use snapshots. You only need to provide the name of the snapshot, which is case-sensitive.

Edit the call to the AddAzureAppConfiguration method, which is often found in the Program.cs file of your application. If you don't have an application, you can reference any of the .NET quickstart guides, like creating an ASP.NET core app with Azure App Configuration.

Add snapshots to your configuration

C#
configurationBuilder.AddAzureAppConfiguration(options =>
{
    options.Connect(Environment.GetEnvironmentVariable("ConnectionString"));

    // Select an existing snapshot by name. This will add all of the key-values from the snapshot to this application's configuration.
    options.SelectSnapshot("SnapshotName");
    
    // Other changes to options
});


  • Microsoft.Extensions.Configuration.AzureAppConfiguration
  • Microsoft.Azure.AppConfiguration.AspNetCore
  • Microsoft.Azure.AppConfiguration.Functions.Worker

 

Manage active snapshots

The page under Operations > Snapshots displays two tabs: Active snapshots and Archived snapshots. Select Active snapshots to view the list of all active snapshots in an App Configuration store.

Screenshot of the list of active snapshots.

View existing snapshot

In the Active snapshots tab, select the ellipsis ... on the right of an existing snapshot and select View to view a snapshot. This action opens a Snapshot details page that displays the snapshot's settings and the key-values included in the snapshot.

Screenshot of the detailed view of an active snapshot.

Archive a snapshot

In the Active snapshots tab, select the ellipsis ... on the right of an existing snapshot and select Archive to archive a snapshot. Confirm archival by selecting Yes or cancel with No. Once a snapshot has been archived, a notification appears to confirm the operation and the list of active snapshots is updated.

Screenshot of the archive option in the active snapshots.

Manage archived snapshots

Go to Operations > Snapshots > Archived snapshots to view the list of all archived snapshots in an App Configuration store. Archived snapshots remain accessible for the retention period that was selected during their creation.

Screenshot of the list of archived snapshots.

View archived snapshot

Detailed view of snapshot is available in the archive state as well. In the Archived snapshots tab, select the ellipsis ... on the right of an existing snapshot and select View to view a snapshot. This action opens a Snapshot details page that displays the snapshot's settings and the key-values included in the snapshot.

Screenshot of the detailed view of an archived snapshot.

Recover an archived snapshot

In the Archived snapshots tab, select the ellipsis ... on the right of an archived snapshot and select Recover to recover a snapshot. Once a snapshot has been recovered, a notification appears to confirm the operation and the list of archived snapshots is updated.

Screenshot of the recover option in the archived snapshots.

Microsoft Azure – Creating an OS Disk Snapshot of a Azure VM

 

Microsoft Azure – Creating an OS Disk Snapshot of a Azure VM


snapshot is a kind of actual copy of a VM at a particular point in time.

The purpose of taking a snapshot of an azure VM is to backup the VM data or to recover the VM data in times of critical needs. This snapshot can be used to provision the Azure VM in case of VM failures or VM Crash or else in case of any other business needs. 

Let’s get into the implementation of how we can create an OS Disk Snapshot of a select Azure VM.

Step 1: Log in to Azure Portal

Step 2: Select your Azure VM from Azure Virtual Machines

Step 3: then Navigate to Settings >> Disk >> Select the OS Disk

Step 4: After selecting OS Disk, click on + Create snapshot.

Step 5: Fill up the required details like Subscription, Resource Group and Provide Unique VM Snapshot Name.

  • Select Snapshot type: Full 
  • Select Storage type: Standard HDD | Premium SSD | Zone-redundant (This should be selected according to requirements needed in the project)

Step 6: For the next parameters, you can leave them as default and go for Review + create to proceed.

You will be notified once the deployment completes. That’s it. This snapshot can be used as recovery/backup of a select azure VM for future deployment in case of VM failures or VM crashes or else in case of any other business needs.