PowerShell script exchange
Post Reply
oli4
Enthusiast
Posts: 63
Liked: 3 times
Joined: Aug 14, 2012 11:34 am
Contact:

Create Backup Job from VM folders

Post by oli4 »

Hello

is there an easy way to create with powershell a backup job for each VM folder from VMware vCenter?
With Add-VBRViBackupJob I can only specify an "Entity", means a VM.

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

Re: Create Backup Job from VM folders

Post by veremin » 1 person likes this post

Entity parameter accepts folder item, as well. I've just created a job with a folder as a source, using the following script:

Code: Select all

$Server = Get-VBRServer -Name "Name of your vCenter"
$Folder = Find-VBRViEntity -Server $Server -name "Name of your folder"| where {$_.type -eq "Folder"}
$Repository = Get-VBRBackupRepository -Name "Name of your repository"
Add-VBRViBackupJob -Name "Test Job" -BackupRepository $Repository -Entity $Folder
Thanks.
oli4
Enthusiast
Posts: 63
Liked: 3 times
Joined: Aug 14, 2012 11:34 am
Contact:

Re: Create Backup Job from VM folders

Post by oli4 »

Hi Vladimir, my script looks almost the same, but when I try your (or my) script I get the message:

Add-VBRViBackupJob : Cannot bind parameter 'Entity'. Cannot convert the "Testfolder" value of type "System.String" to type "Veeam.Backup.Core.Infrastructure.IViItem".
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Create Backup Job from VM folders

Post by veremin »

Can you provide me with the script you've created? It looks like the way you get a folder entity might be slightly wrong. Thanks.
oli4
Enthusiast
Posts: 63
Liked: 3 times
Joined: Aug 14, 2012 11:34 am
Contact:

Re: Create Backup Job from VM folders

Post by oli4 »

I tried it with that easy one:

$Folder = "Testfolder"
Add-VBRViBackupJob -Name "Testjob" -Entity $Folder
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Create Backup Job from VM folders

Post by veremin »

So, that is the problem. In the example provided by you $Folder variable contains string value "Testfolder", not the ViItem that is expected by -Entity parameter.

Try the script I've mentioned, replacing "Name of your folder" with the name of folder you want to backup.

Thanks.
oli4
Enthusiast
Posts: 63
Liked: 3 times
Joined: Aug 14, 2012 11:34 am
Contact:

Re: Create Backup Job from VM folders

Post by oli4 »

I dont see the difference, my original script is:

Code: Select all

$vCenter = "<vCenter Name>"
$VeeamFolders = Find-VBRViFolder -Server $vCenter -Name "*-BKP*"

ForEach($V in $VeeamFolders)
    {
    Add-VBRViBackupJob -Name $V.Name -Entity $V.Name
    }
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Create Backup Job from VM folders

Post by veremin »

$V.Name is a string containing name of a folder, not a folder object itself. That's the difference.

In order for your script to work properly, it should be changed:

Code: Select all

    $vCenter = "<vCenter Name>"
    $VeeamFolders = Find-VBRViFolder -Server $vCenter -Name "*-BKP*"

    ForEach($V in $VeeamFolders)
        {
        Add-VBRViBackupJob -Name $V.Name -Entity $V
        }
Thanks.
oli4
Enthusiast
Posts: 63
Liked: 3 times
Joined: Aug 14, 2012 11:34 am
Contact:

Re: Create Backup Job from VM folders

Post by oli4 » 1 person likes this post

OK, thanks, now it works.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Create Backup Job from VM folders

Post by veremin »

You're welcome. Feel free to reach us, if other help is needed. Thanks.
kdegnan
Lurker
Posts: 1
Liked: never
Joined: Jul 10, 2024 5:24 pm
Full Name: Kevin Degnan
Contact:

Re: Create Backup Job from VM folders

Post by kdegnan »

Hi folks,

Resurrecting a very old thread, but I'm trying to do something similar. I'd like to automate the creation of VMware backup jobs on a per-folder basis. We have VBR 12 and I'm trying to use the Add-VBRViBackupJob cmdlet, but it has trouble converting from CViFolderItem to IViItem:

PS C:\Windows\System32> $vmEntity = Find-VBRViEntity -Server "server_name" -Name "folder_name" -VMsAndTemplates

PS C:\Windows\System32> $job = Add-VBRViBackupJob -Name "VM Backups" -Entity $vmEntity
Add-VBRViBackupJob: Cannot bind parameter 'Entity'. Cannot convert the "Veeam.Backup.Core.Infrastructure.CViFolderItem" value of type "Deserialized.Veeam.Backup.Core.Infrastructure.CViFolderItem" to type "Veeam.Backup.Core.Infrastructure.IViItem".

Has Veeam dropped support for using a folder as an entity? Or is something else going on here? Thanks in advance!
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Create Backup Job from VM folders

Post by david.domask »

Hi Kevin, welcome to the forums!

Can you check your output on $vmEntity and show the output (redacting any sensitive information like hostnames or IPs)?

I just tested quick on 12.1.2.172 and created a job with a folder without issue.

Code: Select all

$server = Get-VBRserver -name 'some vCenter'
$folder = Find-VBRViEntity -Server $server -VMsAndTemplates -Name "some_folder"
$repo = Get-VBRBackupRepository -name 'some_repo'
Add-VBRViBackupJob -Name "test2" -BackupRepository $repo -Entity $folder

Job Name                  Type            State      Last Result  Description
--------                  ----            -----      -----------  -----------
test2                     VMware Backup   Stopped    None         Created by Powershell at 12.07.2024 16:23:46.
It might be the -Server flag, but I'm not confident this is the issue, but try it out that way and maybe show the output of your variables if it's not going.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests