1
0
mirror of https://github.com/Microsoft/sql-server-samples.git synced 2025-12-08 14:58:54 +00:00
Files
sql-server-samples/samples/manage/azure-automation-automated-export/README.md

5.8 KiB
Raw Blame History

services, platforms, author
services platforms author
azure automation azure trgrie-msft

Setting up Auto Export in Azure Automation

Provides the scripts and lists the steps to set up automatically exporting your databases to Azure Storage with Azure Automation.

Prerequisite Set Up

  1. Create and set up your Azure Automation Account
  2. Add Azure Automation Credential assets for your SQL Azure servers
  3. Create the Azure Storage Account to hold your bacpac files
  4. Set Up Log Analytics (OMS) and Alerts (optional for alerting)
    • If you don't have Log Analytics set up on your Azure account, follow these instructions for setting it up.
  5. Set Up Log Analytics Alerts
    • To send yourself an email if an error occurs or one of the jobs fails, you need to set up alerts.
    • Select your log analytics account that you want to use in the azure portal and click on the OMS Portal box under Management.
    • Click on Log Search and enter the queries you want to alert on. These are two that are suggested:
      • Category=JobStreams “Error occurred*”
      • Category=JobLogs ResultType=Failed
    • The first will alert on an the provided script saying an error occurred so you know if something didn't go quite right. The second alerts if the script fails entirely.

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 servers 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 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:
    • $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
  2. Add a schedule for your Automated Export runbook

You should now be all set up for Automated Exports into blob storage of your selected SQL Azure databases.