Skip to main content
Answer

DR Automation using PowerShell

  • May 30, 2022
  • 8 comments
  • 254 views

chandrasinghe

Hi Community,

 For automated disaster recovery process. Need help to develop PowerShell scripts.

  1. Add backup repository
  2. Decrypt backup
  3. Import backups

Code up to now as bellow

$account = Get-VBRAmazonAccount -AccessKey "XXXXXXXXXXXX"
$connect = Connect-VBRAmazonS3Service -Account $account -RegionType Global -ServiceType CapacityTier
$bucket = Get-VBRAmazonS3Bucket -Connection $connect -Name "veeam-backup"
$folder = Get-VBRAmazonS3Folder -Name "S3-Folder" -Bucket $bucket -Connection $connect
$securepassword = Read-Host -Prompt "Enter password" -AsSecureString
$key = Add-VBREncryptionKey -Password $securepassword
Add-VBRAmazonS3Repository -Name "AmazonS3Repository" -Connection $connect -AmazonS3Folder $folder -DecryptBackups -DecryptionKey $key

But <-DecryptBackups -DecryptionKey $key> option doesnt work, 

error prompt as below

Add-VBRAmazonS3Repository : A parameter cannot be found that matches parameter name 'DecryptBackups'.

At line:1 char:99

+ ...  -Connection $connect -AmazonS3Folder $folder -DecryptBackups -Decryp ...

+                                                   ~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Add-VBRAmazonS3Repository], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,Veeam.Backup.PowerShell.Cmdlets.AddVBRAmazonS3Repository

Best answer by chandrasinghe

Finally I was able to automate VM recovery via PowerShell except for credentials. 

Add backup repository to Veeam

$account = Get-VBRAmazonAccount -AccessKey "xxxxxxxxxxx"
$connect = Connect-VBRAmazonS3Service -Account $account -RegionType Global -ServiceType CapacityTier
$bucket = Get-VBRAmazonS3Bucket -Connection $connect -Name "veeam-backup"
$folder = Get-VBRAmazonS3Folder -Name "s3-folder-name" -Bucket $bucket -Connection $connect
$securepassword = Read-Host -Prompt "Enter password" -AsSecureString
$key = Add-VBREncryptionKey -Password $securepassword
Add-VBRAmazonS3Repository -Name "AmazonS3Repository" -Connection $connect -AmazonS3Folder $folder

Import Backup from S3 repository

$repository = Get-VBRObjectStorageRepository -Name "AmazonS3Repository"
$securepassword = Read-Host -Prompt "Enter password" -AsSecureString
$key = Add-VBREncryptionKey -Password $securepassword
Mount-VBRObjectStorageRepository -Repository $repository -EncryptionKey $key

Decrypt backup Jobs (Specify password)
$encryptedbackup = Get-VBRImportedEncryptedBackup -Name "backup-job" Get-VBRImportedEncryptedBackupHint -Backup $encryptedbackup Set-VBREncryptedBackupPassword -Backup $encryptedbackup -Password "xxxxxxxxxxxxx"

Setup aws credentials$creds = Get-VBRAmazonAccount -AccessKey "xxxxxxxxxx"
Set-VBRAmazonAccount -Account $creds -SecretKey "xxxxxxxxxxxxxxxxxxx"

Restore VM to AWS Ec2


$restorepoint = Get-VBRBackup -Name  "backup-job" | Get-VBRRestorePoint -Name "INF-VM" | Sort-Object –Property CreationTime –Descending | Select-Object -First 1

$account = Get-VBRAmazonAccount -Id "xxxxxxxxxxxxxxxxxx"

$region = Get-VBRAmazonEC2Region -Account $account -RegionType Global -Name "region-name"

$config = New-VBRAmazonEC2DiskConfiguration -DiskName "INF-VM-flat.vmdk" -Include -DiskType GeneralPurposeSSD

$instance = Get-VBRAmazonEC2InstanceType -Region $region -Name "ec2-type"

$vpc = Get-VBRAmazonEC2VPC -Region $region

$sgroup = Get-VBRAmazonEC2SecurityGroup -VPC $vpc -Name "security-group-name"

$subnet = Get-VBRAmazonEC2Subnet -VPC $vpc -Name "x.x.x.x/xx"

Start-VBRVMRestoreToAmazon -RestorePoint $restorepoint -Region $region -LicenseType  BYOL -InstanceType $instance -VMName "Restored VM" -DiskConfiguration $config -VPC $vpc -SecurityGroup $sgroup -Subnet $subnet -Reason "Data recovery"

 

 

8 comments

JMeixner
Forum|alt.badge.img+16
  • On the path to Greatness
  • May 30, 2022

Did you try to enclose your parameter variables in quotes (“)?

E.g.:

-DecryptBackups -DecryptionKey “$key”


vNote42
Forum|alt.badge.img+12
  • On the path to Greatness
  • May 31, 2022

