Azure Database - Export

Octopus.AzurePowerShell exported 2020-06-23 by bobjwalker belongs to ‘Azure’ category.

Exports a database to a bacpac

Depends on az cli

Source database requires ‘Allow Azure services and resources to access this server’ option turn on in the SQL server firewall

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Azure Account

azDbExport.AzAcct =

null

Resource Group Name

azDbExport.rgName =

null

SQL Server Name

azDbExport.sqlSvrName =

The name of the SQL Server to connect to.

Database Name

azDbExport.dbName =

The name of the database you wish to export

SQL Server Admin Name

azDbExport.adminName =

The admin name of the SQL server containing the database you wish to export

Admin Password

azDbExport.adminPwd =

The admin password of the SQL server containing the database you wish to export

Azure Blob Access Key

azDbExport.blobAccessKey =

the access key (Shared Access Key or Storage Access Key) to grant access to the storage account

Access Key Type

azDbExport.accessKeyType =

The type of key the access key represents

Container Uri

azDbExport.ContainerUri =

The URI of the container to save the exported database in. Format is: https://{StorageAccountName}.blob.core.windows.net/{ContainerName}

Backup Name

azDbExport.backupName = #{azDbExport.dbName}

The name of the file being saved. The bacpac extension (.bacpac) will be appended automatically. Defaults to DB Name

Script body

Steps based on this template will execute the following PowerShell script.

$rgname = $OctopusParameters["azDbExport.rgName"]
$svrName = $OctopusParameters["azDbExport.sqlSvrName"]
$dbName = $OctopusParameters["azDbExport.dbName"]
$adminName = $OctopusParameters["azDbExport.adminName"]
$adminPwd = $OctopusParameters["azDbExport.adminPwd"]
$accessKey = $OctopusParameters["azDbExport.blobAccessKey"]
$accessKeyType = $OctopusParameters["azDbExport.accessKeyType"]
$containerUri = $OctopusParameters["azDbExport.ContainerUri"]
$backupName = $OctopusParameters["azDbExport.backupName"]

$backupUri = "$containerUri/$backupName.bacpac"

if([string]::IsNullOrEmpty($rgname))
{
	throw "resource group name is not provided"
}

if([string]::IsNullOrEmpty($svrName))
{
	throw "sql server name is not provided"
}

if([string]::IsNullOrEmpty($dbName))
{
	throw "database name not provided"
}
# admin name, password and access key will not be validated in favor of security

if([string]::IsNullOrEmpty($accessKeyType))
{
	throw "access key type not provided"
}

if([string]::IsNullOrEmpty($containerUri))
{
	throw "containerUri not provided"
}

if([string]::IsNullOrEmpty($backupName))
{
	throw "backup name not provided"
}

