Geeks With Blogs
Jim Giercyk

 

As companies begin migrating to AZURE, DBAs are tempted to save terrestrial (non-AZURE) backup files to “the cloud” to leverage the unlimited amount of space that is available.  No more alarms in the middle of the night due to a lack of disk space.  Ole Hallengren has even added this option to his maintenance solution (https://ola.hallengren.com/).  Others have also followed suit.

The trouble is that most backup solutions do not have a way to clean up old blob backup files.  This little script will clean up files older that the “$daystokeep” parameter. 

 


import-module AzureRM

$daysToKeep = 7
$storageAccount = 'sqlbackups'
$storageAccessKey = '0JqxsxUOb9kJQa2oAqlGFjalB78vieOqySMdValN+fpYfrSu2XtZz8VNaS/iEb5KqdVySsSFYtLKQe+/imDnEw=='
$storageContainer = 'prodbackups'

$context = New-AzureStorageContext -StorageAccountName $storageAccount -StorageAccountKey $storageAccessKey
New-AzureStorageContainer -Name $storageContainer -Context $context -Permission Blob -ErrorAction SilentlyContinue

$EGBlobs = Get-AzureStorageBlob -Container $storageContainer -Context $context | sort-object LastModified | select lastmodified, name

foreach($blob in $EGBlobs)
{
    if($blob.lastmodified -lt (get-date).AddDays($daysToKeep*-1))

        {

        Remove-AzureStorageBlob -Blob $blob.name -Container $storageContainer -Context $context
 
        }
}


 

You must of course set your own parameter values, but the script is pretty simple and blindly removes every file older than 7 days from the storage container named “prodbackups”.  With a little tweaking, you can filter by extension type or particular file name or pattern. 

 

I have a version of this script in my maintenance plan, and run it every night.  Although there is an unlimited amount of space available in the cloud, leaving all of your backup files on a storage account without a little cleanup can get very expensive.  All of that storage comes at a price.

Posted on Monday, May 1, 2017 3:26 PM | Back to top


Comments on this post: Deleting old AZURE backups with Powershell

# re: Deleting old AZURE backups with Powershell

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Many of the backup solutions do not have a way to clean up old backup files and the trouble is almost faced by many of us. I was here for searching the solution for same and I found this article really informative and useful. Keep sharing more like this!
modular home manufacturers
Left by Merlin John on May 29, 2017 12:08 PM

# Joke forever
Requesting Gravatar...
Great article thanks for sharing
www.jokeforever.com
Left by Surinder on Jun 27, 2017 1:25 PM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Great article

In this post u can enjoy all kind of jokes
Left by Surinder on Jun 27, 2017 1:34 PM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Great article
Left by Surinder on Jun 27, 2017 1:37 PM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
This is not prefect process to do backup of your data by using powershell. This is the mistake what most of non-IT companies do. I would like to say to those organizations that their third party tool which can be downloaded from essay help blog which helps you people in prefect transferring of your data into new server.
Left by Bessie R. Charity on Jul 21, 2017 10:47 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Thank you for this! I'm always looking for a great backup solution. -Selwa | https://fleekconsulting.com
Left by Selwa on Jul 21, 2017 7:05 PM

# Great Article
Requesting Gravatar...
Thanks for sharing this article with us this article provide us valueable information.I hope you post more articles in your future.I have two blogs,my first blog helps the people to find Latest Songs Lyrics and my second blog provide Latest Funny Jokes.I visit you site to get latest articles.Thanks
Left by Harry on Sep 05, 2017 1:37 PM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Nice post, many thanks
vivalared link to link 
Left by Vivalared on Sep 11, 2017 2:11 PM

# re: Great post
Requesting Gravatar...
Helpful post.



Read my new Funny Jokessite and enjoy.
Left by Niti Para on Oct 05, 2017 12:33 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Very helpful for me.

Read Hindi Jokes for fun.
Left by Niti Para on Oct 05, 2017 12:37 AM

# gamesdro.com
Requesting Gravatar...
Buddies if you can search for online game, then go our webpage gamesdro.com and play in without any requirement, such a many amazing games is available in this homepage.
Left by Vivek on Oct 06, 2017 6:15 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Nice post, many thanks
http://www.newsmswishes.com
Left by Sumit Kumar on Oct 15, 2017 7:43 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Nice post, many thanks for sharing
new year sms Wishes
Left by Sumit Kumar on Oct 15, 2017 7:46 AM

# re: Deleting old AZURE backups with Powershell

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
This is a very good post.I have visited your blog first time and it is quite appreciable. I really appreciate your hardwork for it.Your content is very informative and it will surely help the people.You can check my website. Lyricab
Left by Lyricab on Oct 31, 2017 11:58 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Awesome blog nice, Keep It up
Lyrics Songs
Left by Lyrics Songs on Nov 11, 2017 7:04 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Very helpful post, thanks for sharing.
New Lyrics Song
Left by Sakil on Dec 01, 2017 10:30 PM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Azure has become one of the leading platforms used by companies to save terrestrial backup files to “the cloud” to leverage the unlimited amount of space that is available. Thanks for sharing the codes to delete old Azure backups using PowerShell. Private Tour Washington DC
Left by Taylor Shaw on Dec 05, 2017 6:13 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...

great article i hope you post more articles in href="http://punjabisongs360.in" />future.
Left by Priya on Dec 17, 2017 12:03 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Awesome blog and great article. Thank for sharing...
All New Lyrics Song
Left by Bilas on Dec 20, 2017 2:20 PM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Most backup solutions do not have a way to clean up old blob backup files and this will be an effective strategy to deal with the issue. Using PowerShell for deleting the old azure backups looks to be the perfect option. Thanks for the share. wooden beads
Left by lionel on Dec 26, 2017 4:03 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Thanks for sharing this article i hope you post more i your future check out New Year Wishes for friends

New Year Images
Left by Harpreet singh on Dec 30, 2017 12:52 PM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Sidhu Moose wala back with new song in 2018 Just Listen the real talkJust Listen sidhu Moose wala
Left by Sidhu Moose Wala on Jan 02, 2018 4:04 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
This is so irritating. I can find anything on this website. No fan-club registration info anywhere.
Putlocker, 123movies
Left by Anna Shetty on Jan 17, 2018 2:56 AM

# webhositng
Requesting Gravatar...
It's great because of the knowledge you share with us
$1 godaddy hostingI will always follow your blog and will share your blog with my friends.
Left by jackwatson on Mar 10, 2018 1:15 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
if you want extra save on fashionable products you can visit their
best deals on fashionable products at a cheap price
Left by sarah on Mar 10, 2018 7:13 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
thanks for sharing this article with us
best offers on clothing products
Left by milley on Mar 10, 2018 7:15 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Left by jack on Mar 10, 2018 7:19 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
great website templates. looks so amazing
shirt in minimum price
Left by peter on Mar 10, 2018 7:20 AM

# re: Deleting old AZURE backups with Powershell
Requesting Gravatar...
Left by clinit on Mar 27, 2018 10:20 AM

Your comment:
 (will show your gravatar)


Copyright © Jim Giercyk | Powered by: GeeksWithBlogs.net