Skip to content

Commit f6a3ce3

Browse files
author
Cameron Battagler
committed
Finished out documentation with how to add the script to Azure Automation
1 parent 47205a4 commit f6a3ce3

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ Add-Type -TypeDefinition @"
1818
$databaseServerPairs =
1919
@([pscustomobject]@{serverName="SAMPLESERVER1";databaseName="SAMPLEDATABASE1"},
2020
[pscustomobject]@{serverName="SAMPLESERVER1";databaseName="SAMPLEDATABASE2"},
21-
[pscustomobject]@{serverName="SAMPLESERVER2";databaseName="SAMPLEDATABASE3"});
21+
[pscustomobject]@{serverName="SAMPLESERVER2";databaseName="SAMPLEDATABASE3"}
22+
);
2223

23-
$serverCred = Get-AutomationPSCredential -Name 'NAMEOFSERVERCREDENTIAL1';
24+
# The Credentials for the database servers
25+
$serverCred1 = Get-AutomationPSCredential -Name 'NAMEOFSERVERCREDENTIAL1';
2426
$serverCred2 = Get-AutomationPSCredential -Name 'NAMEOFSERVERCREDENTIAL2';
25-
$serverCredentialsDictionary = @{'SAMPLESERVER1'=$serverCred;'SAMPLESERVER2'=$serverCred2}
27+
$serverCredentialsDictionary = @{
28+
'SAMPLESERVER1'=$serverCred1;
29+
'SAMPLESERVER2'=$serverCred2;
30+
}
2631

2732
# The number of databases you want to have running at the same time.
2833
$batchingLimit = 10;
@@ -34,6 +39,7 @@ $waitInMinutes = 30;
3439
# Connection Asset Name for Authenticating (Keep as AzureClassicRunAsConnection if you created the default RunAs accounts)
3540
$connectionAssetName = "AzureClassicRunAsConnection";
3641

42+
3743
$storageKeyVariableName = "STORAGEKEYVARIABLENAME";
3844
$storageAccountName = "STORAGEACCOUNTNAME";
3945
$storageContainerName = "STORAGECONTAINERNAME";
@@ -134,8 +140,6 @@ function CheckCopy($dbObj)
134140
# This function starts the export. If there is an error, we set the state to ToDrop. Otherwise, we set the state to Exporting.
135141
function StartExport($dbObj)
136142
{
137-
# Setup the server connection that the storage account is on.
138-
$serverManageUrl = "https://autoexportserver.database.windows.net";
139143
# Get the current time to use as a unique identifier for the blob name.
140144
$currentTime = Get-Date -format "_yyyy-MM-dd_HH:mm.ss";
141145
$blobName = $dbObj.DatabaseName + "_ExportBlob" + $currentTime;

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,33 @@ Provides the scripts and lists the steps to set up automatically exporting your
3030

3131
## Script Set Up
3232

33+
Save the AutoExport.ps1 and AutoExportBlobRetention.ps1 files locally to make these edits
34+
3335
1. In the AutoExport.ps1 script, here are the values that need to be modified:
3436
- $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.
37+
Add them in the format: `[pscustomobject]@{serverName="SAMPLESERVER1";databaseName="SAMPLEDATABASE1"}` make sure to comma separate the items
3538
- $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.
39+
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.
40+
Add the $serverCreds to the dictionary in the format `'SAMPLESERVERNAME1'=$serverCred1;`
3641
- $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).
3742
- $retryLimit: This tells the script how many times it can retry an operation.
3843
- $waitTimeInMinutes: This tells the script how long it can wait for an operation to complete before it fails.
39-
- $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.
44+
- $storageKeyVariableName: This is the Azure Automation string Variable name you created to store your Storage Key.
4045
- $storageAccountName: This is the name of the storage account you are exporting to.
4146
- $connectionAssetName: Connection Asset Name for Authenticating (Keep as AzureClassicRunAsConnection if you created the default RunAs accounts)
4247
2. In AutoExportBlobRetention, here are the values that need to be modified:
43-
- -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.
44-
- $storageContainer: This is the name of the storage container where you will be monitoring the exported blobs.
48+
- $storageKeyVariableName: This is the Azure Automation string Variable name you created to store your Storage Key.
49+
- $storageAccountName: This is the name of your Storage Account you exported your bacpacs to.
50+
- $storageContainerName: This is the name of the storage container where you will be monitoring the exported blobs.
4551
- $retentionInDays: This is how many days you want to keep the exported blobs stored for before deleting.
52+
53+
## Adding the Script to Azure Automation
54+
55+
1. Import the scripts as Azure Automation Runbooks
56+
- 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.
57+
- [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)
58+
2. Add a schedule for your Automated Export runbook
59+
- 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).
60+
- 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).
61+
62+
You should now be all set up for Automated Exports into blob storage of your selected SQL Azure databases.

0 commit comments

Comments
 (0)