Een back-up maken van een virtuele machine in Azure met een Bicep-sjabloon
Artikel
Met Azure Backup kunt u een back-up maken van uw Azure-VM met meerdere opties, zoals Azure Portal, PowerShell, CLI, Azure Resource Manager, Bicep, enzovoort. In dit artikel wordt beschreven hoe u een back-up maakt van een Virtuele Azure-machine met een Azure Bicep-sjabloon en Azure PowerShell. Deze quickstart is gericht op het implementeren van een Bicep-sjabloon om een Recovery Services-kluis te maken. Zie de Bicep-documentatie en de sjabloonreferentie voor meer informatie over het ontwikkelen van Bicep-sjablonen.
Bicep is een taal voor het declaratief implementeren van Azure-resources. U kunt Bicep gebruiken in plaats van JSON om uw Azure Resource Manager-sjablonen (ARM-sjablonen) te ontwikkelen. Bicep-syntaxis vermindert de complexiteit en verbetert de ontwikkelervaring. Bicep is een transparante abstractie van ARM-sjabloon JSON die alle mogelijkheden van JSON-sjablonen biedt. Tijdens de implementatie converteert bicep CLI een Bicep-bestand naar een ARM-sjabloon-JSON. In een Bicep-bestand worden de Azure-resources en resource-eigenschappen vermeld, zonder een reeks programmeeropdrachten te schrijven om resources te maken.
Resourcetypen, API-versies en eigenschappen die geldig zijn in een ARM-sjabloon, zijn ook geldig in een Bicep-bestand.
Vereisten
Zie Bicep-hulpprogramma's installeren om uw omgeving in te stellen voor Bicep-ontwikkeling.
Notitie
Installeer de nieuwste Azure PowerShell-module en de Bicep CLI, zoals beschreven in het artikel.
De sjabloon controleren
De onderstaande sjabloon is afkomstig uit Azure-quickstartsjablonen. Met deze sjabloon kunt u eenvoudige Windows-VM en Recovery Services-kluis implementeren die zijn geconfigureerd met DefaultPolicy for Protection.
Bicep
@description('Specifies a name for generating resource names.')
@maxLength(8)paramprojectNamestring
@description('Specifies the location for all resources.')paramlocationstring = resourceGroup().location
@description('Specifies the administrator username for the Virtual Machine.')paramadminUsernamestring
@description('Specifies the administrator password for the Virtual Machine.')
@secure()paramadminPasswordstring
@description('Specifies the unique DNS Name for the Public IP used to access the Virtual Machine.')paramdnsLabelPrefixstring
@description('Virtual machine size.')paramvmSizestring = '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'
])paramwindowsOSVersionstring = '2016-Datacenter'varstorageAccountName = '${projectName}store'varnetworkInterfaceName = '${projectName}-nic'varvNetAddressPrefix = '10.0.0.0/16'varvNetSubnetName = 'default'varvNetSubnetAddressPrefix = '10.0.0.0/24'varpublicIPAddressName = '${projectName}-ip'varvmName = '${projectName}-vm'varvNetName = '${projectName}-vnet'varvaultName = '${projectName}-vault'varbackupFabric = 'Azure'varbackupPolicyName = 'DefaultPolicy'varprotectionContainer = 'iaasvmcontainer;iaasvmcontainerv2;${resourceGroup().name};${vmName}'varprotectedItem = 'vm;iaasvmcontainerv2;${resourceGroup().name};${vmName}'varnetworkSecurityGroupName = 'default-NSG'resourcestorageAccount'Microsoft.Storage/storageAccounts@2021-06-01' = {
name: storageAccountNamelocation: locationsku: {
name: 'Standard_LRS'
}
kind: 'Storage'properties: {}
}
resourcepublicIPAddress'Microsoft.Network/publicIPAddresses@2020-06-01' = {
name: publicIPAddressNamelocation: locationproperties: {
publicIPAllocationMethod: 'Dynamic'dnsSettings: {
domainNameLabel: dnsLabelPrefix
}
}
}
resourcenetworkSecurityGroup'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
name: networkSecurityGroupNamelocation: locationproperties: {
securityRules: [
{
name: 'default-allow-3389'properties: {
priority: 1000access: 'Allow'direction: 'Inbound'destinationPortRange: '3389'protocol: 'Tcp'sourceAddressPrefix: '*'sourcePortRange: '*'destinationAddressPrefix: '*'
}
}
]
}
}
resourcevNet'Microsoft.Network/virtualNetworks@2020-06-01' = {
name: vNetNamelocation: locationproperties: {
addressSpace: {
addressPrefixes: [
vNetAddressPrefix
]
}
subnets: [
{
name: vNetSubnetNameproperties: {
addressPrefix: vNetSubnetAddressPrefixnetworkSecurityGroup: {
id: networkSecurityGroup.id
}
}
}
]
}
}
resourcenetworkInterface'Microsoft.Network/networkInterfaces@2020-06-01' = {
name: networkInterfaceNamelocation: locationproperties: {
ipConfigurations: [
{
name: 'ipconfig1'properties: {
privateIPAllocationMethod: 'Dynamic'publicIPAddress: {
id: publicIPAddress.id
}
subnet: {
id: '${vNet.id}/subnets/${vNetSubnetName}'
}
}
}
]
}
}
resourcevirtualMachine'Microsoft.Compute/virtualMachines@2020-06-01' = {
name: vmNamelocation: locationproperties: {
hardwareProfile: {
vmSize: vmSize
}
osProfile: {
computerName: vmNameadminUsername: adminUsernameadminPassword: adminPassword
}
storageProfile: {
imageReference: {
publisher: 'MicrosoftWindowsServer'offer: 'WindowsServer'sku: windowsOSVersionversion: 'latest'
}
osDisk: {
createOption: 'FromImage'
}
dataDisks: [
{
diskSizeGB: 1023lun: 0createOption: 'Empty'
}
]
}
networkProfile: {
networkInterfaces: [
{
id: networkInterface.id
}
]
}
diagnosticsProfile: {
bootDiagnostics: {
enabled: truestorageUri: storageAccount.properties.primaryEndpoints.blob
}
}
}
}
resourcerecoveryServicesVault'Microsoft.RecoveryServices/vaults@2020-02-02' = {
name: vaultNamelocation: locationsku: {
name: 'RS0'tier: 'Standard'
}
properties: {}
}
resourcevaultName_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
}
}
De resources die in de bovenstaande sjabloon zijn gedefinieerd, zijn:
Als u de sjabloon wilt implementeren, selecteert u Proberen om de Azure Cloud Shell te openen en plakt u vervolgens het volgende PowerShell-script in het shell-venster. Als u de code wilt plakken, klikt u met de rechtermuisknop op het shell-venster en selecteert u Plakken.
Azure PowerShell
$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$locationNew-AzResourceGroupDeployment -ResourceGroupName$resourceGroupName -TemplateUri$templateUri -projectName$projectName -adminUsername$adminUsername -adminPassword$adminPassword -dnsLabelPrefix$dnsPrefix
De implementatie valideren
Een back-uptaak starten
Met de sjabloon maakt u een virtuele machine en schakelt u back-ups in op de virtuele machine. Nadat u de sjabloon hebt geïmplementeerd, moet u een back-uptaak starten. Zie Een back-uptaak startenvoor meer informatie.
Als u geen back-up meer nodig heeft voor de virtuele machine, dan kunt u deze opschonen.
Sla het opschoonproces over om het herstellen van de VIRTUELE machine uit te proberen.
Als u een bestaande VIRTUELE machine hebt gebruikt, kunt u de uiteindelijke cmdlet Remove-AzResourceGroup overslaan om de resourcegroep en de VM te behouden.
Volg vervolgens deze stappen:
Schakel bescherming uit en verwijderen de herstelpunten en kluis.
Verwijder de resourcegroep en de bijbehorende VM-resources als volgt:
पुनर्प्राप्ति वॉल्ट और Azure बैकअप नीतियों को कार्यान्वित करना सीखने से पहले Azure बैकअप के बारे में जानें. Windows IaaS VM पुनर्प्राप्ति कार्यान्वित करना, ऑन-प्रिमाइसेस कार्यभार का बैकअप लेना और पुनर्स्थापित करना और Azure VM बैकअप प्रबंधित करना सीखें.