3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windows AzureのSQL データベースをPowerShellでバックアップ

Posted at

PowerShellを使ったSQL データベースのバックアップ

PowerShellの起動

Windows Azure PowerShellを開きます。

準備

ストレージ名を指定して、初期設定を行います。

Get-AzureSubscription -Current | Set-AzureSubscription -CurrentStorageAccountName storage1

各種設定

初期設定を行います。
SQLのサーバー名、ストレージのキー、ストレージ名、DB名、コンテナ名、Blob名(ファイル名)を変数に設定しておきます。

$dateStr = Get-Date -Format "yyyy-MM-dd-HH-mm"
$ServerName = "serverxxx"
$StorageKey = "xxxxxxxxx...."
$StorageName = "storage1"
$DatabaseName = "sampledb"
$ContainerName = "db-bak"
$BlobName = "db-"+$dateStr+".bacpac"

資格情報の入力ダイアログが表示されるのでSQL データベースのユーザー名、パスワードを入力します。

$credential = Get-Credential

エクスポートの準備

$SqlCtx = New-AzureSqlDatabaseServerContext -ServerName $ServerName -Credential $credential
$StorageCtx = New-AzureStorageContext -StorageAccountName $StorageName -StorageAccountKey $StorageKey
$Container = Get-AzureStorageContainer -Name $ContainerName -Context $StorageCtx

エクスポート実行

$exportRequest = Start-AzureSqlDatabaseExport -SqlConnectionContext $SqlCtx -StorageContainer $Container -DatabaseName $DatabaseName -BlobName $BlobName

5~10分くらいかかるので経過確認の確認

Get-AzureSqlDatabaseImportExportStatus -Request $exportRequest

完了すると
Status : Completed
になります。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?