backup single VM (not all VMs) within job?

PowerShell script exchange

backup single VM (not all VMs) within job?

Veeam Logoby mark.harre » Sat Jan 14, 2012 11:44 am

Hi,

we have a weekly backup job for about 12 VMs.
Is it possible to backup a single VM (not all VMs) in the job without creating a separate temp job? For example if i want to manually backup a single VM before an update. I am trying to limit/consolidate the number jobs and restore points and if I create a new job i can't take advantage of deduplication and my retore point policy for the weekly job.

ps we are using version 5 but intend to upgrade to version 6 soon.

thx
Mark
mark.harre
Influencer
 
Posts: 12
Liked: never
Joined: Tue Dec 21, 2010 1:29 pm
Full Name: Mark Harre

Re: backup single VM (not all VMs) within job?

Veeam Logoby Sethbartlett » Sat Jan 14, 2012 10:38 pm

There is no way to backup a single VM in a job in 5 or 6. The only time this can really happen is if the job failed on that one VM, you can then do a retry to just do that one VM.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: backup single VM (not all VMs) within job?

Veeam Logoby ThomasMc » Sun Jan 15, 2012 1:58 am 2 people like this post

If you have the Veeam Snapin install then you could use this ;)

Create Folder "C:\VeeamScripts"
Save Code to file "C:\VeeamScripts\SingleVMBackup.ps1"

Code: Select all
#* Load Veeam snapin
asnp VeeamPSSnapin -ErrorAction SilentlyContinue
#* User Input
$jobName = Read-Host "Enter Job Name"
$vmName = Read-Host "Enter VM Name"

#* Find the job that has our VM
$job = Get-VBRJob | ?{$_.Name -eq $jobName}

#* Get all objects in job apart from our target VM
$execObjs = $job.GetObjectsInJob() | ?{$_.Name -ne $vmName}

#* Exclude the objects from the job(*Note: this isn't removing the objects
#* from the job)
Remove-VBRJobObject -Job $job -Objects $execObjs

#* Start the job only backing upi the target VM
Start-VBRJob -Job $job

#* Find the exclude job objects
$incObjs = $job | Get-VBRJobObject | ?{$_.Type -eq "Exclude"}

#* Delete the exclude objects(*Note: this tells VBR to include them again
foreach ($obj in $incObjs) {
   $obj.Delete()
}


Create shortcut on your desktop with the path

Code: Select all
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\VeeamScripts\SingleVMBackup.ps1"


and then double click it.
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: backup single VM (not all VMs) within job?

Veeam Logoby tsightler » Sun Jan 15, 2012 3:31 am

I used to use this basic trick with V5, but have you tested this with V6? I don't think it works. Last time I tried it seems that if the exact same object is included in the job and also excluded from the job that it still backs it up. The include appears to override the exclude if the object is the same.
tsightler
Veeam Software
 
Posts: 4836
Liked: 1786 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: backup single VM (not all VMs) within job?

Veeam Logoby ThomasMc » Sun Jan 15, 2012 4:04 am

Seems to work ok for me Tom (6.0.0.158 x64)

*Note 4 Objects in job
Image
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: backup single VM (not all VMs) within job?

Veeam Logoby jkcouch » Sun Jan 15, 2012 4:53 am

Cool Thomas. I think I have just the use for it. Clever!!

However I think that there should be a way to easly backup one vm without having to create a job for it. I see real value in that.
jkcouch
Enthusiast
 
Posts: 30
Liked: never
Joined: Sun Jun 26, 2011 7:02 pm
Full Name: Jeff Couch

Re: backup single VM (not all VMs) within job?

Veeam Logoby tsightler » Sun Jan 15, 2012 3:01 pm

Good to know Thomas, I'll have to test again. I was actually morning the loss of this little "shortcut" to backing up a single VM.
tsightler
Veeam Software
 
Posts: 4836
Liked: 1786 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: backup single VM (not all VMs) within job?

Veeam Logoby mark.harre » Mon Jan 16, 2012 7:58 am

Thx Thomas,
I will try the script.
rgds,
Mark
mark.harre
Influencer
 
Posts: 12
Liked: never
Joined: Tue Dec 21, 2010 1:29 pm
Full Name: Mark Harre

Re: backup single VM (not all VMs) within job?

Veeam Logoby Daveyd » Tue Jan 17, 2012 1:07 am

I'm interested in knowing how you make out Mark. I have 3 VMs each running multiple instances of MYSQL. I have them separated into 3 different jobs due to the fact that I could not exclude 1 or 2 of the VMs from being backed up at any point in time. I would like to combine all 3 servers into 1 job for better dedupe ratios and have the ability not to backup 1 or 2 of the VMs in the 3 VM job at any time.
Daveyd
Expert
 
Posts: 272
Liked: 10 times
Joined: Thu May 20, 2010 4:17 pm
Full Name: Dave DeLollis

Re: backup single VM (not all VMs) within job?

Veeam Logoby ThomasMc » Fri Jan 20, 2012 10:19 pm

Daveyd wrote:I'm interested in knowing how you make out Mark. I have 3 VMs each running multiple instances of MYSQL. I have them separated into 3 different jobs due to the fact that I could not exclude 1 or 2 of the VMs from being backed up at any point in time. I would like to combine all 3 servers into 1 job for better dedupe ratios and have the ability not to backup 1 or 2 of the VMs in the 3 VM job at any time.

