mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Added instructions for adding the Blob Storage container, added better information messages, added edits suggested in pull request #199
This commit is contained in:
@@ -39,7 +39,6 @@ $waitInMinutes = 30;
|
||||
# Connection Asset Name for Authenticating (Keep as AzureClassicRunAsConnection if you created the default RunAs accounts)
|
||||
$connectionAssetName = "AzureClassicRunAsConnection";
|
||||
|
||||
|
||||
$storageKeyVariableName = "STORAGEKEYVARIABLENAME";
|
||||
$storageAccountName = "STORAGEACCOUNTNAME";
|
||||
$storageContainerName = "STORAGECONTAINERNAME";
|
||||
@@ -144,9 +143,9 @@ function StartExport($dbObj)
|
||||
$currentTime = Get-Date -format "_yyyy-MM-dd_HH:mm.ss";
|
||||
$blobName = $dbObj.DatabaseName + "_ExportBlob" + $currentTime;
|
||||
# Use the stored credential to create a server credential to use to login to the server.
|
||||
$servercredential = $global:serverCredentialsDictionary[$dbObj.ServerName];
|
||||
$serverCredential = $global:serverCredentialsDictionary[$dbObj.ServerName];
|
||||
# Set up a SQL connection context to use when exporting.
|
||||
$ctx = New-AzureSqlDatabaseServerContext -ServerName $dbObj.ServerName -Credential $servercredential;
|
||||
$ctx = New-AzureSqlDatabaseServerContext -ServerName $dbObj.ServerName -Credential $serverCredential;
|
||||
# Get the storage key to setup the storage context.
|
||||
$storageKey = Get-AutomationVariable -Name $global:storageKeyVariableName;
|
||||
# Get the storage context.
|
||||
@@ -171,7 +170,7 @@ function StartExport($dbObj)
|
||||
}
|
||||
# Set the state to Exporting.
|
||||
$dbObj.DatabaseState = ([DatabaseState]::Exporting);
|
||||
LogMessage ("Exporting " + $dbObj.DatabaseCopyName);
|
||||
LogMessage ("Exporting " + $dbObj.DatabaseCopyName + " with RequestID: " + $dbObj.Export.RequestGuid);
|
||||
$dbObj.OperationStartTime = Get-Date;
|
||||
}
|
||||
|
||||
@@ -192,7 +191,7 @@ function CheckExport($dbObj)
|
||||
{
|
||||
# If the status is "Failed" and we have more retries left, try to export the database copy again.
|
||||
LogMessage ("The last export failed on database " + $dbObj.DatabaseName + ", going back to ToExport state to try again");
|
||||
LogMessage $check
|
||||
LogMessage $check.ErrorMessage
|
||||
$dbObj.DatabaseState = ([DatabaseState]::ToExport);
|
||||
$dbObj.RetryCount++;
|
||||
return;
|
||||
@@ -229,7 +228,7 @@ function ExportProcess
|
||||
$dbsToCopy = $global:dbs | Where-Object DatabaseState -eq ([DatabaseState]::ToCopy);
|
||||
for($i = 0; $i -lt $dbsToCopy.Count; $i++)
|
||||
{
|
||||
LogMessage $dbsToCopy[$i];
|
||||
LogMessage "Database Name: $($dbsToCopy[$i].DatabaseName) State: $($dbsToCopy[$i].DatabaseState) Retry Count: $($dbsToCopy[$i].RetryCount)";
|
||||
StartCopy($dbsToCopy[$i]);
|
||||
}
|
||||
|
||||
@@ -244,7 +243,7 @@ function ExportProcess
|
||||
$dbsToExport = $global:dbs | Where-Object DatabaseState -eq ([DatabaseState]::ToExport);
|
||||
for($i = 0; $i -lt $dbsToExport.Count; $i++)
|
||||
{
|
||||
LogMessage $dbsToExport[$i];
|
||||
LogMessage "Database Name: $($dbsToExport[$i].DatabaseName) State: $($dbsToExport[$i].DatabaseState) Retry Count: $($dbsToExport[$i].RetryCount)";
|
||||
StartExport($dbsToExport[$i]);
|
||||
}
|
||||
|
||||
@@ -259,7 +258,7 @@ function ExportProcess
|
||||
$dbsToDrop = $global:dbs | Where-Object DatabaseState -eq ([DatabaseState]::ToDrop);
|
||||
for($i = 0; $i -lt $dbsToDrop.Count; $i++)
|
||||
{
|
||||
LogMessage $dbsToDrop[$i];
|
||||
LogMessage "Database Name: $($dbsToDrop[$i].DatabaseName) State: $($dbsToDrop[$i].DatabaseState) Retry Count: $($dbsToDrop[$i].RetryCount)";
|
||||
StartDrop($dbsToDrop[$i]);
|
||||
}
|
||||
|
||||
@@ -273,23 +272,23 @@ function ExportProcess
|
||||
|
||||
# Authenticate to Azure with certificate
|
||||
Write-Verbose "Get connection asset: $connectionAssetName" -Verbose;
|
||||
$Conn = Get-AutomationConnection -Name $connectionAssetName;
|
||||
if ($Conn -eq $null)
|
||||
$automationConnection = Get-AutomationConnection -Name $connectionAssetName;
|
||||
if ($automationConnection -eq $null)
|
||||
{
|
||||
throw "Could not retrieve connection asset: $connectionAssetName. Assure that this asset exists in the Automation account.";
|
||||
}
|
||||
|
||||
$CertificateAssetName = $Conn.CertificateAssetName;
|
||||
Write-Verbose "Getting the certificate: $CertificateAssetName" -Verbose;
|
||||
$AzureCert = Get-AutomationCertificate -Name $CertificateAssetName;
|
||||
if ($AzureCert -eq $null)
|
||||
$certificateAssetName = $automationConnection.CertificateAssetName;
|
||||
Write-Verbose "Getting the certificate: $certificateAssetName" -Verbose;
|
||||
$automationCertificate = Get-AutomationCertificate -Name $certificateAssetName;
|
||||
if ($automationCertificate -eq $null)
|
||||
{
|
||||
throw "Could not retrieve certificate asset: $CertificateAssetName. Assure that this asset exists in the Automation account.";
|
||||
throw "Could not retrieve certificate asset: $certificateAssetName. Assure that this asset exists in the Automation account.";
|
||||
}
|
||||
|
||||
Write-Verbose "Authenticating to Azure with certificate." -Verbose;
|
||||
Set-AzureSubscription -SubscriptionName $Conn.SubscriptionName -SubscriptionId $Conn.SubscriptionID -Certificate $AzureCert;
|
||||
Select-AzureSubscription -SubscriptionId $Conn.SubscriptionID;
|
||||
Set-AzureSubscription -SubscriptionName $automationConnection.SubscriptionName -SubscriptionId $automationConnection.SubscriptionID -Certificate $automationCertificate;
|
||||
Select-AzureSubscription -SubscriptionId $automationConnection.SubscriptionID;
|
||||
|
||||
$currentIndex = 0;
|
||||
for($currentRun = 0; $currentRun -lt ([math]::Ceiling($databaseServerPairs.Length/$batchingLimit)); $currentRun++)
|
||||
|
||||
@@ -16,6 +16,11 @@ Provides the scripts and lists the steps to set up automatically exporting your
|
||||
- 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).
|
||||
3. Create the Azure Storage Account to hold your bacpac files
|
||||
- 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).
|
||||
- Create the Blob Storage Container
|
||||
- Go to your Storage Account
|
||||
- Click the Blobs tile
|
||||
- Click the Add Container button
|
||||
- Name the container, keep the access type as Private, and click the Create button
|
||||
- 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).
|
||||
- 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).
|
||||
4. Set Up Log Analytics (OMS) and Alerts (optional for alerting)
|
||||
|
||||
Reference in New Issue
Block a user