Skip to content

Commit 5935502

Browse files
author
Cameron Battagler
committed
Added instructions for adding the Blob Storage container, added better information messages, added edits suggested in pull request microsoft#199
1 parent 83fe1ad commit 5935502

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

samples/manage/azure-automation-automated-export/AutoExport.ps1

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ $waitInMinutes = 30;
3939
# Connection Asset Name for Authenticating (Keep as AzureClassicRunAsConnection if you created the default RunAs accounts)
4040
$connectionAssetName = "AzureClassicRunAsConnection";
4141

42-
4342
$storageKeyVariableName = "STORAGEKEYVARIABLENAME";
4443
$storageAccountName = "STORAGEACCOUNTNAME";
4544
$storageContainerName = "STORAGECONTAINERNAME";
@@ -144,9 +143,9 @@ function StartExport($dbObj)
144143
$currentTime = Get-Date -format "_yyyy-MM-dd_HH:mm.ss";
145144
$blobName = $dbObj.DatabaseName + "_ExportBlob" + $currentTime;
146145
# Use the stored credential to create a server credential to use to login to the server.
147-
$servercredential = $global:serverCredentialsDictionary[$dbObj.ServerName];
146+
$serverCredential = $global:serverCredentialsDictionary[$dbObj.ServerName];
148147
# Set up a SQL connection context to use when exporting.
149-
$ctx = New-AzureSqlDatabaseServerContext -ServerName $dbObj.ServerName -Credential $servercredential;
148+
$ctx = New-AzureSqlDatabaseServerContext -ServerName $dbObj.ServerName -Credential $serverCredential;
150149
# Get the storage key to setup the storage context.
151150
$storageKey = Get-AutomationVariable -Name $global:storageKeyVariableName;
152151
# Get the storage context.
@@ -171,7 +170,7 @@ function StartExport($dbObj)
171170
}
172171
# Set the state to Exporting.
173172
$dbObj.DatabaseState = ([DatabaseState]::Exporting);
174-
LogMessage ("Exporting " + $dbObj.DatabaseCopyName);
173+
LogMessage ("Exporting " + $dbObj.DatabaseCopyName + " with RequestID: " + $dbObj.Export.RequestGuid);
175174
$dbObj.OperationStartTime = Get-Date;
176175
}
177176

