PowerShell script exchange
mark.harre
Influencer
Posts: 12
Liked: never
Joined: Dec 21, 2010 1:29 pm
Full Name: Mark Harre
Contact:

backup single VM (not all VMs) within job?

Post by mark.harre » 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

Sethbartlett
Expert
Posts: 282
Liked: 25 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

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

Post by Sethbartlett » 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.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

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

Post by ThomasMc » 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.

tsightler
VP, Product Management
Posts: 5421
Liked: 2243 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

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

Post by tsightler » 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.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

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

Post by ThomasMc » Jan 15, 2012 4:04 am

Seems to work ok for me Tom (6.0.0.158 x64)

*Note 4 Objects in job
Image

jkcouch
Enthusiast
Posts: 30
Liked: never
Joined: Jun 26, 2011 7:02 pm
Full Name: Jeff Couch
Contact:

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

Post by jkcouch » 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.

tsightler
VP, Product Management
Posts: 5421
Liked: 2243 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

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

Post by tsightler » 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.

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

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

Post by mark.harre » Jan 16, 2012 7:58 am

Thx Thomas,
I will try the script.
rgds,
Mark

Daveyd
Expert
Posts: 283
Liked: 11 times
Joined: May 20, 2010 4:17 pm
Full Name: Dave DeLollis
Contact:

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

Post by Daveyd » 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.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

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

Post by ThomasMc » 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.

Backerupper
Enthusiast
Posts: 47
Liked: 23 times
Joined: Dec 28, 2012 2:32 pm
Contact:

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

Post by Backerupper » 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!

veremin
Product Manager
Posts: 16901
Liked: 1438 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » 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.

Backerupper
Enthusiast
Posts: 47
Liked: 23 times
Joined: Dec 28, 2012 2:32 pm
Contact:

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

Post by Backerupper » 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!

northrundicandus
Service Provider
Posts: 14
Liked: 3 times
Joined: Aug 11, 2011 9:01 pm
Full Name: Joe Ross
Contact:

[MERGED] : Changes with v7

Post by northrundicandus » 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()
}

veremin
Product Manager
Posts: 16901
Liked: 1438 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » 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.

sirinech
Influencer
Posts: 23
Liked: 1 time
Joined: Mar 21, 2014 3:06 pm
Full Name: sirine chadly
Contact:

[MERGED] start a job

Post by sirinech » Apr 10, 2014 1:17 pm

Hello,

Is it possible to start a job for a specific VM not all VMs inside it?

foggy
Veeam Software
Posts: 18278
Liked: 1564 times
Joined: Jul 11, 2011 10:22 am
Full Name: Alexander Fogelson
Contact:

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

Post by foggy » Apr 10, 2014 1:22 pm

Sirine, this can be performed with the help of PowerShell, please look above for details.

rverhe
Influencer
Posts: 11
Liked: never
Joined: Dec 01, 2014 12:50 pm
Full Name: Rob Verhees
Contact:

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

Post by rverhe » Dec 10, 2014 9:48 am

This script don't work with V8. It does not readd my VMs in the job.
Is there an update?

Failure:

Method invocation failed because [Veeam.Backup.Core.CHierarchyObj] does not contain a method named 'GetItem'.
At I:\Scripts\VM-in-job.ps1:27 char:4
+ $Excitem = $obj.GetObject().GetItem()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Add-VBRViJobObject : Cannot validate argument on parameter 'Entities'. The argument is null. Provide a valid value for
the argument, and then try running the command again.
At I:\Scripts\VM-in-job.ps1:28 char:44
+ Add-VBRViJobObject -job $Job -Entities $Excitem
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-VBRViJobObject], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.AddVBRViJobObject

veremin
Product Manager
Posts: 16901
Liked: 1438 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » Dec 10, 2014 5:37 pm

If you want to backup just one VM, why not to use Quick Backup that has been developed for such use cases specifically? Thanks.

Backerupper
Enthusiast
Posts: 47
Liked: 23 times
Joined: Dec 28, 2012 2:32 pm
Contact:

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

Post by Backerupper » Feb 06, 2015 4:43 pm

The script is still handy for backing up new VMs - Quick Backup will not work unless an initial backup has been created. Many folks like to add a VM to a job and back it up as part of their provisioning process.

The script has been updated for v8 here:
http://blog.smasterson.com/2015/02/06/v ... owershell/

Code: Select all

# Load Veeam snapin
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
 
Clear-Host
Write-Host "Veeam Single VM Backup Script`n"
Write-Host "Notes:"
Write-Host "VM must be explicitly defined in the job"
Write-Host "VM can not be inherited by a folder, datastore or other object"
Write-Host "else it will get excluded as well and job will be empty."
Write-Host "Always confirm job completion via Veeam BR Console!"
 
# Check Veeam Version (Must be v8)
If ((Get-PSSnapin VeeamPSSnapin).Version.Major -ne 8) {
	Write-Host "You must be running VBR v8 to run this script...Exiting"
	Exit
}
 
# 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
Remove-VBRJobObject -Objects $execObjs
 
