PowerShell script exchange
Post Reply
aldvm
Novice
Posts: 8
Liked: 1 time
Joined: Jul 11, 2013 2:04 pm
Full Name: Agnius
Contact:

Backup single VM within a job. Backup folder as a source.

Post by aldvm »

I'm trying to modify a script wrote to backup single VM. Problem that I have backup job with folder as target of backup. My last modification:

Code: Select all

    #* Load Veeam snapin
    #asnp VeeamPSSnapin -ErrorAction SilentlyContinue
    #* User Input
    $jobName = "Backup Job"
    $vmName = "VMtoBackup"

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

    #* Get all objects in job apart from our target VM
    $execObjs = foreach($v in $job.GetOibs()) {$v.VmName -ne $vmName}
    #$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 $job2 -Objects $execObjs

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

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

    #* Delete the exclude objects(*Note: this tells VBR to include them again
    foreach ($obj in $incObjs) {
       $obj.Delete()
    }
I need to get all VM from backup folder and exclude VM. I'm stuck here:

Code: Select all

Remove-VBRJobObject -Job $job2 -Objects $execObjs
I'm receiving this error:

Code: Select all

Remove-VBRJobObject : Cannot bind parameter 'Objects'. Cannot convert value "Tr
ue" to type "Veeam.Backup.Core.CObjectInJob". Error: "Invalid cast from 'System
.Boolean' to 'Veeam.Backup.Core.CObjectInJob'."
At C:\scripts\DLX-VMBackup.ps1:17 char:44
+     Remove-VBRJobObject -Job $job2 -Objects <<<<  $execObjs
    + CategoryInfo          : InvalidArgument: (:) [Remove-VBRJobObject], Para
   meterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.Powe
   rShell.Command.RemoveVBRJobObject
Maybe someone have such working script or can help me in this case?
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Backup single VM within job witch backup foldre

Post by ThomasMc »

That script look familiar :D but as you already know won't be able to do what your trying at it relies on the VMs being add individually, I detailed a way that Vladimir has scripted so you should check out this post
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Backup single VM within job witch backup foldre

Post by veremin »

In case of folder the script mentioned by Thomas should be modified a little bit:

Code: Select all

Asnp VMware.VimAutomation.Core
Asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your Job"
$Server = Get-VBRServer -name "Name of vCenter"
$VMname = read-host "Input VM name"
$Repo = Get-VBRBackupRepository -name "Name of Repository"
$Folder = $Job | Get-VBRJobObject
Connect-VIServer -Server $Server.Name -User "User" -Password "Password"
$Object = (Get-Folder -name $Folder.name) | Get-VM | ? {$_.name -ne $VMname}
$ObjectsToExclude = Find-VBRViEntity -Server $Server -name $Object.name
Add-VBRViBackupJob -Name "Temprorary Job" -BackupRepository $Repo -Entity $ObjectsToExclude
$Job1 = Get-VBRJob -name "Temprorary Job"
Foreach ($VmToExclude in ($Job1 | Get-VBRJobObject))
{
$VmToExclude.name
[Veeam.Backup.Core.CObjectInJob]::CreateViOij($Job.Id.guid, $VmToExclude.Object.Id.Guid, $VmToExclude.info.folderId, $VmToExclude.info.VssOptions, $VmToExclude.info.ApproxSize, $VmToExclude.info.Location, $VmToExclude.info.type,$VmToExclude.info.DiskFilter, $False)
$Objects = Get-VBRJob -name $Job.name | Get-VBRJobObject | ?{$_.name -eq $VmToExclude.name}
$Objects | Remove-VBRJobObject
$Objects.delete()
}
Remove-VBRJob -Job $Job1 -Confirm:$False
Honestly, I’ve tested it only roughly, so don’t hesitate to let me know if anything doesn’t work as expected.

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests