Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Azure Backup memungkinkan Anda mencadangkan Azure VM menggunakan beberapa opsi - seperti portal Microsoft Azure, PowerShell, CLI, Azure Resource Manager, Bicep, dan sebagainya. Artikel ini menjelaskan cara mencadangkan sebuah Mesin Virtual Azure menggunakan file Azure Bicep dan Azure PowerShell. Panduan cepat ini berfokus pada proses penerapan file Bicep untuk membuat vault Layanan Pemulihan. Untuk informasi selengkapnya tentang mengembangkan file Bicep, lihat dokumentasi Bicep dan referensi templat.
Bicep adalah bahasa pemrograman untuk menyebarkan sumber daya Azure secara deklaratif. Anda dapat menggunakan Bicep sebagai ganti JSON untuk mengembangkan templat Azure Resource Manager (templat ARM). Sintaks Bicep mengurangi kerumitan dan meningkatkan pengalaman pengembangan. Bicep adalah abstraksi transparan dari JSON templat ARM yang menyediakan semua fitur templat JSON. Selama penyebaran, Bicep CLI mengubah file Bicep menjadi JSON templat ARM. File Bicep menunjukkan status sumber daya Azure dan properti sumber daya, tanpa menulis urutan perintah pemrograman untuk membuat sumber daya.
Jenis sumber daya, versi API, dan properti yang valid dalam templat ARM, juga valid dalam file Bicep.
Prasyarat
Untuk menyiapkan lingkungan untuk pengembangan Bicep, lihat Pasang alat Bicep.
Nota
Instal modul Azure PowerShell terbaru dan Bicep CLI seperti yang dijelaskan dalam artikel.
Meninjau templat
Templat yang digunakan di bawah ini berasal dari templat mulai cepat Azure. Templat ini memungkinkan Anda untuk menyebarkan vault Windows VM dan Recovery Services sederhana yang dikonfigurasi dengan DefaultPolicy for Protection.
@description('Specifies a name for generating resource names.')
@maxLength(8)
param projectName string
@description('Specifies the location for all resources.')
param location string = resourceGroup().location
@description('Specifies the administrator username for the Virtual Machine.')
param adminUsername string
@description('Specifies the administrator password for the Virtual Machine.')
@secure()
param adminPassword string
@description('Specifies the unique DNS Name for the Public IP used to access the Virtual Machine.')
param dnsLabelPrefix string
@description('Virtual machine size.')
param vmSize string = 'Standard_A2'
@description('Specifies the Windows version for the VM. This will pick a fully patched image of this given Windows version.')
@allowed([
'2008-R2-SP1'
'2012-Datacenter'
'2012-R2-Datacenter'
'2016-Nano-Server'
'2016-Datacenter-with-Containers'
'2016-Datacenter'
'2019-Datacenter'
'2019-Datacenter-Core'
'2019-Datacenter-Core-smalldisk'
'2019-Datacenter-Core-with-Containers'
'2019-Datacenter-Core-with-Containers-smalldisk'
'2019-Datacenter-smalldisk'
'2019-Datacenter-with-Containers'
'2019-Datacenter-with-Containers-smalldisk'
])
param windowsOSVersion string = '2016-Datacenter'
var storageAccountName = '${projectName}store'
var networkInterfaceName = '${projectName}-nic'
var vNetAddressPrefix = '10.0.0.0/16'
var vNetSubnetName = 'default'
var vNetSubnetAddressPrefix = '10.0.0.0/24'
var publicIPAddressName = '${projectName}-ip'
var vmName = '${projectName}-vm'
var vNetName = '${projectName}-vnet'
var vaultName = '${projectName}-vault'
var backupFabric = 'Azure'
var backupPolicyName = 'DefaultPolicy'
var protectionContainer = 'iaasvmcontainer;iaasvmcontainerv2;${resourceGroup().name};${vmName}'
var protectedItem = 'vm;iaasvmcontainerv2;${resourceGroup().name};${vmName}'
var networkSecurityGroupName = 'default-NSG'
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'Storage'
properties: {}
}
resource publicIPAddress 'Microsoft.Network/publicIPAddresses@2020-06-01' = {
name: publicIPAddressName
location: location
properties: {
publicIPAllocationMethod: 'Dynamic'
dnsSettings: {
domainNameLabel: dnsLabelPrefix
}
}
}
resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
name: networkSecurityGroupName
location: location
properties: {
securityRules: [
{
name: 'default-allow-3389'
properties: {
priority: 1000
access: 'Allow'
direction: 'Inbound'
destinationPortRange: '3389'
protocol: 'Tcp'
sourceAddressPrefix: '*'
sourcePortRange: '*'
destinationAddressPrefix: '*'
}
}
]
}
}
resource vNet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
name: vNetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
vNetAddressPrefix
]
}
subnets: [
{
name: vNetSubnetName
properties: {
addressPrefix: vNetSubnetAddressPrefix
networkSecurityGroup: {
id: networkSecurityGroup.id
}
}
}
]
}
}
resource networkInterface 'Microsoft.Network/networkInterfaces@2020-06-01' = {
name: networkInterfaceName
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig1'
properties: {
privateIPAllocationMethod: 'Dynamic'
publicIPAddress: {
id: publicIPAddress.id
}
subnet: {
id: '${vNet.id}/subnets/${vNetSubnetName}'
}
}
}
]
}
}
resource virtualMachine 'Microsoft.Compute/virtualMachines@2020-06-01' = {
name: vmName
location: location
properties: {
hardwareProfile: {
vmSize: vmSize
}
osProfile: {
computerName: vmName
adminUsername: adminUsername
adminPassword: adminPassword
}
storageProfile: {
imageReference: {
publisher: 'MicrosoftWindowsServer'
offer: 'WindowsServer'
sku: windowsOSVersion
version: 'latest'
}
osDisk: {
createOption: 'FromImage'
}
dataDisks: [
{
diskSizeGB: 1023
lun: 0
createOption: 'Empty'
}
]
}
networkProfile: {
networkInterfaces: [
{
id: networkInterface.id
}
]
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: true
storageUri: storageAccount.properties.primaryEndpoints.blob
}
}
}
}
resource recoveryServicesVault 'Microsoft.RecoveryServices/vaults@2020-02-02' = {
name: vaultName
location: location
sku: {
name: 'RS0'
tier: 'Standard'
}
properties: {}
}
resource vaultName_backupFabric_protectionContainer_protectedItem 'Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems@2020-02-02' = {
name: '${vaultName}/${backupFabric}/${protectionContainer}/${protectedItem}'
properties: {
protectedItemType: 'Microsoft.Compute/virtualMachines'
policyId: '${recoveryServicesVault.id}/backupPolicies/${backupPolicyName}'
sourceResourceId: virtualMachine.id
}
}
Sumber daya yang ditentukan dalam templat di atas adalah:
- Microsoft.Storage/storageAccounts
- Microsoft.Network/publicIPAddresses
- Microsoft.Network/networkSecurityGroups
- Microsoft.Jaringan/virtualNetworks
- Microsoft.Network/networkInterfaces
- Microsoft.Compute/virtualMachines
- Microsoft.RecoveryServices/vaults
- Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems
Menyebarkan templat
Untuk menyebarkan templat, pilih Coba untuk membuka Azure Cloud Shell, lalu tempelkan skrip PowerShell berikut ini di jendela shell. Untuk menempelkan kode, klik kanan jendela shell lalu pilih Tempel.
$projectName = Read-Host -Prompt "Enter a project name (limited to eight characters) that is used to generate Azure resource names"
$location = Read-Host -Prompt "Enter the location (for example, centralus)"
$adminUsername = Read-Host -Prompt "Enter the administrator username for the virtual machine"
$adminPassword = Read-Host -Prompt "Enter the administrator password for the virtual machine" -AsSecureString
$dnsPrefix = Read-Host -Prompt "Enter the unique DNS Name for the Public IP used to access the virtual machine"
$resourceGroupName = "${projectName}rg"
$templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.recoveryservices/recovery-services-create-vm-and-configure-backup/main.bicep"
New-AzResourceGroup -Name $resourceGroupName -Location $location
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -projectName $projectName -adminUsername $adminUsername -adminPassword $adminPassword -dnsLabelPrefix $dnsPrefix
Validasikan penggelaran
Memulai pekerjaan cadangan
Templat membuat VM dan mengaktifkan pencadangan pada VM. Setelah menyebarkan templat, Anda perlu memulai tugas pencadangan. Untuk informasi selengkapnya, lihat Memulai Tugas Pencadangan.
Memantau pencadangan pekerjaan
Untuk memantau pekerjaan pencadangan, lihat Memantau pekerjaan pencadangan.
Membersihkan sumber daya
- Jika Anda tidak perlu lagi mencadangkan VM, Anda dapat menghapusnya.
- Untuk mencoba memulihkan VM, lewati proses pembersihan.
- Jika Anda telah menggunakan VM yang ada, Anda dapat melewati cmdlet Remove-AzResourceGroup akhir untuk menyimpan grup sumber daya dan VM.
Ikuti langkah-langkah ini:
Nonaktifkan perlindungan, hapus titik pemulihan dan vault.
Hapus grup sumber daya dan sumber daya VM terkait, sebagai berikut:
Disable-AzRecoveryServicesBackupProtection -Item $item -RemoveRecoveryPoints $vault = Get-AzRecoveryServicesVault -Name "myRecoveryServicesVault" Remove-AzRecoveryServicesVault -Vault $vault Remove-AzResourceGroup -Name "myResourceGroup"
Langkah selanjutnya
Dalam panduan memulai cepat ini, Anda membuat brankas Layanan Pemulihan, mengaktifkan perlindungan pada mesin virtual (VM), dan membuat titik pemulihan awal.
- Pelajari cara mencadangkan VM di portal Microsoft Azure.
- Pelajari cara memulihkan VM dengan cepat
- Pelajari cara membuat file Bicep.
- Pelajari cara mendekompilasi (menguraikan) templat Azure Resource Manager (templat ARM) ke file Bicep.
- Pelajari cara memulihkan Azure VM menggunakan REST API.