write-host "starting db export"
az sql db export --resource-group $rgname --server $svrName --name $dbName --admin-password $adminPwd --admin-user $adminName --storage-key $accessKey --storage-key-type $accessKeyType --storage-uri $backupUri

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "c1d6e994-16c8-4896-b6f2-57f9558184ea",
  "Name": "Azure Database - Export",
  "Description": "Exports a database to a bacpac\n\n*Depends on az cli*\n\n*Source database requires 'Allow Azure services and resources to access this server' option turn on in the SQL server firewall*",
  "Version": 2,
  "ExportedAt": "2020-06-23T21:41:09.205Z",
  "ActionType": "Octopus.AzurePowerShell",
  "Author": "bobjwalker",
  "Packages": [],
  "Parameters": [
    {
      "Id": "0bf888db-667e-4303-a4bd-c721bf1de0ad",
      "Name": "azDbExport.AzAcct",
      "Label": "Azure Account",
      "HelpText": null,
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "AzureAccount"
      }
    },
    {
      "Id": "d5885f12-d921-4ce8-afc2-384f0b82daae",
      "Name": "azDbExport.rgName",
      "Label": "Resource Group Name",
      "HelpText": null,
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "03b281f5-e1e2-42a8-bb43-317bc4981393",
      "Name": "azDbExport.sqlSvrName",
      "Label": "SQL Server Name",
      "HelpText": "The name of the SQL Server to connect to.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "e67ef4ab-3084-45e7-81df-7cda76baf2fc",
      "Name": "azDbExport.dbName",
      "Label": "Database Name",
      "HelpText": "The name of the database you wish to export",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "6da5679d-1c84-4fb4-8f91-22fd91b50baa",
      "Name": "azDbExport.adminName",
      "Label": "SQL Server Admin Name",
      "HelpText": "The admin name of the SQL server containing the database you wish to export",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "44e1a2a3-6b9b-44a5-893d-d26f14166b52",
      "Name": "azDbExport.adminPwd",
      "Label": "Admin Password",
      "HelpText": "The admin password of the SQL server containing the database you wish to export",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Id": "40715e88-4892-48c6-83f2-603c0193439b",
      "Name": "azDbExport.blobAccessKey",
      "Label": "Azure Blob Access Key",
      "HelpText": "the access key (Shared Access Key or Storage Access Key) to grant access to the storage account",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Id": "fcb94050-5f81-410e-9ed9-c5f52653f9c6",
      "Name": "azDbExport.accessKeyType",
      "Label": "Access Key Type",
      "HelpText": "The type of key the access key represents",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "SharedAccessKey|Shared Access Key\nStorageAccessKey|Storage Access Key"
      }
    },
    {
      "Id": "a8631db7-556e-4532-aacd-595266c4347f",
      "Name": "azDbExport.ContainerUri",
      "Label": "Container Uri",
      "HelpText": "The URI of the container to save the exported database in.  Format is: `https://{StorageAccountName}.blob.core.windows.net/{ContainerName}`",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "85686923-5e57-4b1d-8dd7-6b5ca263ba42",
      "Name": "azDbExport.backupName",
      "Label": "Backup Name",
      "HelpText": "The name of the file being saved. The bacpac extension (`.bacpac`) will be appended automatically.  Defaults to DB Name",
      "DefaultValue": "#{azDbExport.dbName}",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Azure.AccountId": "#{azDbExport.AzAcct}",
    "Octopus.Action.Script.ScriptBody": "$rgname = $OctopusParameters[\"azDbExport.rgName\"]\n$svrName = $OctopusParameters[\"azDbExport.sqlSvrName\"]\n$dbName = $OctopusParameters[\"azDbExport.dbName\"]\n$adminName = $OctopusParameters[\"azDbExport.adminName\"]\n$adminPwd = $OctopusParameters[\"azDbExport.adminPwd\"]\n$accessKey = $OctopusParameters[\"azDbExport.blobAccessKey\"]\n$accessKeyType = $OctopusParameters[\"azDbExport.accessKeyType\"]\n$containerUri = $OctopusParameters[\"azDbExport.ContainerUri\"]\n$backupName = $OctopusParameters[\"azDbExport.backupName\"]\n\n$backupUri = \"$containerUri/$backupName.bacpac\"\n\nif([string]::IsNullOrEmpty($rgname))\n{\n\tthrow \"resource group name is not provided\"\n}\n\nif([string]::IsNullOrEmpty($svrName))\n{\n\tthrow \"sql server name is not provided\"\n}\n\nif([string]::IsNullOrEmpty($dbName))\n{\n\tthrow \"database name not provided\"\n}\n# admin name, password and access key will not be validated in favor of security\n\nif([string]::IsNullOrEmpty($accessKeyType))\n{\n\tthrow \"access key type not provided\"\n}\n\nif([string]::IsNullOrEmpty($containerUri))\n{\n\tthrow \"containerUri not provided\"\n}\n\nif([string]::IsNullOrEmpty($backupName))\n{\n\tthrow \"backup name not provided\"\n}\n\nwrite-host \"starting db export\"\naz sql db export --resource-group $rgname --server $svrName --name $dbName --admin-password $adminPwd --admin-user $adminName --storage-key $accessKey --storage-key-type $accessKeyType --storage-uri $backupUri\n"
  },
  "Category": "Azure",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-database-export.json",
  "Website": "/step-templates/c1d6e994-16c8-4896-b6f2-57f9558184ea",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQB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