I am definitely no AWS-expert, but it seems these parameters (-DecryptBackups -DecryptionKey) doesn't exist for Add-VBRAmazonS3Repository 

https://helpcenter.veeam.com/docs/backup/powershell/add-vbramazons3repository.html?ver=110

 


marcofabbri
Forum|alt.badge.img+12
  • On the path to Greatness
  • June 1, 2022

@chandrasinghe did you take the command from here?

Set-VBRAzureExternalRepository -ExternalRepository $repository -DecryptBackups -DecryptionKey $key

https://helpcenter.veeam.com/docs/backup/powershell/set-vbrazureexternalrepository.html?ver=110

because as @vNote42 said, maybe those parameters doesn’t exist for AWS.


chandrasinghe
  • Author
  • Comes here often
  • June 9, 2022

Did you try to enclose your parameter variables in quotes (“)?

E.g.:

-DecryptBackups -DecryptionKey “$key”

do we need put variables inside quotes.


chandrasinghe
  • Author
  • Comes here often
  • June 9, 2022

I am definitely no AWS-expert, but it seems these parameters (-DecryptBackups -DecryptionKey) doesn't exist for Add-VBRAmazonS3Repository 

https://helpcenter.veeam.com/docs/backup/powershell/add-vbramazons3repository.html?ver=110

 

I got it from here : https://helpcenter.veeam.com/docs/backup/powershell/add-vbramazons3externalrepository.html?zoom_highlight=decryptbackups&ver=110


chandrasinghe
  • Author
  • Comes here often
  • Answer
  • June 9, 2022

Finally I was able to automate VM recovery via PowerShell except for credentials. 

Add backup repository to Veeam

$account = Get-VBRAmazonAccount -AccessKey "xxxxxxxxxxx"
$connect = Connect-VBRAmazonS3Service -Account $account -RegionType Global -ServiceType CapacityTier
$bucket = Get-VBRAmazonS3Bucket -Connection $connect -Name "veeam-backup"
$folder = Get-VBRAmazonS3Folder -Name "s3-folder-name" -Bucket $bucket -Connection $connect
$securepassword = Read-Host -Prompt "Enter password" -AsSecureString
$key = Add-VBREncryptionKey -Password $securepassword
Add-VBRAmazonS3Repository -Name "AmazonS3Repository" -Connection $connect -AmazonS3Folder $folder

Import Backup from S3 repository

$repository = Get-VBRObjectStorageRepository -Name "AmazonS3Repository"
$securepassword = Read-Host -Prompt "Enter password" -AsSecureString
$key = Add-VBREncryptionKey -Password $securepassword
Mount-VBRObjectStorageRepository -Repository $repository -EncryptionKey $key

Decrypt backup Jobs (Specify password)
$encryptedbackup = Get-VBRImportedEncryptedBackup -Name "backup-job" Get-VBRImportedEncryptedBackupHint -Backup $encryptedbackup Set-VBREncryptedBackupPassword -Backup $encryptedbackup -Password "xxxxxxxxxxxxx"

Setup aws credentials$creds = Get-VBRAmazonAccount -AccessKey "xxxxxxxxxx"
Set-VBRAmazonAccount -Account $creds -SecretKey "xxxxxxxxxxxxxxxxxxx"

Restore VM to AWS Ec2


$restorepoint = Get-VBRBackup -Name  "backup-job" | Get-VBRRestorePoint -Name "INF-VM" | Sort-Object –Property CreationTime –Descending | Select-Object -First 1

$account = Get-VBRAmazonAccount -Id "xxxxxxxxxxxxxxxxxx"

$region = Get-VBRAmazonEC2Region -Account $account -RegionType Global -Name "region-name"

$config = New-VBRAmazonEC2DiskConfiguration -DiskName "INF-VM-flat.vmdk" -Include -DiskType GeneralPurposeSSD

$instance = Get-VBRAmazonEC2InstanceType -Region $region -Name "ec2-type"

$vpc = Get-VBRAmazonEC2VPC -Region $region

$sgroup = Get-VBRAmazonEC2SecurityGroup -VPC $vpc -Name "security-group-name"

$subnet = Get-VBRAmazonEC2Subnet -VPC $vpc -Name "x.x.x.x/xx"

Start-VBRVMRestoreToAmazon -RestorePoint $restorepoint -Region $region -LicenseType  BYOL -InstanceType $instance -VMName "Restored VM" -DiskConfiguration $config -VPC $vpc -SecurityGroup $sgroup -Subnet $subnet -Reason "Data recovery"

 

 


vNote42
Forum|alt.badge.img+12
  • On the path to Greatness
  • June 9, 2022

its a different cmdlet. You use Add-VBRAmazonS3Repository in your script.


vNote42
Forum|alt.badge.img+12
  • On the path to Greatness
  • June 9, 2022

Thanks for sharing your solution!