Blob Storage Sync tool updated
During a SQL Server migration this month, I found some inconsistencies in my Azure Blob Storage Sync tool, so I made several improvements, and fixed an outstanding bug.
As you know, it relies on the naming convention provided in Ola Hallengren’s Maintenance Solution and comes in two parts: the AzureBlobStorageSync command-line application, and the AzureBlobStorageRestore command-line application.
New Features
I realised that it was not possible, using this tool, to download every file from the Blob Storage Container in one go. The code only downloaded the files necessary to perform the latest restore for a single database.
To resolve this, and allow all files to be downloaded from Blob Storage, I have added a new configuration key called DownloadFilesFromAzure
, which takes True
or False
values.
Another new feature is an explicit option to upload all local files to Blob Storage during a sync. Previously, it was implied that all local files in the LocalPath
should be uploaded, but you may not want to do that. This is implemented as configuration key CopyFilesToAzure
, which takes True
or False
values.
Deleting Files
There are now two ways to delete files from a Blob Storage Container:
- Files that do not match the source, that must be deleted off the target;
- Files that are no longer needed on the target.
The first option is a typical synchronisation feature and was implicit in the previous version. It is now implemented using the configuration key DeleteMissingFilesFromAzure
, which takes a True
or False
value. If it is set to True
, files that do not exist on the local drive will be deleted from Blob Storage.
The second option is for deleting files that match a certain string in the file name. This is handy for server migrations where the file names generated by Ola’s backup script contain the old server name. While the backup script can perform cleanup tasks based on timestamps, it will ignore files that have a different server name, and you might be left with orphaned files long after the backup retention window has passed.
The configuration key, called DeleteExplicitFilesFromAzure
takes True
or False
values, plus an additional configuration key, called ExplicitFilesToDeleteMatchingString
. Here you can put a string containing the old server name, and any matching file with that name will be deleted. This particular feature only works with one string at a time. You will have to run it more than once if you need to delete file names that match other strings.
Fixes
Yes, the only logged issue in the repository has been fixed! I now use sp_executesql
instead of EXEC
for the T-SQL portion of the restore tool. This was probably the easiest thing to fix.
A more critical fix, and the main reason for this blog post and tool update, is to do with downloading files.
Imagine an all-too-common scenario where a download fails before it is complete. In an emergency, the last thing you need is your Restore tool failing. Whereas before I was simply using the name of the file, I now also check file size as well. If the file sizes do not match, the file will be downloaded from Blob Storage again.
Files now download from smallest to largest in size. This is a major benefit if you have a lot of small transaction log files.
Notes
Reading the list of files from Blob Storage takes about ten seconds for 2,500 files, before parsing can begin. This is not a lot of time, but it’s something to keep in mind.
Feature Requests and Bug Reports
If you have any feature requests, or have found a bug, please log that on the GitHub repository. Even better, if you know C#, you can add your own features and fix your own bugs, submit a pull request, and I’ll merge your code into the tool.
Questions, comments or complaints? Twitter is the place: @bornsql is where you’ll find me.