Ekspor/Salin cuplikan terkelola sebagai VHD ke akun penyimpanan di wilayah berbeda dengan PowerShell
Skrip ini mengekspor snapshot terkelola ke akun penyimpanan di wilayah yang berbeda. Skrip ini pertama-tama akan membuat URI SAS dari snapshot dan kemudian menggunakannya untuk menyalinnya ke akun penyimpanan di wilayah yang berbeda. Gunakan skrip ini untuk mempertahankan cadangan disk yang dikelola di wilayah yang berbeda untuk pemulihan bencana.
Jika perlu, instal modul Azure PowerShell menggunakan petunjuk yang ada di panduan Azure PowerShell, lalu jalankan Connect-AzAccount
untuk membuat koneksi dengan Azure. Selain itu, Anda harus memiliki kunci publik SSH bernama id_rsa.pub
di direktori .ssh profil pengguna Anda.
Jika Anda tidak memiliki langganan Azure, buat akun gratis Azure sebelum memulai.
Skrip sampel
#Provide the subscription Id of the subscription where snapshot is created
$subscriptionId = "yourSubscriptionId"
#Provide the name of your resource group where snapshot is created
$resourceGroupName ="yourResourceGroupName"
#Provide the snapshot name
$snapshotName = "yourSnapshotName"
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://docs.microsoft.com/en-us/Az.Storage/storage-dotnet-shared-access-signature-part-1
$sasExpiryDuration = "3600"
#Provide storage account name where you want to copy the snapshot.
$storageAccountName = "yourstorageaccountName"
#Name of the storage container where the downloaded snapshot will be stored
$storageContainerName = "yourstoragecontainername"
#Provide the key of the storage account where you want to copy snapshot.
$storageAccountKey = 'yourStorageAccountKey'
#Provide the name of the VHD file to which snapshot will be copied.
$destinationVHDFileName = "yourvhdfilename"
# Set the context to the subscription Id where Snapshot is created
Select-AzSubscription -SubscriptionId $SubscriptionId
#Generate the SAS for the snapshot
$sas = Grant-AzSnapshotAccess -ResourceGroupName $ResourceGroupName -SnapshotName $SnapshotName -DurationInSecond $sasExpiryDuration -Access Read
#Create the context for the storage account which will be used to copy snapshot to the storage account
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
#Copy the snapshot to the storage account
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $storageContainerName -DestContext $destinationContext -DestBlob $destinationVHDFileName
Penjelasan skrip
Skrip ini menggunakan perintah berikut untuk membuat URI SAS snapshot terkelola dan menyalin snapshot ke akun penyimpanan menggunakan URI SAS. Setiap perintah dalam tabel ditautkan ke dokumentasi spesifik perintah.
Perintah | Catatan |
---|---|
Grant-AzSnapshotAccess | Menghasilkan SAS URI untuk rekam jepret yang digunakan untuk menyalinnya ke akun penyimpanan. |
New-AzureStorageContext | Membuat konteks akun penyimpanan menggunakan nama dan kunci akun. Konteks ini dapat digunakan untuk melakukan operasi baca/tulis pada akun penyimpanan. |
Start-AzureStorageBlobCopy | Menyalin VHD yang mendasar dari rekam jepret ke akun penyimpanan |
Langkah berikutnya
Membuat disk terkelola dari VHD
Membuat mesin virtual dari disk terkelola
Untuk informasi selengkapnya tentang modul Azure PowerShell, lihat dokumentasi Azure PowerShell.
Sampel skrip PowerShell komputer virtual tambahan dapat ditemukan dalam dokumentasi Azure Linux VM.