- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试了多个 powershell 脚本来执行 azure VM 备份和恢复,但它们似乎都不起作用或不太有效。任何人都可以分享 powershell 脚本来创建 VM 备份并通过 azure devops 管道在 azure 中恢复。
PowerShell 脚本:
<#
.SYNOPSIS
Written By John Lewis
email: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84eeebeaebf7c4e8edf2e1aae7ebe9" rel="noreferrer noopener nofollow">[email protected]</a>
Ver 1.1
v 1.2 updates - minor fixes
v 1.1 updates - Added Pre-Checks
v 1.0 updates - RTM
Deploys Azure Backup Vault and configures Azure VMs to leverage vault. Provides automated restore to new VM.
.PARAMETER Action
.PARAMETER backupvmname
.PARAMETER backupvmrg
.PARAMETER rg
.PARAMETER policyname
.PARAMETER containertype
.PARAMETER Location
.PARAMETER wrkloadtype
.PARAMETER vaultname
.PARAMETER createvmname
.PARAMETER createvmrg
.PARAMETER vaultrg
.PARAMETER vnet
.PARAMETER vnetrg
.PARAMETER createvmsubnet
.EXAMPLE
.\AZRM-VMBackup.ps1 -csvimport -csvfile C:\temp\backupservers.csv
.EXAMPLE
.\AZRM-VMBackup.ps1 -action createpolicy -vaultname myvault -vaultrg myres -policyname mypolicy
.EXAMPLE
.\AZRM-VMBackup.ps1 -action createvault -vaultname myvault -vaultrg myres
.EXAMPLE
.\AZRM-VMBackup.ps1 -action addvmcreatevault -backupvmname myvm -backupvmrg myres -vaultname myvault -vaultrg myres
.EXAMPLE
.\AZRM-VMBackup.ps1 -action restorevm -createvmname myvm -createvmrg myres -vaultrg backuprg -vaultname myvaultname -vnet vnet -vnetrg myvnetrg
#>
[CmdletBinding(DefaultParameterSetName = 'default')]
Param(
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateNotNullorEmpty()]
[ValidateSet("createpolicy","createvault","addvmcreatevault","addvmtovault","restorevm","executebackup","getstatus")]
[string]
$Action = 'createvault',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$vaultrg = "vault",
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$storeagerg = $createvmrg,
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateNotNullorEmpty()]
[string]
$location = "East US",
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$vaultname = "vault",
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$backupvmname = '',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$backupvmrg = '',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateNotNullorEmpty()]
[string]
$backupvmlocation = $location,
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$createvmname = '',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$createvmrg = '',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateNotNullorEmpty()]
[string]
$createvmlocation = $location,
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true,Position=4)]
[ValidateNotNullorEmpty()]
[Alias("createvmvnet")]
[string]
$VNetName = 'vnet',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateNotNullorEmpty()]
[string]
$vnetrg = $createvmrg,
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$policyname = 'policy',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$containertype = 'AzureVM',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$wrkloadtype = 'AzureVM',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$provider = "Microsoft.RecoveryServices",
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$Profile = "profile",
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$csvfile = -join $workfolder + "\azrm-vmbackup.csv",
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[Alias("csv")]
[switch]
$csvimport,
[Parameter(Mandatory=$False)]
[string]
$GenerateName = -join ((65..90) + (97..122) | Get-Random -Count 6 | % {[char]$_}) + "rmp",
[Parameter(Mandatory=$False)]
[string]
$StorageName = $createvmname + 'str',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateSet("Standard_LRS","Standard_GRS")]
[string]
$StorageType = 'Standard_GRS',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateNotNullorEmpty()]
[Alias("int1")]
[string]
$InterfaceName1 = $createvmname + '_nic1',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[Alias("int2")]
[string]
$InterfaceName2 = $createvmname + "_nic2",
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$SubscriptionID = '',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$TenantID = '',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateSet("InProgress","Completed")]
[string]
$status = 'InProgress',
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[ValidateRange(0,8)]
[ValidateNotNullorEmpty()]
[Alias("createvmsubnet")]
[Int]
$Subnet1 = 4
)
$workfolder = Split-Path $script:MyInvocation.MyCommand.Path
$ProfileFile = $workfolder+'\'+$profile+'.json'
$restorejson = $workfolder+'\'+ 'config.json'
Function validate-profile {
$comparedate = (Get-Date).AddDays(-14)
$fileexist = Test-Path $ProfileFile -NewerThan $comparedate
if($fileexist)
{
$az = Import-AzureRmContext -Path $ProfileFile
$subid = $az.Context.Subscription.Id
Set-AzureRmContext -SubscriptionId $subid | Out-Null
Write-Host "Using $ProfileFile"
}
else
{
Write-Host "Please enter your credentials"
Add-AzureRmAccount
Save-AzureRmContext -Path $ProfileFile -Force
Write-Host "Saved Profile to $ProfileFile"
exit
}
}
Function csv-run {
param(
[string] $csvin = $csvfile
)
$GetPath = test-path -Path $csvin
if(!$csvin)
{exit}
else {
Write-Host $GetPath "File Exists"
import-csv -Path $csvin -Delimiter ',' -ErrorAction SilentlyContinue -InformationAction SilentlyContinue | ForEach-Object{.\AZRM-VMBackup.ps1 -VMName $_.VMName -rg $_.rg -Action $_.Action -vmrg $_.vmrg -servaultname $_.servaultname }
}
}
Function Check-StorageName
{
param(
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]$StorageName = $StorageName
)
$checkname = Get-AzureRmStorageAccountNameAvailability -Name $StorageName | Select-Object -ExpandProperty NameAvailable
if($checkname -ne 'False') {
Write-Host "Storage Account Found..."
$script:StorageNameVerified = $StorageName.ToLower()
}
else
{
$script:StorageNameVerified = $StorageName.ToLower()
Create-Storage
}
}
#region Create Storage
Function Create-Storage {
param(
[string]$StorageName = $script:StorageNameVerified,
[string]$StorageType = $StorageType,
[string]$containerName = 'vhds',
[string]$Location = $Location,
[string]$storeagerg = $storeagerg
)
Write-Host "Starting Storage Creation..."
$script:StorageAccount = New-AzureRmStorageAccount -ResourceGroupName $storeagerg -Name $StorageName.ToLower() -Type $StorageType -Location $Location -ErrorAction Stop -WarningAction SilentlyContinue
Write-Host "Completed Storage Creation" -ForegroundColor White
}
Function Check-Vnet {
$vnetexists = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $vnetrg -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if(!$vnetexists)
{
Write-Host "$VNetName does not exists!"
break
}
else
{ $existvnet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $vnetrg
$addspace = $existvnet.AddressSpace | Select-Object -ExpandProperty AddressPrefixes
$namespace = $existvnet.Name
$existvnet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $vnetrg
$addsubnet = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $existvnet
$sub = $addsubnet.AddressPrefix
$subname = $addsubnet.Name
$nsg = $addsubnet.NetworkSecurityGroup
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $existvnet | ft Name,AddressPrefix -AutoSize -Wrap -HideTableHeaders
Write-Host " "
Write-Host "VNET CONFIGURATION - Existing VNET" -ForegroundColor Cyan
Write-Host " "
Write-Host "Active VNET: $VnetName in resource group $vnetrg"
Write-Host "Address Space: $addspace "
Write-Host "Subnet Ranges: $sub "
Write-Host "Subnet Names: $subname "
}
}
Function Check-VaultExists {
$vaultexists = Get-AzureRmRecoveryServicesVault -Name $vaultname -ResourceGroupName $vaultrg -ErrorAction Stop -WarningAction SilentlyContinue -InformationAction SilentlyContinue
if(!$vaultexists)
{
Write-Host "Specified vault $vaultname does not exist!" -ForegroundColor Red
break
}
}
function Check-VaultNullValues {
if(!$vaultrg) {
Write-Host "Please select -vaultrg" -ForegroundColor Red
exit
}
elseif(!$vaultname) {
Write-Host "Please Enter -vaultname" -ForegroundColor Red
exit
}
elseif(!$Location) {
Write-Host "Please Enter -Location" -ForegroundColor Red
exit
}
}
function Check-BackupVMNullValues {
if(!$backupvmrg) {
Write-Host "Please select -backupvmrg" -ForegroundColor Red
exit
}
elseif(!$backupvmname) {
Write-Host "Please Enter -backupvmname" -ForegroundColor Red
exit
}
elseif(!$Location) {
Write-Host "Please Enter -Location" -ForegroundColor Red
exit
}
}
function Check-CreateVMNullValues {
if(!$createvmrg) {
Write-Host "Please select -createvmrg" -ForegroundColor Red
exit
}
elseif(!$createvmname) {
Write-Host "Please Enter -createvmname" -ForegroundColor Red
exit
}
if(!$backupvmrg) {
Write-Host "Please select -backupvmrg" -ForegroundColor Red
exit
}
elseif(!$backupvmname) {
Write-Host "Please Enter -backupvmname" -ForegroundColor Red
exit
}
elseif(!$Location) {
Write-Host "Please Enter -Location" -ForegroundColor Red
exit
}
}
function Check-StorageNullValues {
if(!$storeagerg) {
Write-Host "Please select -storage" -ForegroundColor Red
exit
}
elseif(!$StorageName) {
Write-Host "Please Enter -createvmname" -ForegroundColor Red
exit
}
elseif(!$Location) {
Write-Host "Please Enter -Location" -ForegroundColor Red
exit
}
}
function Check-VNETNullValues {
if(!$vnetrg) {
Write-Host "Please select -vnetrg" -ForegroundColor Red
exit
}
elseif(!$VNetName) {
Write-Host "Please Enter -vnetname" -ForegroundColor Red
exit
}
elseif(!$Location) {
Write-Host "Please Enter -Location" -ForegroundColor Red
exit
}
}
function Reg-Provider {
param($provider = $provider)
Register-AzureRmResourceProvider -ProviderNamespace $provider
}
Function Provision-RG
{
Param(
[string]$rg = $vaultrg
)
New-AzureRmResourceGroup -Name $rg -Location $Location –Confirm:$false -WarningAction SilentlyContinue -Force | Out-Null
}
Function Check-VMExists {
param(
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$Location = $Location,
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$rg = $backupvmrg,
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$VMName = $backupvmname
)
$extvm = Get-AzureRmVm -Name $VMName -ResourceGroupName $rg -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if(!$extvm)
{
Write-Host "$VMName does not exist, please verify the VM exists" -ForegroundColor Yellow
Break
}
else {Write-Host "Restoration VM found" -ForegroundColor Green}
} #
#endregion
Function Configure-Backup {
param(
[Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$true)]
[string]
$action = $action
)
switch ($action)
{
"createvault" {
Check-VaultNullValues
Write-Host "Creating new Backup Vault $vaultname"
Write-Config
Provision-RG
Create-Vault
Get-CurrentPolicies
Create-Policy
Write-Completion
}
"createpolicy" {
Write-Host "Creating new Policy"
Write-Config
Check-VaultExists
Get-CurrentPolicies
Create-Policy
Write-Completion
}
"addvmtovault" {
Check-VMExists
Check-VaultExists
Write-Host "Adding VM $backupvmname to $vaultname"
Write-Config
Get-CurrentPolicies
AddVM-Vault
Write-Completion
}
"executebackup" {
Write-Host "Executing backup of $backupvmname to $vaultname"
Check-VMExists
Write-Config
Check-BackupVMNullValues
Get-CurrentPolicies
TriggerBackup-Vault
Write-Completion
}
"addvmcreatevault" {
Check-VaultNullValues
Write-Host "Creating new Backup Vault $vaultname"
Write-Config
Provision-RG
Create-Vault
Create-Policy
Check-BackupVMNullValues
Check-VaultExists
Check-VMExists
Write-Host "Adding VM $backupvmname to $vaultname"
Get-CurrentPolicies
AddVM-Vault
Write-Completion
}
"restorevm" {
Check-CreateVMNullValues
Check-VNETNullValues
Check-Vnet
Check-StorageNullValues
Check-VMExists
Check-StorageName
Write-Host "Restoring VM Backup from $backupvmname to $createvmname"
Write-Config
Restore-VMVHD
Create-VM
Write-Completion
}
"getstatus" {
Write-Host "Obtaining current job information"
Get-JobProgress
}
default{"An unsupported backup command was used"}
}
exit
}
Function Get-JobProgress {
param(
$status = $status
)
Get-AzureRmRecoveryservicesBackupJob –Status $status
}
function Create-Vault {
New-AzureRmResourceGroup -Name $vaultrg -Location $Location –Confirm:$false -WarningAction SilentlyContinue -Force | Out-Null
New-AzureRmRecoveryServicesVault -Name $vaultname -ResourceGroupName $vaultrg -Location $location
$vault1 = Get-AzureRmRecoveryServicesVault –Name $vaultname
Set-AzureRmRecoveryServicesBackupProperties -Vault $vault1 -BackupStorageRedundancy GeoRedundant
}
function Get-Context {
param($vaultname = $vaultname)
Get-AzureRmRecoveryServicesVault -Name $vaultname | Set-AzureRmRecoveryServicesVaultContext
}
function Get-CurrentPolicies {
param(
$vaultname = $vaultname,
$wrkloadtype = $wrkloadtype
)
Get-AzureRmRecoveryServicesVault -Name $vaultname | Set-AzureRmRecoveryServicesVaultContext
$schPol = Get-AzureRmRecoveryServicesBackupSchedulePolicyObject -WorkloadType $wrkloadtype
$retPol = Get-AzureRmRecoveryServicesBackupRetentionPolicyObject -WorkloadType $wrkloadtype
}
function Create-Policy {
param(
$vaultname = $vaultname,
$policyname = $policyname,
$wrkloadtype = $wrkloadtype
)
Get-AzureRmRecoveryServicesVault -Name $vaultname | Set-AzureRmRecoveryServicesVaultContext
$schPol = Get-AzureRmRecoveryServicesBackupSchedulePolicyObject -WorkloadType $wrkloadtype
$retPol = Get-AzureRmRecoveryServicesBackupRetentionPolicyObject -WorkloadType $wrkloadtype
New-AzureRmRecoveryServicesBackupProtectionPolicy -Name $policyname -WorkloadType $wrkloadtype -RetentionPolicy $retPol -SchedulePolicy $schPol -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -InformationAction SilentlyContinue
$script:pol = Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name $policyname
}
function Modify-Policy {
param(
$vaultname = $vaultname,
$policyname = $policyname,
$wrkloadtype = $wrkloadtype
)
$retPol = Get-AzureRmRecoveryServicesBackupRetentionPolicyObject -WorkloadType "AzureVM"
$retPol.DailySchedule.DurationCountInDays = 365
$pol= Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name $policyname
Set-AzureRmRecoveryServicesBackupProtectionPolicy -Policy $pol -RetentionPolicy $RetPol
}
function TriggerBackup-Vault {
param(
$vaultname = $vaultname,
$backupvmname = $backupvmname,
$containertype = "AzureVM"
)
Get-AzureRmRecoveryServicesVault -Name $vaultname | Set-AzureRmRecoveryServicesVaultContext
$namedContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType $containertype -Status "Registered" -FriendlyName $backupvmname
$item = Get-AzureRmRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM"
$job = Backup-AzureRmRecoveryServicesBackupItem -Item $item
}
function AddVM-Vault {
param(
$vaultname = $vaultname,
$backupvmname = $backupvmname,
$containertype = "AzureVM",
$vaultrg = $backupvmrg,
$policyname = $policyname
)
Get-AzureRmRecoveryServicesVault -Name $vaultname | Set-AzureRmRecoveryServicesVaultContext
$script:pol = Get-AzureRmRecoveryServicesBackupProtectionPolicy -Name $policyname
Enable-AzureRmRecoveryServicesBackupProtection -Policy $script:pol -Name $backupvmname -ResourceGroupName $vaultrg
$namedContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType $containertype -Status "Registered" -FriendlyName $backupvmname
$item = Get-AzureRmRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM"
$job = Backup-AzureRmRecoveryServicesBackupItem -Item $item
$job
}
Function Get-RestorePoint {
Get-AzureRmRecoveryServicesVault -Name $vaultname | Set-AzureRmRecoveryServicesVaultContext
$startDate = (Get-Date).AddDays(-7)
$endDate = Get-Date
$rp = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $backupitem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime()
$rp[0]
}
Function Write-Config {
param(
)
Write-Host " "
$time = " Start Time " + (Get-Date -UFormat "%d-%m-%Y %H:%M:%S")
Write-Host BACKUP/RESTORE CONFIGURATION - $time -ForegroundColor Cyan
Write-Host " "
Write-Host "Operation: $Action " -ForegroundColor White
Write-Host " "
}
Function Write-Completion {
param(
)
Write-Host " "
$time = " End Time " + (Get-Date -UFormat "%d-%m-%Y %H:%M:%S")
Write-Host BACKUP/RESTORE CONFIGURATION - $time -ForegroundColor Cyan
Write-Host " "
Write-Host "Completed operation: $Action " -ForegroundColor White
Write-Host " "
}
function Restore-VMVHD {
param(
$vaultname = $vaultname,
$storeagerg = $storeagerg,
$StorageName = $script:StorageNameVerified,
$backupvmname = $backupvmname
)
Get-AzureRmRecoveryServicesVault -Name $vaultname | Set-AzureRmRecoveryServicesVaultContext
$namedContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" –Status "Registered" -FriendlyName $backupvmname -WarningAction SilentlyContinue -InformationAction SilentlyContinue -ErrorAction Stop
$backupitem = Get-AzureRmRecoveryServicesBackupItem –Container $namedContainer –WorkloadType "AzureVM" -InformationAction SilentlyContinue -WarningAction SilentlyContinue -ErrorAction Stop
$startDate = (Get-Date).AddDays(-7)
$endDate = Get-Date
$rp = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $backupitem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime() -WarningAction SilentlyContinue -ErrorAction Stop -InformationAction SilentlyContinue
$rp[0]
Write-Host "Preparing Restore Job"
$restorejob = Restore-AzureRmRecoveryServicesBackupItem -RecoveryPoint $rp[0] -StorageAccountName $StorageName -StorageAccountResourceGroupName $storeagerg -WarningAction SilentlyContinue -InformationAction SilentlyContinue -ErrorAction Stop
Wait-AzureRmRecoveryServicesBackupJob -Job $restorejob -Timeout 43200 -WarningAction SilentlyContinue -InformationAction SilentlyContinue -ErrorAction Stop
Write-Host "Restore Job Running"
$script:restorejob = $restorejob
$restorejob = Get-AzureRmRecoveryServicesBackupJob -Job $script:restorejob -InformationAction SilentlyContinue -WarningAction SilentlyContinue -ErrorAction Stop
$JobDetails = Get-AzureRmRecoveryServicesBackupJobDetails -Job $restorejob -InformationAction SilentlyContinue -WarningAction SilentlyContinue -ErrorAction Stop
$properties = $JobDetails.properties
$properties
$storageAccountName = $properties["Target Storage Account Name"]
$containerName = $properties["Config Blob Container Name"]
$blobName = $properties["Config Blob Name"]
Write-Host $storageAccountName
Write-Host $blobName
Write-Host $containerName
Write-Host "Completed restore job"
Set-AzureRmCurrentStorageAccount -Name $storageaccountname -ResourceGroupName $storeagerg
$destination_path = $restorejson
Get-AzureStorageBlobContent -Container $containerName -Blob $blobName -Destination $destination_path -ErrorAction Stop -WarningAction SilentlyContinue -InformationAction SilentlyContinue -Force -Confirm:$false
$obj = ((Get-Content -Path $destination_path -Raw -Encoding Unicode)).TrimEnd([char]0x00) | ConvertFrom-Json
Write-Host "Exported json configuration file to $destination_path"
$vm = New-AzureRmVMConfig -VMSize $obj.'properties.hardwareProfile'.vmSize -VMName $createvmname -ErrorAction Stop -WarningAction SilentlyContinue -InformationAction SilentlyContinue
Set-AzureRmVMOSDisk -VM $vm -Name "osdisk" -VhdUri $obj.'properties.StorageProfile'.osDisk.vhd.Uri -CreateOption "Attach" -WarningAction SilentlyContinue -ErrorAction Stop -InformationAction SilentlyContinue
$vm.StorageProfile.OsDisk.OsType = $obj.'properties.StorageProfile'.OsDisk.OsType
foreach($dd in $obj.'properties.StorageProfile'.DataDisks)
{
$vm = Add-AzureRmVMDataDisk -VM $vm -Name "datadisk1" -VhdUri $dd.vhd.Uri -DiskSizeInGB 128 -Lun $dd.Lun -CreateOption "Attach"
}
Write-Host "Completed data disk configuration"
$pip = New-AzureRmPublicIpAddress -Name $InterfaceName1 -ResourceGroupName $createvmrg -Location $createvmlocation -AllocationMethod "Dynamic" –Confirm:$false -WarningAction SilentlyContinue -ErrorAction Stop -Force -InformationAction SilentlyContinue
Write-Host "Completed public ip creation"
$script:VNet = Get-AzureRMVirtualNetwork -Name $VNetName -ResourceGroupName $vnetrg | Set-AzureRmVirtualNetwork
$script:Interface1 = New-AzureRmNetworkInterface -Name $InterfaceName1 -ResourceGroupName $createvmrg -Location $createvmlocation -SubnetId $VNet.Subnets[$Subnet1].Id -PublicIpAddressId $pip.Id –Confirm:$false -WarningAction SilentlyContinue -ErrorAction Stop -EnableIPForwarding -Force
$script:VirtualMachine = Add-AzureRmVMNetworkInterface -VM $vm -Id $script:Interface1.Id -Primary -WarningAction SilentlyContinue -ErrorAction Stop -InformationAction SilentlyContinue
Write-Host "Completed vm prep"
}
Function Login-AddAzureRmProfile
{
Add-AzureRmAccount -WarningAction SilentlyContinue
}
Function Create-VM
{
Write-Host "Creating VM"
New-AzureRmVM -ResourceGroupName $createvmrg -Location $createvmlocation -VM $script:VirtualMachine
}
try {
Get-AzureRmResourceGroup -Location $Location -ErrorAction Stop | Out-Null
}
catch {
Write-Host -foregroundcolor Yellow `
"User has not authenticated, use Add-AzureRmAccount or $($_.Exception.Message)"; `
Login-AddAzureRmProfile
}
Reg-Provider
if($csvimport) {
try {
csv-run
}
catch {
Write-Host -foregroundcolor Yellow `
"$($_.Exception.Message)"; `
break
}
}
try {
Configure-Backup
}
catch {
Write-Host -foregroundcolor Yellow `
"$($_.Exception.Message)"; `
break
}
错误消息:
当我从运行书籍自动化帐户运行时,出现以下错误。提供运行时参数来运行上述脚本,并保留 CSVIMPORT 参数的值。
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'Path' because it is null.
at System.Management.Automation.ParameterBinderController.BindPositionalParametersInSet(UInt32 validParameterSets, Dictionary`2 nextPositionalParameters, CommandParameterInternal argument, ParameterBindingFlags flags, ParameterBindingException& bindingException)
at System.Management.Automation.ParameterBinderController.BindPositionalParameters(Collection`1 unboundArguments, UInt32 validParameterSets, UInt32 defaultParameterSet, ParameterBindingException& outgoingBindingException)
at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Environments Context
------------ -------
{[AzureCloud, AzureCloud], [AzureChinaCloud, AzureChinaCloud], [AzureUSGovernment, AzureUSGovernment]} Microsoft.Azur...
A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: Are you sure you want to register the provider 'Microsoft.RecoveryServices'
最佳答案
param (
[Parameter(Mandatory=$false)][String]$ResourceGroupName,
[Parameter(Mandatory=$false)][String]$ServicePrincipalName,
[Parameter(Mandatory=$false)][String]$ServicePrincipalPass,
[Parameter(Mandatory=$false)][String]$SubscriptionId,
[Parameter(Mandatory=$false)][String]$TenantId,
[Parameter(Mandatory=$false)][String]$VMname,
[Parameter(Mandatory=$false)][String]$vaultname
)
$targetVault = Get-AzRecoveryServicesVault -ResourceGroupName $ResourceGroupName -Name $vaultname
$targetVault.ID
Get-AzRecoveryServicesBackupProtectionPolicy -WorkloadType "AzureVM" -VaultId $targetVault.ID
Get-AzRecoveryServicesVault -Name $vaultname | Set-AzRecoveryServicesVaultContext
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -Name $policyname
Enable-AzRecoveryServicesBackupProtection -ResourceGroupName $ResourceGroupName -Name $VMname -Policy $policy
$backupcontainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -FriendlyName $VMname
$item = Get-AzRecoveryServicesBackupItem -Container $backupcontainer -WorkloadType "AzureVM"
$backupjob=Backup-AzRecoveryServicesBackupItem -Item $item
echo $backupjob
#$Backupstatus=Get-AzRecoveryservicesBackupJob
#Wait-AzRecoveryServicesBackupJob -Job $joblist[0] -Timeout 43200 -VaultId $targetVault.ID
Get-AzRecoveryservicesBackupJob
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName $VMname -VaultId $targetVault.ID
$backupitem = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType "AzureVM" -VaultId $targetVault.ID
echo "Please wait for backup to complete - Backup is in progress"
start-sleep -s 30
$joblist = Get-AzRecoveryservicesBackupJob –Status "InProgress" -VaultId $targetVault.ID
$joblist[0]
while (!$rp.ContainerName)
{
$startDate = (Get-Date).AddDays(-7)
$endDate = Get-Date
$rp = Get-AzRecoveryServicesBackupRecoveryPoint -Item $backupitem -StartDate $startdate.ToUniversalTime() -EndDate $enddate.ToUniversalTime() -VaultId $targetVault.ID
start-sleep -s 30
$rp[0]
Write-Host -NoNewline "Waiting 30 seconds for" $VMName "VM to backup"
}
Get-AzRecoveryservicesBackupJob
echo "Backup is completed successfully"
关于azure - 用于从 azure devops 管道自动执行 azure Linux VM 备份和恢复的 Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70835589/
市场是否支持 Azure Devops Server 2020?我最近构建了一个扩展并添加了对 ADO Server 2019 的支持,但是当我更新安装目标以包含新的服务器版本时,我在市场中没有看到任
在公司,我们将 Azure Devops 工作区的 URL 从 https://oldname.visualstudio.com 更改为至 https://dev.azure.com/newname
我想将 SSH 公钥添加到运行我的 yaml 管道的 Azure DevOps 帐户。根据这篇文章:Azure DevOps API Add public key在使用 PAT token 进行身份验
Azure CLI与 Azure DevOps extension已更换 VSTS CLI .但我找不到有关如何使用 Azure CLI 和 Azure DevOps 扩展连接到 Team Found
我正在尝试使用 API 在 Azure devops 中创建/更新工作项。如果项目没有任何关系,我可以创建/更新它。但是,如果我指定关系,例如亲子然后我得到以下错误: TF401349:发生意外错误,
我们有一个每晚安排的管道运行测试并将结果发布到测试运行。我们可以看到测试运行的 url,因为它是由 PublishTestResults@2 任务生成的。我想通过向一组用户发送测试运行的 devops
我在 azure devops 中有 2 个变量 Var1= A,B,C Var2= 1,2 我需要在以下条件下运行一个任务 Var1=A,B,C & Var2=1,2 Var1=A & Var2=1
我正在尝试运行 container job在本地构建和缓存的 Docker 镜像(来自 Dockerfile)中运行,而不是从注册表中拉取镜像。根据我目前的测试,代理只尝试从注册表中提取图像,而不是在
我有以下配置:Azure DevOps 服务器版本 Dev18.M170.8 trigger: none # No CI build pr: none # Not for pull requests
Azure DevOps 是否禁止人们在创建合并请求时添加/删除所需的审阅者? 我已经设置了“自动包含审稿人”的政策,其中包含一组必需的审稿人。 但创建 PR 的任何人仍然可以轻松地将其他人添加到所需
在 Azure DevOps 中,我有一个项目管理员组。它的权限设置为除了 删除共享的 Analytics View &编辑共享的 Analytics View 是允许的。 有一个团队和区域设置,项目
我在 azure devops 中找到了以下任务定义: - task: DotNetCoreCLI@2 name: 'CleanProjectsBeforeBuild' displayName
TL;DR - 是否有 Azure DevOps 管道任务用于在构建过程中格式化代码?我一直没能找到一个,但真的会发现它很有用。 我的团队使用免费的 CodeMaid “美化”(格式化)C# 代码的
我正在尝试从我在 Azure DevOps 中的项目的根目录中获取 dist 文件。但无论我做什么,我都会继续收到此错误: ##[error]Error: ENOENT: no such file o
我想在发布时设置通知。我以前可以这样做,但现在我无法为不同的项目设置它。我不知道 Azure DevOps 中是否发生了某些变化,或者我搞砸了自己。 Azure 告诉我指定一个有效的筛选器,但我没有要
我正在尝试设置构建管道以在特定代理池上运行。目前它坚持在“Azure Pipelines”池上工作: 但是我无法更改构建管道的代理池(至少我不确定如何)。 我的 YAML 如下所示: trigger:
我正在尝试使用一些使用条件编译符号的项目在 Azure DevOps 中设置构建。构建不断失败,因为它似乎没有看到我的符号。任何想法在哪里应用设置? 我有两个共享一些代码的项目,符号基本上用于控制项目
我正在寻找一种在 Azure DevOps .yaml 文件中设置动态需求名称的方法。 现在我们有一些由 Azure DevOps 服务随机选择的自托管构建代理,但有时我们需要选择一个代理来调查它为什
当我们在 Azure DevOps 中创建一个新的 Pull Request 时,我们最近注意到 Reviewer 在默认情况下是 Optional 的。 这引起了一些困惑,据我所知,过去总是默认要求
使用继承的进程 - 我们不能修改 Reason 或 Root Cause 选项列表值?如果我们不能对其进行定制以适应我们的流程,那么专业组织如何实际使用它? https://docs.microsof
我是一名优秀的程序员,十分优秀!