Hi,
We need to prepare a script for on demand or ad-hoc backup request,
if a user wants to trigger an adhoc backup before any activity, with x days of retention
can we schedule it through Automation Account?
Hi,
We need to prepare a script for on demand or ad-hoc backup request,
if a user wants to trigger an adhoc backup before any activity, with x days of retention
can we schedule it through Automation Account?
@SaurabhGada-0698 Did you get chance to look into my previous comment ? Do revert if you have further questions.
@SaurabhGada-0698 Welcome to Microsoft Q & A Community Forum. I understand you are trying to trigger on demand back up of azure vm using PowerShell. You can use below commands to trigger the on-demand backup for a virtual machine.
Here is a sample script to trigger an on-demand backup. This script assumes that you have enabled system assigned identity for automation account. Also, enable appropriate RBAC permissions to the system identity of this automation account. Otherwise, the runbook may fail.
try
{
"Logging in to Azure..."
Connect-AzAccount -Identity
}
catch {
Write-Error -Message $_.Exception
throw $_.Exception
}
Get-AzRecoveryServicesVault -Name "<recoveryvault name>" | Set-AzRecoveryServicesVaultContext
$namedContainer = Get-AzRecoveryServicesBackupContainer -ContainerType AzureVM -Status Registered -FriendlyName "<azurevmname>"
$item = Get-AzRecoveryServicesBackupItem -Container $namedContainer -WorkloadType AzureVM
$job = Backup-AzRecoveryServicesBackupItem -Item $item
References:
9 people are following this question.