Bagikan melalui


Menyalin rekam jepret disk terkelola dalam langganan yang sama atau langganan yang berbeda dengan PowerShell (Windows)

Skrip ini menyalin rekam jepret disk terkelola ke langganan yang sama atau berbeda. Gunakan skrip ini untuk skenario berikut:

  1. Migrasikan rekam jepret di penyimpanan Premium (Premium_LRS) ke penyimpanan Standar (Standard_LRS atau Standard_ZRS) untuk mengurangi biaya Anda.
  2. Migrasikan rekam jepret dari penyimpanan redundan lokal (Premium_LRS, Standard_LRS) ke penyimpanan redundan zona (Standard_ZRS) untuk mendapatkan manfaat dari keandalan penyimpanan ZRS yang lebih tinggi.
  3. Pindahkan snapshot ke langganan lain di wilayah yang sama untuk waktu retensi yang lebih lama.

Jika diperlukan, instal modul Azure PowerShell menggunakan instruksi yang ditemukan 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 akun Azure, buat akun gratis sebelum memulai.

Contoh skrip

#Provide the subscription Id of the subscription where snapshot exists
$sourceSubscriptionId='yourSourceSubscriptionId'

#Provide the name of your resource group where snapshot exists
$sourceResourceGroupName='yourResourceGroupName'

#Provide the name of the snapshot
$snapshotName='yourSnapshotName'

#Set the context to the subscription Id where snapshot exists
Select-AzSubscription -SubscriptionId $sourceSubscriptionId

#Get the source snapshot
$snapshot= Get-AzSnapshot -ResourceGroupName $sourceResourceGroupName -Name $snapshotName

#Provide the subscription Id of the subscription where snapshot will be copied to
#If snapshot is copied to the same subscription then you can skip this step
$targetSubscriptionId='yourTargetSubscriptionId'

#Name of the resource group where snapshot will be copied to
$targetResourceGroupName='yourTargetResourceGroupName'

#Set the context to the subscription Id where snapshot will be copied to
#If snapshot is copied to the same subscription then you can skip this step
Select-AzSubscription -SubscriptionId $targetSubscriptionId

#We recommend you to store your snapshots in Standard storage to reduce cost. Please use Standard_ZRS in regions where zone redundant storage (ZRS) is available, otherwise use Standard_LRS
#Please check out the availability of ZRS here: https://docs.microsoft.com/en-us/Az.Storage/common/storage-redundancy-zrs#support-coverage-and-regional-availability
$snapshotConfig = New-AzSnapshotConfig -SourceResourceId $snapshot.Id -Location $snapshot.Location -CreateOption Copy -SkuName Standard_LRS

#Create a new snapshot in the target subscription and resource group
New-AzSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotName -ResourceGroupName $targetResourceGroupName 

Penjelasan skrip

Skrip ini menggunakan perintah berikut untuk membuat rekam jepret di langganan target menggunakan Id rekam jepret sumber. Setiap perintah dalam tabel ditautkan ke dokumentasi spesifik perintah.

Command Notes
New-AzSnapshotConfig Membuat konfigurasi rekam jepret yang digunakan untuk pembuatan rekam jepret. Ini termasuk Id sumber daya rekam jepret induk dan lokasi yang sama dengan rekam jepret induk.
New-AzSnapshot Membuat rekam jepret menggunakan konfigurasi rekam jepret, nama rekam jepret, dan nama grup sumber daya yang diteruskan sebagai parameter.

Langkah selanjutnya

Membuat komputer virtual dari rekam jepret

Untuk informasi selengkapnya tentang modul Azure PowerShell, lihat dokumentasi Azure PowerShell.

Sampel skrip PowerShell komputer virtual tambahan dapat ditemukan di dokumentasi Azure Windows VM.