Workaround for Reducing Size of Azure Data Disks (Windows)
Azure supports only disk incremental resizing.
The aim of this article is to describe a workaround that will achive this goal.
For Standard Unmanaged Storage, reducing the size of a disk is pointless, since only the actual data stored on disks will be charged, regardless of the disk capacity. For this reason it is always a good practice to use the maximum disk size (1 TB, 1023 GB).
Unmanaged Premium Storage Disks and Managed Disks (Standard HDD, Standard SSD and Premium) will be charged basing on the selected perfomance tier, which can be of one of the available types (P10, P20 or P30). The performance tier is driven by disk capacity:
- P10: x < = 128 GB
- P20: 128 GB < x < = 512 GB
- P30 : 512 GB < x < = 1023 GB
The above list may be updated over time, as new Storage Tiers may be introduced. For a complete and updated list, please refer to this article: Azure Disks.
A proper scenario for which the shrink of an Azure Disk can be helpful could be when it's necessary to reduce costs, by scaling down to a lower performance tier,
Note: this workaround will work only for DataDisks. OS Disks are not supported.
The idea is basically built on the following steps
Attach a new Empty Data-Disk, create a volume and assign an available drive Letter
Stop/Close any application that might update data in the source drive. This is necessary for preserve data consistency.
Move data from the DataDisk you want to shrink to the new drive, using robocopy (Windows) .
Why robocopy? There is no better answer than the one provided here: https://blogs.technet.microsoft.com/josebda/2014/08/18/using-file-copy-to-measure-storage-performance-why-its-not-a-good-idea-and-what-you-should-do-instead
NOTE: You might want to preserve Security information from the source drive (i.e. if the disk you are resizing contains SQL Server data, you need to keep the existing permissions for the SQL Service Account to that drive's folder).This is a sample command :
robocopy E:\ F:\ *.* /j /e /sec /Xd "System Volume Information" "$RECYCLE.BIN" /Xo
The command above will move all data from E: to F:. Copy will be optimized for large files (/J), and will affect al files and subfolders (/e). Security information will be preserved (/sec). The copy will ignore system folders like "Sys Vol Info" and the recycle bin (/Xd). Option /Xo will not overwrite existing data unless the source copy is newer than the one possibly existing at destination.
Remove the original DataDisk
Rename the new drive as the original.
Start/Run the Application you stopped on step 2.
Simple but reliable!
Enjoy your time shrinking your data disks!