# Start the job only backing up the target VM
$runJob = 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 = Find-VBRViEntity -Name $obj.Name
    Add-VBRViJobObject -job $Job -Entities $Excitem | Out-Null
    $obj.Delete()
}
 
Write-Host "`nBackup Complete"

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

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

Post by ThomasMc » Feb 17, 2015 9:30 pm

Many thanks for keeping these alive Shawn :)

KennethLarsen
Novice
Posts: 8
Liked: 1 time
Joined: Mar 03, 2014 7:21 am
Full Name: Kenneth Larsen
Contact:

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

Post by KennethLarsen » Jul 02, 2015 9:06 am

That script dont work here.. Posted it on the authors blog, but no response ! yeah i know I should fix it myself.. I havent.. !

Code: Select all

Add-VBRViJobObject : Cannot validate argument on parameter 'Entities'. The argument is null. Supply a non-null
argument and try the command again.
At C:\Install\Backup_1_VM_in_a_job.ps1:41 char:44
+     Add-VBRViJobObject -job $Job -Entities $Excitem | Out-Null
+                                            ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-VBRViJobObject], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.AddVBRViJobObject

Add-VBRViJobObject : Cannot validate argument on parameter 'Entities'. The argument is null. Supply a non-null
argument and try the command again.
At C:\Install\Backup_1_VM_in_a_job.ps1:41 char:44
+     Add-VBRViJobObject -job $Job -Entities $Excitem | Out-Null
+                                            ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-VBRViJobObject], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.AddVBRViJobObject

veremin
Product Manager
Posts: 16901
Liked: 1438 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » Jul 02, 2015 10:38 am

So, the provided portion suggests that variable assignment went wrong and currently $ExcItem contains nothing.

Try to check code line by line and see which one doesn't return anything:

Code: Select all

$jobName = Read-Host "Enter Job Name"
$JobName

$job = Get-VBRJob | ?{$_.Name -eq $jobName}
$job

$incObjs = $job.GetObjectsInJob() | ?{$_.Type -eq "Exclude"}
$incObjs

foreach ($obj in $incObjs) {
   $Excitem = $obj.GetObject().GetItem()
   $Excitem
}
Thanks.

jelloir
Novice
Posts: 5
Liked: 1 time
Joined: May 07, 2015 11:45 pm
Contact:

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

Post by jelloir » Aug 13, 2015 2:12 am

v.Eremin wrote:If you want to backup just one VM, why not to use Quick Backup that has been developed for such use cases specifically? Thanks.
Quick backup needs more flexibility and should offer an option of which backup source to choose as the quick backup. There may be situations where it's necessary to choose a particular backup job source rather than Veeam assuming you want to use the most recent backup.

For example... Just now we needed to choose an older backup of a VM as the source of the quick backup due to some changes being made with associating a copy job with that job and moving VM's to new backups. But because a newer backup of that VM existed from another job we had to delete the the newer backup to make Veeam run the quick backup from the source we required.

A simple "Use most recent backup" or "Choose source of backup" would be useful for quick backups.

veremin
Product Manager
Posts: 16901
Liked: 1438 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » Aug 13, 2015 10:10 am

Got it. However, I believe that in this particular case running a custom script would have been easier than deleting existing newer backups. Thanks.

GabesVirtualWorld
Expert
Posts: 184
Liked: 15 times
Joined: Jun 15, 2009 10:49 am
Full Name: Gabrie van Zanten
Contact:

[MERGED] Backup single VM from larger job

Post by GabesVirtualWorld » Oct 24, 2016 10:15 am

Hi

Sometimes we have the need to make an extra backup of a single VM which is part of a larger job. For example before a big change, when snapshots are not desired.

Is there an easy way to do this? I don't want to create a new job because that would cause a complete full backup.

Regards
Gabrie

veremin
Product Manager
Posts: 16901
Liked: 1438 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » Oct 24, 2016 10:31 am

I think Quick Backup is the functionality you're looking for. Thanks.

t481
Enthusiast
Posts: 56
Liked: never
Joined: Apr 28, 2015 7:52 am
Contact:

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

Post by t481 » Feb 13, 2017 7:58 am

Hello Veeam,
Clearly there's a lot of demand for this feature. Any chance this could be incorporated into a future release?

veremin
Product Manager
Posts: 16901
Liked: 1438 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » Feb 13, 2017 6:13 pm

May I ask why Quick Backup functionality does not work for you? Thanks.

rybaker
Lurker
Posts: 1
Liked: never
Joined: Mar 01, 2017 8:49 pm
Full Name: Ryan Baker
Contact:

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

Post by rybaker » Mar 01, 2017 8:54 pm

I agree this should be an added feature and here's why.

We just started backing up our sql trans logs with veeam. Made the changes to my existing job to a couple of sql servers and guess what? Error while trying to backup the trans logs! Veeam wants me to take a full backup of the VM again after making this change to backup the trans logs. I don't want to backup all of the VMs only the SQL servers that I made this change to. However I cant without running the whole job. :cry:

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests