I previously blogged about how to delete blob entries older than a given date.
I have extended the script slightly to first download entries, zip then and upload them again to another storage container, before actually doing the removal. Before the deletion is carried out a simple check of file size is performed to ensure the upload succeced.
The sequence is illustrated below:
And the script:
function FileIsLocked( [string] $filePath ) { $script:locked = $false $fileInfo = New-Object System.IO.FileInfo $filePath trap { # if we are in here, the file is locked $script:locked = $true continue } $fileStream = $fileInfo.Open [System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None ) if ($fileStream) { $fileStream.Close() } $script:locked }# Name of your account $accountName = <Account Name> # Account key # Get current date on format YYYYMMDD, e.g. 20110906 #Location of where blob entries should be downloaded to # Name of source and target storage container # Download and removed blob entries older than 90 days # Download blob entries # Zip files Write-Host “Check if File is locked” while ($fileIsLocked) # Upload zip-file # Check if upload went well by comparing file size $bfc = New-Object Cerebrata.AzureUtilities.ManagementClient.StorageManagementEntities.BlobsFilterCriteria $blobInfo = Get-Blob $fileInfo = (New-Object IO.FileInfo “$zipFileName”) if ($blobInfo.Size -eq $fileInfo.Length) # Remove downloaded blob entries |