Code: Select all
#Limitations of this script:
# - Per Backup job only one OS type is possible and EnableFUSEProtocol need to be set for Linux/Unix
# - This script assumes that it is executed on a second B&R Server that is just used for rescan. If you run this scipt on the original VBR server, disable the rescan part
# - Object Storage rescan on second VBR need rescan of all Repositories for SOBR dependancy verification. Be aware of this when you have multiple Repositories as it can take some time.
$vbrserver = "win2"
$vbruser = "Administrator"
$vbrpassword = "xxxxx" #suggest to encrypt the password with Microsoft Machine Key encryption
$vbrjob = "VMsWINObject"
$scanserver = "win2"
$scancredentials = "win2\scanwin"
$repotorescan = "Wasabi1"
$decryptionkeysdescription = "key1"
# Only needed for v10 and older. Add the Veeam PowerShell snapin - if it already is loaded continue silently with no error
#Add-PSSnapin VeeamPSSnapin -ErrorAction SilentlyContinue
#connect to your backup server
Write-Host "------------------------------------------------------------------"
Write-Host "------------------------------------------------------------------"
Write-Host "------------------------------------------------------------------"
Write-Host "------------------------------------------------------------------"
Write-Host "------------------------------------------------------------------"
Write-Host "------------------------------------------------------------------"
Write-Host "------------------------------------------------------------------"
Write-Host "Connect to VBR:"
Disconnect-VBRServer
Connect-VBRServer -Server $vbrserver -user $vbruser -password $vbrpassword
# Rescan Repository to check for new restore points (only needed if backup is done by other B&R server
Write-Host "------------------------------------------------------------------"
Write-Host "Start Repo Sync:"
$repositoryselected = Get-VBRObjectStorageRepository -Name $repotorescan
Write-Host "Type:"
$repositoryselected.Type
If ( ($repositoryselected.Type -eq "AmazonS3Compatible") -or ($repositoryselected.Type -eq "AmazonS3") -or ($repositoryselected.Type -eq "AzureBlob")){
Write-Host "Object Storage detected"
Unmount-VBRObjectStorageRepository -Repository $repositoryselected -force
$key = Get-VBREncryptionKey -Description $decryptionkeysdescription
Mount-VBRObjectStorageRepository -Repository $repositoryselected -EncryptionKey $key
Rescan-VBREntity -AllRepositories -Wait
} ELSE {
Write-Host "Standard Storage detected"
Get-VBRBackupRepository -Name $repotorescan | Rescan-VBREntity -Wait
}
# The backup variable $backup is populated by the cmdlet Get-VBRBackup which will return info regarding the backup data
$backup = Get-VBRBackup -Name $vbrjob
$backup
# Provide the IP or hostname of the target server where the iSCSI volume will be mounted
$targetServerName = $scanserver
# Provide the credentials to access the remote server example: lab\administrator
# These must be stored within the Credentials manager in Veeam Backup & Replication
$TargetAdminCreds = Get-VBRCredentials -name $scancredentials
# Filter the restore points by unique Object ID to get the virtual machines
Write-Host "------------------------------------------------------------------"
Write-Host "List of VMs within the Job:"
$filter = Get-VBRRestorePoint -Backup $backup | Sort-Object –Property CreationTime | Select -Last 1 | Select-Object Name
$filter
Write-Host "------------------------------------------------------------------"
Write-Host "Mounting VMs...:"
foreach ($vm in $filter) {
# Get-VBRRestorePoint is where you find the last restore point you wish to use
$restorepoint = Get-VBRRestorePoint -Backup $backup -Name $vm.Name | Sort-Object –Property CreationTime | Select -Last 1
# Publish the disk(s) for the restore point
#$session = Publish-VBRBackupContent -RestorePoint $restorepoint -EnableFUSEProtocol -TargetServerName $targetServerName -TargetServerCredentials $TargetAdminCreds
$session = Publish-VBRBackupContent -RestorePoint $restorepoint -TargetServerName $targetServerName -TargetServerCredentials $TargetAdminCreds
# Obtaining information about mounted disks
$contentInfo = Get-VBRPublishedBackupContentInfo -Session $session
Write-Host "`nBackup Job Name:" $session.BackupName "`nRestore Point time:" $session.RestorePoint "`nVM Name:" $session.PublicationName
# Produce a report showing what mount points were published and where
foreach ($contentType in $contentInfo) {
Write-Host "================================"
$disks = $contentType.Disks
Write-Host "Mounted Disk:" $disks.DiskName
Write-Host "Mounted At:" $disks.MountPoints
Write-Host "Mounted As:" $contentType.Mode
Write-Host "Available From:" $contentType.ServerIps "(Port:" $contentType.ServerPort ")"
Write-Host "Available Via:" $disks.AccessLink
Write-Host "================================"
}
}
#Scansoftware commands goes here
Write-Host "Now the scan software can scan the backups."
Write-Host "On the Linux scan server they can be found at /tmp/Veeam.Mount.FS on Windows it is mounted to c:\VeeamFLR"
Write-Host "This demo waits now until you have checked that the restore point was mounted. Press enter if you want to unmount the backup."
# Pause for demo, remove in final code
Pause
#Get all Publish sessions and remove them all.
$unpubsession = Get-VBRPublishedBackupContentSession
Unpublish-VBRBackupContent -Session $unpubsession
# Close VBR connection
Disconnect-VBRServer