This repository was archived by the owner on Dec 20, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAzureSqlPerformance.psm1
81 lines (61 loc) · 3.88 KB
/
AzureSqlPerformance.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function Test-AzureSqlDatabaseImportPerformance {
[CmdletBinding()]
param(
[parameter(Mandatory=$true)][string]$DatabaseName,
[parameter(Mandatory=$true)][string]$ServerAdminUsername,
[parameter(Mandatory=$true)][string]$ServerAdminPassword,
[parameter(Mandatory=$true)][string]$ServerLocationName,
[parameter(Mandatory=$true)][string]$DatabaseEdition,
[parameter(Mandatory=$true)][string]$DatabaseServiceObjective,
[parameter(Mandatory=$true)][string]$StorageAccountName,
[parameter(Mandatory=$true)][string]$StorageAccountKey,
[parameter(Mandatory=$true)][string]$StorageAccountContainer,
[parameter(Mandatory=$true)][string]$StorageAccountBlobName,
[parameter(Mandatory=$true)][string]$MaximumSizeGB
)
process
{
$location = Get-AzureLocation | Where-Object -FilterScript { $_.Name -eq $ServerLocationName }
if ($location -eq $null) {
throw "Location is not valid."
}
Write-Verbose $ServerAdminUsername
Write-Verbose $ServerAdminPassword
$server = New-AzureSqlDatabaseServer -AdministratorLogin $ServerAdminUsername -AdministratorLoginPassword $ServerAdminPassword -Location $ServerLocationName
Write-Verbose "Server Name is $($server.ServerName)."
while ($server.OperationStatus -ne "Success") {
Write-Verbose "Waiting for server to be created."
$server = Get-AzureSqlDatabaseServer $server.ServerName
}
Write-Verbose "Server is ready."
$objective = Get-AzureSqlDatabaseServiceObjective -ServerName $server.ServerName | Where-Object -FilterScript { $_.Name -eq $DatabaseServiceObjective }
if ($objective -eq $null) {
throw "Objective is not valid."
}
$database = New-AzureSqlDatabase -ServerName $server.ServerName -DatabaseName $DatabaseName -Edition $DatabaseEdition -ServiceObjective $objective -MaxSizeGB $MaximumSizeGB
while ($database.Status -ne 0) {
Write-Verbose "Waiting for database to come online."
$database = Get-AzureSqlDatabase -ServerName $server.Name -DatabaseName $DatabaseName
}
New-AzureSqlDatabaseServerFirewallRule -ServerName $server.ServerName -RuleName Everything -StartIpAddress 0.0.0.0 -EndIpAddress 255.255.255.255
$passwordassecurestring = ConvertTo-SecureString -String $ServerAdminPassword -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($ServerAdminUsername, $passwordassecurestring)
$servercontext = New-AzureSqlDatabaseServerContext -ServerName $server.ServerName -Credential $credential
$storagecontext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$container = Get-AzureStorageContainer -Name $StorageAccountContainer -Context $storagecontext
$operation = Start-AzureSqlDatabaseImport -SqlConnectionContext $servercontext -StorageContainer $container -DatabaseName $DatabaseName -BlobName $StorageAccountBlobName
$startedimport = Get-Date
do {
Start-Sleep -Seconds 10
$requeststatus = Get-AzureSqlDatabaseImportExportStatus -Username $ServerAdminUsername -Password $ServerAdminPassword -ServerName $server.ServerName -RequestId $operation.RequestGuid
Write-Output $requeststatus
$currenttime = Get-Date
$currentduration = $currenttime - $startedimport
Write-Output "Import has been running for $($currentduration.TotalMinutes) minutes."
} while ($requeststatus.Status.StartsWith("Running"))
$finishedimport = Get-Date
$duration = $finishedimport - $startedimport
Write-Output "Total Minutes was $($duration.TotalMinutes) minutes."
}
}
Export-ModuleMember -Function Test-AzureSqlDatabaseImportPerformance