@@ -192,7 +191,7 @@ function CheckExport($dbObj)
192191
{
193192
# If the status is "Failed" and we have more retries left, try to export the database copy again.
194193
LogMessage ("The last export failed on database " + $dbObj.DatabaseName + ", going back to ToExport state to try again");
195-
LogMessage $check
194+
LogMessage $check.ErrorMessage
196195
$dbObj.DatabaseState = ([DatabaseState]::ToExport);
197196
$dbObj.RetryCount++;
198197
return;
@@ -229,7 +228,7 @@ function ExportProcess
229228
$dbsToCopy = $global:dbs | Where-Object DatabaseState -eq ([DatabaseState]::ToCopy);
230229
for($i = 0; $i -lt $dbsToCopy.Count; $i++)
231230
{
232-
LogMessage $dbsToCopy[$i];
231+
LogMessage "Database Name: $($dbsToCopy[$i].DatabaseName) State: $($dbsToCopy[$i].DatabaseState) Retry Count: $($dbsToCopy[$i].RetryCount)";
233232
StartCopy($dbsToCopy[$i]);
234233
}
235234

@@ -244,7 +243,7 @@ function ExportProcess
244243
$dbsToExport = $global:dbs | Where-Object DatabaseState -eq ([DatabaseState]::ToExport);
245244
for($i = 0; $i -lt $dbsToExport.Count; $i++)
246245
{
247-
LogMessage $dbsToExport[$i];
246+
LogMessage "Database Name: $($dbsToExport[$i].DatabaseName) State: $($dbsToExport[$i].DatabaseState) Retry Count: $($dbsToExport[$i].RetryCount)";
248247
StartExport($dbsToExport[$i]);
249248
}
250249

@@ -259,7 +258,7 @@ function ExportProcess
259258
$dbsToDrop = $global:dbs | Where-Object DatabaseState -eq ([DatabaseState]::ToDrop);
260259
for($i = 0; $i -lt $dbsToDrop.Count; $i++)
261260
{
262-
LogMessage $dbsToDrop[$i];
261+
LogMessage "Database Name: $($dbsToDrop[$i].DatabaseName) State: $($dbsToDrop[$i].DatabaseState) Retry Count: $($dbsToDrop[$i].RetryCount)";
263262
StartDrop($dbsToDrop[$i]);
264263
}
265264

@@ -273,23 +272,23 @@ function ExportProcess
273272

274273
# Authenticate to Azure with certificate
275274
Write-Verbose "Get connection asset: $connectionAssetName" -Verbose;
276-
$Conn = Get-AutomationConnection -Name $connectionAssetName;
277-
if ($Conn -eq $null)
275+
$automationConnection = Get-AutomationConnection -Name $connectionAssetName;
276+
if ($automationConnection -eq $null)
278277
{
279278
throw "Could not retrieve connection asset: $connectionAssetName. Assure that this asset exists in the Automation account.";
280279
}
281280

282-
$CertificateAssetName = $Conn.CertificateAssetName;
283-
Write-Verbose "Getting the certificate: $CertificateAssetName" -Verbose;
284-
$AzureCert = Get-AutomationCertificate -Name $CertificateAssetName;
285-
if ($AzureCert -eq $null)
281+
$certificateAssetName = $automationConnection.CertificateAssetName;
282+
Write-Verbose "Getting the certificate: $certificateAssetName" -Verbose;
283+
$automationCertificate = Get-AutomationCertificate -Name $certificateAssetName;
284+
if ($automationCertificate -eq $null)
286285
{
287-
throw "Could not retrieve certificate asset: $CertificateAssetName. Assure that this asset exists in the Automation account.";
286+
throw "Could not retrieve certificate asset: $certificateAssetName. Assure that this asset exists in the Automation account.";
288287
}
289288

290289
Write-Verbose "Authenticating to Azure with certificate." -Verbose;
291-
Set-AzureSubscription -SubscriptionName $Conn.SubscriptionName -SubscriptionId $Conn.SubscriptionID -Certificate $AzureCert;
292-
Select-AzureSubscription -SubscriptionId $Conn.SubscriptionID;
290+
Set-AzureSubscription -SubscriptionName $automationConnection.SubscriptionName -SubscriptionId $automationConnection.SubscriptionID -Certificate $automationCertificate;
291+
Select-AzureSubscription -SubscriptionId $automationConnection.SubscriptionID;
293292

294293
$currentIndex = 0;
295294
for($currentRun = 0; $currentRun -lt ([math]::Ceiling($databaseServerPairs.Length/$batchingLimit)); $currentRun++)

samples/manage/azure-automation-automated-export/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ Provides the scripts and lists the steps to set up automatically exporting your
1616
- Create your Automation Credential for each of your SQL Azure servers you intend to export by [following the instructions here](https://docs.microsoft.com/en-us/azure/automation/automation-credentials#creating-a-new-credential-asset).
1717
3. Create the Azure Storage Account to hold your bacpac files
1818
- Create the Storage Account by [following the instructions here](https://docs.microsoft.com/en-us/azure/storage/storage-create-storage-account#create-a-storage-account).
19+
- Create the Blob Storage Container
20+
- Go to your Storage Account
21+
- Click the Blobs tile
22+
- Click the Add Container button
23+
- Name the container, keep the access type as Private, and click the Create button
1924
- Copy your Storage Account access keys by [following the instructions here](https://docs.microsoft.com/en-us/azure/storage/storage-create-storage-account#view-and-copy-storage-access-keys).
2025
- Create an Azure Automation string Variable asset for your Storage Account access key by [following the instructions here](https://docs.microsoft.com/en-us/azure/automation/automation-variables#creating-an-automation-variable).
2126
4. Set Up Log Analytics (OMS) and Alerts (optional for alerting)

0 commit comments

Comments
 (0)