From f6a3ce33099457a0e4accd32e4f849de926f1601 Mon Sep 17 00:00:00 2001 From: Cameron Battagler Date: Thu, 16 Mar 2017 16:37:29 -0500 Subject: [PATCH] Finished out documentation with how to add the script to Azure Automation --- .../AutoExport.ps1 | 14 +++++++---- .../README.md | 23 ++++++++++++++++--- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/samples/manage/azure-automation-automated-export/AutoExport.ps1 b/samples/manage/azure-automation-automated-export/AutoExport.ps1 index e9596158..08ea71e0 100644 --- a/samples/manage/azure-automation-automated-export/AutoExport.ps1 +++ b/samples/manage/azure-automation-automated-export/AutoExport.ps1 @@ -18,11 +18,16 @@ Add-Type -TypeDefinition @" $databaseServerPairs = @([pscustomobject]@{serverName="SAMPLESERVER1";databaseName="SAMPLEDATABASE1"}, [pscustomobject]@{serverName="SAMPLESERVER1";databaseName="SAMPLEDATABASE2"}, - [pscustomobject]@{serverName="SAMPLESERVER2";databaseName="SAMPLEDATABASE3"}); + [pscustomobject]@{serverName="SAMPLESERVER2";databaseName="SAMPLEDATABASE3"} + ); -$serverCred = Get-AutomationPSCredential -Name 'NAMEOFSERVERCREDENTIAL1'; +# The Credentials for the database servers +$serverCred1 = Get-AutomationPSCredential -Name 'NAMEOFSERVERCREDENTIAL1'; $serverCred2 = Get-AutomationPSCredential -Name 'NAMEOFSERVERCREDENTIAL2'; -$serverCredentialsDictionary = @{'SAMPLESERVER1'=$serverCred;'SAMPLESERVER2'=$serverCred2} +$serverCredentialsDictionary = @{ + 'SAMPLESERVER1'=$serverCred1; + 'SAMPLESERVER2'=$serverCred2; + } # The number of databases you want to have running at the same time. $batchingLimit = 10; @@ -34,6 +39,7 @@ $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"; @@ -134,8 +140,6 @@ function CheckCopy($dbObj) # This function starts the export. If there is an error, we set the state to ToDrop. Otherwise, we set the state to Exporting. function StartExport($dbObj) { - # Setup the server connection that the storage account is on. - $serverManageUrl = "https://autoexportserver.database.windows.net"; # Get the current time to use as a unique identifier for the blob name. $currentTime = Get-Date -format "_yyyy-MM-dd_HH:mm.ss"; $blobName = $dbObj.DatabaseName + "_ExportBlob" + $currentTime; diff --git a/samples/manage/azure-automation-automated-export/README.md b/samples/manage/azure-automation-automated-export/README.md index 1ac4b8aa..f56cb832 100644 --- a/samples/manage/azure-automation-automated-export/README.md +++ b/samples/manage/azure-automation-automated-export/README.md @@ -30,16 +30,33 @@ Provides the scripts and lists the steps to set up automatically exporting your ## Script Set Up +Save the AutoExport.ps1 and AutoExportBlobRetention.ps1 files locally to make these edits + 1. In the AutoExport.ps1 script, here are the values that need to be modified: - $databaseServerPairs: This is where you put in the names of the databases you want to export along with the name of the server they are on. + Add them in the format: `[pscustomobject]@{serverName="SAMPLESERVER1";databaseName="SAMPLEDATABASE1"}` make sure to comma separate the items - $serverCredentialsDictionary: If you are backing up from multiple servers, you can setup all of the credentials here and look them up by the server’s name later. + Add a $serverCred variable in the format `$serverCred1 = Get-AutomationPSCredential -Name 'NAMEOFSERVERCREDENTIAL1';` for each Azure Automation Credential you created. Increment the variable name (eg. $serverCred2 $serverCred3) for each one. + Add the $serverCreds to the dictionary in the format `'SAMPLESERVERNAME1'=$serverCred1;` - $batchingLimit: This tells the script how many databases can be worked on at the same time (basically, the maximum number of database copies that there will be at once). - $retryLimit: This tells the script how many times it can retry an operation. - $waitTimeInMinutes: This tells the script how long it can wait for an operation to complete before it fails. - - $storageKeyVariableName: This is the AutomationAccount you created the StorageKey variable under (probably the same one you are running the RunBook under) and -Name is the name of the variable. + - $storageKeyVariableName: This is the Azure Automation string Variable name you created to store your Storage Key. - $storageAccountName: This is the name of the storage account you are exporting to. - $connectionAssetName: Connection Asset Name for Authenticating (Keep as AzureClassicRunAsConnection if you created the default RunAs accounts) 2. In AutoExportBlobRetention, here are the values that need to be modified: - - -Name for Get-AzureAutomationVariable: This is the AutomationAccount you created the StorageKey variable under (probably the same one you are running the RunBook under) and -Name is the name of the variable. - - $storageContainer: This is the name of the storage container where you will be monitoring the exported blobs. + - $storageKeyVariableName: This is the Azure Automation string Variable name you created to store your Storage Key. + - $storageAccountName: This is the name of your Storage Account you exported your bacpacs to. + - $storageContainerName: This is the name of the storage container where you will be monitoring the exported blobs. - $retentionInDays: This is how many days you want to keep the exported blobs stored for before deleting. + +## Adding the Script to Azure Automation + +1. Import the scripts as Azure Automation Runbooks + - Create runbooks from the scripts you editted above by [following the instructions here](https://docs.microsoft.com/en-us/azure/automation/automation-creating-importing-runbook#to-import-a-runbook-from-a-file-with-the-azure-portal) for both scripts. + - [Make sure to publish the runbook.](https://docs.microsoft.com/en-us/azure/automation/automation-creating-importing-runbook#to-publish-a-runbook-using-the-azure-portal) +2. Add a schedule for your Automated Export runbook + - Create a recurring schedule by [following the instructions here](https://docs.microsoft.com/en-us/azure/automation/automation-schedules#to-create-a-new-schedule-in-the-azure-portal). + - Link the schedule(s) you created to the runbooks by [following the instructions here](https://docs.microsoft.com/en-us/azure/automation/automation-schedules#to-link-a-schedule-to-a-runbook-with-the-azure-portal). + +You should now be all set up for Automated Exports into blob storage of your selected SQL Azure databases. \ No newline at end of file