PowerShell script exchange
Post Reply
matteu
Veeam Legend
Posts: 857
Liked: 136 times
Joined: May 11, 2018 8:42 am
Contact:

Migrate backup from one job to an other

Post by matteu »

Hello,

I would like to change job governance and I need to move existing backup job to new backup job.
For this I create this script :

Code: Select all

#VMs to migrate
$VMs = "VM1","VM2"
$SourceJob = "SourceJobName"
$TargetJob = "DestinationJobName"

Foreach ($VM in $VMs)
{
    $SourceJobObj = Get-VBRBackup -Name $SourceJob
    $TargetJobObj = Get-VBRJob -Name $TargetJob

    #Move backup from source backup job to target backup job
    Move-VBRBackup -Backup $SourceJobObj -Job $TargetJobObj -Name $VM -RunAsync
}


It's working fine but that means I need to know the source job where are my VM.

I would like to do it without specify the backup job source.

What could help me to know what is the backup job used to backup my VM ? (I use TAG on backup job so I think I need to use Get-VBRRestorePoint but I would like only backup job and no backup copy or other)

My VM are never in more than 1 backup job

Thanks for your help
matteu
Veeam Legend
Posts: 857
Liked: 136 times
Joined: May 11, 2018 8:42 am
Contact:

Re: Migrate backup from one job to an other

Post by matteu »

I make this, it seems to work but maybe you have a better idea ?

It's only for vmware backup and I get only the latest restore point of the VM to know which job is the source job
I removed the -AsSync for the move-vbrbackup because it causes issue when VM I need to move are on the same source job... It's sad to implement this parameter on the cmdlet and not done the job on the Veeam side to be able to manage different VM from the same source job. Maybe an improvment to do for next version.
It take lot's of more time to do it sequentially ...

Code: Select all

$VMs = "vm1","vm2"
$AllBackupJob = Get-VBRBackup | Where-Object {$_.TypeToString -eq "VMware Backup"}
$TargetJob = "bkpjob-destination"
Foreach ($VM in $VMs)
{

    $Query = Get-VBRRestorePoint -Backup $AllBackupJob -Name $VM
    #If VM is in current backup job
    if ($query) {
        #Get last restore point created
        $LastJob = $Query | Sort-Object CreationTime -Descending | Select-Object -First 1
    }
    #Get backup job name used for the last restore point
    $SourceJob = $LastJob.GetSourceJob().Name

    $SourceJobObj = Get-VBRBackup -Name $SourceJob
    $TargetJobObj = Get-VBRJob -Name $TargetJob

    #Move backup from source backup job to target backup job
    Move-VBRBackup -Backup $SourceJobObj -Job $TargetJobObj -Name $VM
}
matteu
Veeam Legend
Posts: 857
Liked: 136 times
Joined: May 11, 2018 8:42 am
Contact:

Re: Migrate backup from one job to an other

Post by matteu »

Is there an easier way to achieve it ?
david.domask
Veeam Software
Posts: 2741
Liked: 630 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Migrate backup from one job to an other

Post by david.domask »

Hi matteu,

Your second approach uses an unsupported method with GetSourceJob(), but probably it's the fastest way.

The supported way to do this with your current code would be to pull the BackupID property from one of the returned restore points, search your $AllBackupJob array for that backup by its UUID, and the CBackup object will have a JobName property. Quick example would be replacing $SourceJob = $LastJob.GetSourceJob().Name this with:

$backupId = $SourceJob.BackupId
$sourceBackup = $AllbackupJob | Where-Object {$_.id -eq $backupId}
$jobName = $sourceBackup.JobName


> I removed the -AsSync for the move-vbrbackup because it causes issue when VM I need to move are on the same source job... It's sad to implement this parameter on the cmdlet and not done the job on the Veeam side to be able to manage different VM from the same source job. Maybe an improvment to do for next version.

As for this, can you elaborate a bit more on the challenge here? What issues did you observe?
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests