Skip to content
Permalink
Browse files

Azure restore changes (#5366)

* more azure funtionality and checking

* adding example and more detail to CBH

* adding in EXAMPLE header

* fixing it for envs other than mine

Just adding features, so safe to add in.
  • Loading branch information...
Stuart-Moore committed Apr 15, 2019
1 parent 01af519 commit 29d69aaddde77b6b9f2ca42ec8bfe035190eadf2
Showing with 34 additions and 14 deletions.
  1. +34 −14 functions/Backup-DbaDatabase.ps1
@@ -94,13 +94,14 @@ function Backup-DbaDatabase {
Internal parameter
.PARAMETER AzureBaseUrl
The URL to the base container of an Azure Storage account to write backups to.
The URL(s) to the base container of an Azure Storage account to write backups to.
If specifying the AzureCredential parameter you can only provide 1 value as page blobs do not support multiple URLs
If useing Shared Access keys, you may specify as many URLs as you want, as long as a corresponding credential exists on the source server.
If specified, the only other parameters than can be used are "CopyOnly", "Type", "CompressBackup", "Checksum", "Verify", "AzureCredential", "CreateFolder".
.PARAMETER AzureCredential
The name of the credential on the SQL instance that can write to the AzureBaseUrl, only needed if using Storage access keys
If using SAS credentials, the command will look for a credential with a name matching the AzureBaseUrl
If using SAS credentials, the command will look for a credential with a name matching the AzureBaseUrl. As page blobs are used with this option we force the number of files to 1 and ignore any value passed in for BlockSize or MaxTransferSize
.PARAMETER NoRecovery
This is passed in to perform a tail log backup if needed
@@ -168,6 +169,11 @@ function Backup-DbaDatabase {
PS C:\> Backup-DbaDatabase -SqlInstance Sql2017 -Database master -BackupFileName NUL
Performs a backup of master, but sends the output to the NUL device (ie; throws it away)
.EXAMPLE
PS C:\ Backup-DbaDatabase -SqlInstance Sql2016 -Database stripetest -AzureBaseUrl https://az.blob.core.windows.net/sql,https://dbatools.blob.core.windows.net/sql
Performs a backup of the database striptest, striping it across the 2 Azure blob containers at https://az.blob.core.windows.net/sql and https://dbatools.blob.core.windows.net/sql, assuming that Shared Access Signature credentials for both containers exist on the source instance
#>
[CmdletBinding(DefaultParameterSetName = "Default", SupportsShouldProcess)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] #For AzureCredential
@@ -194,7 +200,7 @@ function Backup-DbaDatabase {
[int]$MaxTransferSize,
[int]$BlockSize,
[int]$BufferCount,
[string]$AzureBaseUrl,
[string[]]$AzureBaseUrl,
[string]$AzureCredential,
[switch]$NoRecovery,
[switch]$BuildPath,
@@ -219,6 +225,16 @@ function Backup-DbaDatabase {
return
}

if ((Test-Bound 'AzureCredential') -and (Test-Bound 'BlockSize')) {
Write-Message -Level Warning -Message 'BlockSize cannot be specified when backup up to an Azure page blob, ignoring'
$BlockSize = $null
}

if ((Test-Bound 'AzureCredential') -and (Test-Bound 'MaxTransferSize')) {
Write-Message -Level Warning -Message 'MaxTransferSize cannot be specified when backup up to an Azure page blob ignoring'
$MaxTransferSize = $null
}

if ($SqlInstance) {
try {
$Server = Connect-SqlInstance -SqlInstance $SqlInstance -SqlCredential $SqlCredential -AzureUnsupported
@@ -258,24 +274,28 @@ function Backup-DbaDatabase {
}
if ($BlockSize) {
if ($BlockSize -notin (0.5kb, 1kb, 2kb, 4kb, 8kb, 16kb, 32kb, 64kb)) {

Stop-Function -Message "Block size must be one of 0.5kb,1kb,2kb,4kb,8kb,16kb,32kb,64kb"
return
}
}
if ('' -ne $AzureBaseUrl) {
if ($null -ne $AzureBaseUrl) {
$AzureBaseUrl = $AzureBaseUrl.Trim("/")
if ('' -ne $AzureCredential) {
Write-Message -Message "Azure Credential name passed in, will proceed assuming it's value" -Level Verbose
$FileCount = 1
} else {
Write-Message -Message "AzureUrl and no credential, testing for SAS credential"
if (Get-DbaCredential -SqlInstance $server -Name $AzureBaseUrl.trim("/")) {
Write-Message -Message "Found a SAS backup credental" -Level Verbose
} else {
Stop-Function -Message "You must provide the credential name for the Azure Storage Account"
return
foreach ($baseUrl in $AzureBaseUrl) {
Write-Message -Message "AzureUrl and no credential, testing for SAS credential"
if (Get-DbaCredential -SqlInstance $server -Name $AzureBaseUrl.trim("/")) {
Write-Message -Message "Found a SAS backup credental" -Level Verbose
} else {
Stop-Function -Message "You must provide the credential name for the Azure Storage Account"
return
}
}
}
$FileCount = $AzureBaseUrl.count
$BackupDirectory = $AzureBaseUrl
}

@@ -393,7 +413,7 @@ function Backup-DbaDatabase {

$backup.CopyOnly = $copyonly
$backup.Action = $SMOBackupType
if ('' -ne $AzureBaseUrl -and $null -ne $AzureCredential) {
if ($null -ne $AzureBaseUrl -and $null -ne $AzureCredential) {
$backup.CredentialName = $AzureCredential
}

@@ -477,7 +497,7 @@ function Backup-DbaDatabase {
}


if ('' -eq $AzureBaseUrl -and $BackupDirectory) {
if ($null -eq $AzureBaseUrl -and $BackupDirectory) {
$FinalBackupPath = $FinalBackupPath | ForEach-Object { [IO.Path]::GetFullPath($_) }
}

@@ -490,7 +510,7 @@ function Backup-DbaDatabase {

foreach ($backupfile in $FinalBackupPath) {
$device = New-Object Microsoft.SqlServer.Management.Smo.BackupDeviceItem
if ('' -ne $AzureBaseUrl) {
if ($null -ne $AzureBaseUrl) {
$device.DeviceType = "URL"
} else {
$device.DeviceType = "File"

0 comments on commit 29d69aa

Please sign in to comment.
You can’t perform that action at this time.