I've tried it many times now and works as you would want.
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: backup single VM (not all VMs) within job?

Veeam Logoby Backerupper » Fri Sep 27, 2013 8:21 pm

Has anyone had a chance to tweak this for v7 yet?

I found two issues but can only fix one :?

First Issue:
Code: Select all
#* Exclude the objects from the job(*Note: this isn't removing the objects
#* from the job)
Remove-VBRJobObject -Job $job -Objects $execObjs

Change to
Code: Select all
Remove-VBRJobObject -Objects $execObjs

Remove-VBRJobObject was updated to not include the -Job parameter in v7
Removing the switch still adds the VMs to the Excluded list


Second Issue:
Code: Select all
#* Delete the exclude objects(*Note: this tells VBR to include them again
foreach ($obj in $incObjs) {
   $obj.Delete()
}

The issue here is that apparently in v7 $obj.Delete() does actually remove the VM from the job completely.


So the remaining issue is how do we get the VMs out of the Excluded list and back into the 'Included' state?

Many kudos to ThomasMC for the original script!
Backerupper
Enthusiast
 
Posts: 43
Liked: 10 times
Joined: Fri Dec 28, 2012 2:32 pm

Re: backup single VM (not all VMs) within job?

Veeam Logoby v.Eremin » Mon Sep 30, 2013 8:54 am

It seems that if you want to exclude object temporarily you should use the following script:

Code: Select all
asnp VeeamPSSnapin
$Job = Get-VBRjob -name "Name of the job"
$Object = $Job | Get-VBRJobObject -name "name of the object you’re going to exclude"
$Object | Remove-VBRJobObject 


If you want to include it back, you should utilize this one:

Code: Select all
$Excitem = $Object.GetObject().GetItem()
Add-VBRViJobObject -job $Job -Entities $Excitem
$Object.Delete()


However, it’s always recommended to test the script before implementing.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13543
Liked: 1002 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: backup single VM (not all VMs) within job?

Veeam Logoby Backerupper » Mon Sep 30, 2013 1:17 pm

Excellent, that did the trick - thanks v

Here is the complete v7 conversion of ThomasMc's Single VM Backup script

Code: Select all
#* Load Veeam snapin
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

#* User Input
$jobName = Read-Host "Enter Job Name"
$vmName = Read-Host "Enter VM Name"


#* Find the job that has our VM
$job = Get-VBRJob | ?{$_.Name -eq $jobName}

#* Get all objects in job apart from our target VM
$execObjs = $job.GetObjectsInJob() | ?{$_.Name -ne $vmName}

#* Exclude the objects from the job(*Note: this isn't removing the objects
#* from the job)
Remove-VBRJobObject -Objects $execObjs

#* Start the job only backing up the target VM
Start-VBRJob -Job $job

#* Find the exclude job objects
$incObjs = $job.GetObjectsInJob() | ?{$_.Type -eq "Exclude"}

#* Delete the exclude objects and re-add to job
foreach ($obj in $incObjs) {
   $Excitem = $obj.GetObject().GetItem()
    Add-VBRViJobObject -job $Job -Entities $Excitem
   $obj.Delete() | Out-Null
}



Use with caution on production jobs...test first!
Backerupper
Enthusiast
 
Posts: 43
Liked: 10 times
Joined: Fri Dec 28, 2012 2:32 pm

[MERGED] : Changes with v7

Veeam Logoby northrundicandus » Tue Oct 22, 2013 2:34 pm

Alas the "-Job" parameter seems to have been pulled from the v7 update to Remove-VBRJobObject, which unfortunately breaks this great script that I have used in the past which allowed me to backup a single VM. Any advice on how to fix it so that it will work again with v7?

Code: Select all
#* Load Veeam snapin
asnp VeeamPSSnapin -ErrorAction SilentlyContinue
#* User Input
$jobName = Read-Host "Enter Job Name"
$vmName = Read-Host "Enter VM Name"

#* Find the job that has our VM
$job = Get-VBRJob | ?{$_.Name -eq $jobName}

#* Get all objects in job apart from our target VM
$execObjs = $job.GetObjectsInJob() | ?{$_.Name -ne $vmName}

#* Exclude the objects from the job(*Note: this isn't removing the objects
#* from the job)
Remove-VBRJobObject -Job $job -Objects $execObjs

#* Start the job only backing upi the target VM
Start-VBRJob -Job $job
#Start-VBRJob -Job $job -fullbackup

#* Find the exclude job objects
$incObjs = $job | Get-VBRJobObject | ?{$_.Type -eq "Exclude"}

#* Delete the exclude objects(*Note: this tells VBR to include them again
foreach ($obj in $incObjs) {
   $obj.Delete()
}
northrundicandus
Service Provider
 
Posts: 14
Liked: 3 times
Joined: Thu Aug 11, 2011 9:01 pm
Full Name: Joe Ross

Re: backup single VM (not all VMs) within job?

Veeam Logoby v.Eremin » Tue Oct 22, 2013 3:04 pm

Hi, Joe,

Since the previously used commandlets have been changed slightly in version 7, you should modify the said script a little bit. The way it can be done is shown above; so, kindly, take a look.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13543
Liked: 1002 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 23 guests