2013-03-31 4 views
4

azure 데이터베이스를 백업하고 BLOB에 저장하여 복원 할 수 있어야합니다. 이 블로그를 본 적이 있지만 타사 cmdlet을 사용합니다.Powershell을 사용하여 BLOB에 Azure 데이터베이스 백업

http://weblogs.thinktecture.com/cweyer/2011/01/automating-backup-of-a-sql-azure-database-to-azure-blob-storage-with-the-help-of-powershell-and-task-scheduler.html

사람이 PowerShell을 사용하여 달성 할 수있는 방법을 위/도움말을 안내 시겠어요.

답변

0

이외의 여러 가지 방법을 설명하는 기사입니다 먼저 (here 참조) 푸른 자동화 설정이 완료 얻을.

블로우 스크립트를 편집하여 .ps1 파일로 저장하십시오. 처음으로 을 실행할 때 청색 자동화 계정과 데이터베이스 자격 증명을 묻습니다. 이 과정에서 로컬 파일에 자격 증명을 안전하게 저장합니다 (here 완료 방법 참조). 와드 시간이 지나면 저장된 자격 증명을 사용합니다. 당신은 당신이 작업 스케줄러에서 실행하도록 예약 할 수 있습니다 만족하면

.psl 파일과 암호화 된 자격 증명 파일

하나 디렉토리

에 보관해야합니다.

function Get-MyCredential 
{ 
param(
$CredPath, 
[switch]$Help 
) 
$HelpText = @" 

    Get-MyCredential 
    Usage: 
    Get-MyCredential -CredPath `$CredPath 

    If a credential is stored in $CredPath, it will be used. 
    If no credential is found, Export-Credential will start and offer to 
    Store a credential at the location specified. 

"@ 
    if($Help -or (!($CredPath))){write-host $Helptext; Break} 
    if (!(Test-Path -Path $CredPath -PathType Leaf)) { 
     Export-Credential (Get-Credential) $CredPath 
    } 
    $cred = Import-Clixml $CredPath 
    $cred.Password = $cred.Password | ConvertTo-SecureString 
    $Credential = New-Object System.Management.Automation.PsCredential($cred.UserName, $cred.Password) 
    Return $Credential 
} 


function Export-Credential($cred, $path) { 
     $cred = $cred | Select-Object * 
     $cred.password = $cred.Password | ConvertFrom-SecureString 
     $cred | Export-Clixml $path 
} 

#Create a directory with you azure server name to isolate configurations 
$FileRootPath = "C:\PowerShellScripts\AzureServerName" 

Write-Host "Getting Azure credentials" 
$AzureCred = Get-MyCredential ($FileRootPath + "AzureSyncred.txt") 

#Use Azure Automation Account 
#(If You do not have it will not work with other accounts) 
Add-AzureAccount -Credential $AzureCred 
Select-AzureSubscription -SubscriptionId "myAzureSubscriptionId" 

#DO NOT use tcp:myServerName.database.windows.net,1433 but only myServerName 
$ServerName = "myServerName" 
$Date = Get-Date -format "yyyy-MM-dd-HH-mm" 
$DatabaseName = "myTargetDatabaseName" 
$BlobName = $Date + "-" + $DatabaseName.bacpac" 

$StorageName = "myStorageAccountName" 
$ContainerName = "myContainerNameToStoreBacpacFiles" 
$StorageKey = "myStorageAccountKey" 

Write-Host "Getting database user credential" 
#DO NOT use [email protected] but only myDatabaseUsername 
$credential = Get-MyCredential ($FileRootPath + "DbSyncred.xml") 

Write-Host "Connecting to Azure database" 
$SqlCtx = New-AzureSqlDatabaseServerContext -ServerName $ServerName -Credential $credential 
Write-Host "Connecting to Blob storage" 
$StorageCtx = New-AzureStorageContext -StorageAccountName $StorageName -StorageAccountKey $StorageKey 
$Container = Get-AzureStorageContainer -Name $ContainerName -Context $StorageCtx 
Write-Host "Exporting data to blob" 
$exportRequest = Start-AzureSqlDatabaseExport -SqlConnectionContext $SqlCtx -StorageContainer $Container -DatabaseName $DatabaseName -BlobName $BlobName 

Get-AzureSqlDatabaseImportExportStatus -Request $exportRequest 

# use the below script in powershell to execute the script 
# powershell -ExecutionPolicy ByPass –File C:\PowerShellScripts\AzureServerName\mySavedScript.ps1 –noexit 
관련 문제