1
0
mirror of https://github.com/Microsoft/sql-server-samples.git synced 2025-12-08 14:58:54 +00:00

Initial Azure Automation Automated Export Sample

This contains the powershell files for the auotmated export, a README.md
file explaining how to set up the automated export in azure automation,
and an update to the README.md file in the directory above describing
the automated export sample.
This commit is contained in:
tgrieger
2016-09-12 10:50:56 -07:00
parent 25ca9dc307
commit 630619a7ab
4 changed files with 359 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# The storage key for the storage account you are using.
$storageKey = Get-AutomationVariable -Name "STORAGEKEYVARIABLENAME";
# The name of the storage container you are using.
$storageContainer = "STORAGECONTAINERNAME";
# Set up the storage context for the storage account.
$context = New-AzureStorageContext -StorageAccountName "STORAGEACCOUNTNAME" -StorageAccountKey $storageKey
# Get all of the blobs in the storage account.
$blobs = Get-AzureStorageBlob -Container $storageContainer -Context $context
# Set the number of days that you want the blob to be stored for.
$retentionInDays = 30
foreach($blob in $blobs)
{
# Get the current time to compare to the time that the blob was created.
$currentTime = Get-Date;
# If the blob is more than $retentionInDays old, delete it.
if(($currentTime - $blob.LastModified.DateTime).TotalDays -gt $retentionInDays)
{
echo ("Deleting blob " + $blob.Name)
# Delete the blob.e
Remove-AzureStorageBlob -Container $storageContainer -Context $context -Blob $blob.Name;
}
}