Whitepaper 'FinOps and cost management for Kubernetes'
Please consider giving OptScale a Star on GitHub, it is 100% open source. It would increase its visibility to others and expedite product development. Thank you!
Ebook 'From FinOps to proven cloud cost management & optimization strategies'
OptScale FinOps
OptScale — FinOps
FinOps overview
Cost optimization:
AWS
MS Azure
Google Cloud
Alibaba Cloud
Kubernetes
MLOps
OptScale — MLOps
ML/AI Profiling
ML/AI Optimization
Big Data Profiling
OPTSCALE PRICING
cloud migration
Acura — Cloud migration
Overview
Database replatforming
Migration to:
AWS
MS Azure
Google Cloud
Alibaba Cloud
VMWare
OpenStack
KVM
Public Cloud
Migration from:
On-premise
disaster recovery
Acura — DR & cloud backup
Overview
Migration to:
AWS
MS Azure
Google Cloud
Alibaba Cloud
VMWare
OpenStack
KVM

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.

How-to-find-cleanup-orphaned-unused-snapshots-in-Microsoft-Azure

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:

UNUSED_SNAPSHOTS=()
IS_UNUSED_SNAPSHOT=false
IS_DISK_ID=true
for RESOURCE_ID in $OLD_SNAPSHOTS
do
if $IS_DISK_ID
then
if [[ ! "$USED_DISKS[*]" =~ $RESOURCE_ID ]]
then
IS_UNUSED_SNAPSHOT=true
fi
IS_DISK_ID=false
else
if $IS_UNUSED_SNAPSHOT
then
UNUSED_SNAPSHOTS+=($RESOURCE_ID)
fi
IS_UNUSED_SNAPSHOT=false
IS_DISK_ID=true
fi
done
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:

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

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 and MLOps

A full description of OptScale as a FinOps and MLOps open source platform to optimize cloud workload performance and infrastructure cost. Cloud cost optimization, VM rightsizing, PaaS instrumentation, S3 duplicate finder, RI/SP usage, anomaly detection, + AI developer tools for optimal cloud utilization.

FinOps, cloud cost optimization and security

Discover our best practices: 

  • How to release Elastic IPs on Amazon EC2
  • Detect incorrectly stopped MS Azure VMs
  • Reduce your AWS bill by eliminating orphaned and unused disk snapshots
  • And much more deep insights

Optimize RI/SP usage for ML/AI teams with OptScale

Find out how to:

  • see RI/SP coverage
  • get recommendations for optimal RI/SP usage
  • enhance RI/SP utilization by ML/AI teams with OptScale