Whitepaper 'FinOps and cost management for Kubernetes'
OptScale is fully available as an open source solution under Apache 2.0 on GitHub
Ebook 'From FinOps to proven cloud cost management & optimization strategies'

FinOps best practices: How to find and cleanup orphaned and unused snapshots in MS Azure and Alibaba Cloud

Efficient cost management and FinOps have become one of the top priorities for public cloud customers across all industries. One of the main reasons for cloud budget overruns is lack of visibility into a volume’s lifecycle, which leads to the presence of orphaned and unused resources. These overlooked resources are contributed to a company cloud bill, and users don’t even expect that they’re paying for them.


After our blog post Reduce your AWS bill by cleaning orphaned and unused disk snapshots we’ve got many questions on how it can be applied to cloud cost optimization goals to other public clouds, such as Microsoft Azure and Alibaba Cloud?

Let’s explore how we can perform the similar cleanup operations on them.

Cleaning up MS Azure snapshots

The process of finding unused snapshots in Azure can be performed applying the following criteria to the list of snapshots:

  • snapshot is older than certain date
  • the source disk from which the snapshot is created doesn’t exist

Let’s use Azure Cloud Shell in Bash mode to find such snapshots.

Making a list of old snapshots (you can set date threshold according to your needs):

OLD_SNAPSHOTS=$(az snapshot list --query "[?timeCreated <= '2021-01-01T00:00:00.000000+00:00'].{DiskId:creationData.sourceResourceId,Id:id}" --output table | tail -n +3)

Listing disks:

USED_DISKS=$(az disk list --query "[].{Id:id}" --output table | tail -n +3)

Filtering out snapshots which still have source disk:

if [[ ! "$USED_DISKS[*]" =~ $RESOURCE_ID ]]
echo "Detected the following unused snapshots: $UNUSED_SNAPSHOTS"

Once you have them listed and verify that you really don’t need them, you can easily clean them up via a single command:

az snapshot delete --ids "${UNUSED_SNAPSHOTS[@]}"

Free cloud cost optimization. Lifetime

Cleaning up snapshots in Alibaba Cloud

In Alibaba Cloud, Snapshot properties has one more useful value which allows us to put it as criterion for filtering – field “Usage” which is empty if this Snapshot is not used as a source for some disk or image.
Having that, here is how you can detect unused Snapshots using Alibaba Cloud Shell.

Making a list of old snapshots (you can set date threshold according to your needs):

OLD_SNAPSHOTS=$(aliyun ecs DescribeSnapshots --pager --Usage none --Filter.2.Key CreationEndTime --Filter.2.Value 2021-01-01T00:00Z --output cols=SnapshotId,SourceDiskId rows=Snapshots.Snapshot[] | tail -n +3 | sed 's/ | /,/g')

Listing disks:

USED_DISKS=$(aliyun ecs DescribeDisks --pager --output cols=Disks.Disk[].DiskId | tail -n +3 | sed 's/[//' | sed 's/]//')

Filtering out snapshots which still have source disk:

SNAPSHOTID=$(cut -d, -f1 <<< $SNAP_INFO)
DISKID=$(cut -d, -f2 <<< $SNAP_INFO)
if [[ ! "$USED_DISKS[*]" =~ $DISKID ]]
echo "Detected snapshot - $SNAPSHOTID"
# aliyun ecs DeleteSnapshot --SnapshotId=$SNAPSHOTID

Please note the commented line in the last snippet. You’ll need to uncomment it once you verify the list of detected unused snapshots and ready to clean them up

The ways of identifying and cleaning up orphaned snapshots described above will help your company keep MS Azure and Alibaba Cloud costs under control, and implement best practices of FinOps methodology by providing your IT team with more visibility into cloud resources.

Find best practices + helpful tips on how to tag cloud resources in MS Azure → https://hystax.com/ms-azure-tagging-best-practices.

Enter your email to be notified about new and relevant content.

Thank you for joining us!

We hope you'll find it usefull

You can unsubscribe from these communications at any time. Privacy Policy

News & Reports

FinOps & Test Environment Management

A full description of OptScale as a FinOps and Test Environment Management platform to organize shared IT environment usage, optimize & forecast Kubernetes and cloud costs

From FinOps to proven cloud cost management & optimization strategies

This ebook covers the implementation of basic FinOps principles to shed light on alternative ways of conducting cloud cost optimization

Engage your engineers in FinOps and cloud cost savings

Discover how OptScale helps companies quickly increase FinOps adoption by engaging engineers in FinOps enablement and cloud cost savings