Veeam 7 and vCD Catalog Templates

VMware specific discussions

Re: Veeam 7 and vCD Catalog Templates

Veeam Logoby jgreenback » Fri Jan 22, 2016 3:59 pm 2 people like this post

Since we're on the subject of backing up vCloud Catalogs I thought I should update my script post with my changes.
I now handle (sort of) mis-matched VM Folder names in vSphere caused by special characters used in naming a catalog template in vCloud.
Also changed the order in which I add and delete VM folders as this was causing some issues because the veeam cmdlets would only update the NAME of the object in the job but not the location of that object. Not sure why. I'm thinking it has to do with the VM Folder MoREf ID in vSphere being the unique identifier that the cmdlets use in the property Reference.
Finally, I've added logging and a final check for an error log. If it finds an error log was generated it emails the contents to our admins.
Hope this helps someone out there. PM me is you have questions or improvements.
Thanks.

UPDATES:
- Added logging via Start-Transcript / Stop-Transcript in PowerShell
* Output is a daily single file that is appended. New logs each day.
* Change the -Path to where you want the log to go.
- Determine if the Template name can be matched to a vSphere (VMs and Templates) folder. If not, then kick out an error file (dated) with the details.
* When using special characters the folder name in vSphere is shortend thus causing the mis-match and the error.
Not sure how else to handle this. We just email the owner and ask them to rename their template without special characters.
- Email section that checks for and error file and send the admins the contents of the error file.
- Removed Remote PS Session. No longer running remotely due to security hardening here.
- Changed order in which I add/delete VM folders from the backup jobs. Delete first, Add last.
- Now using v8 cmdlets.

*PLEASE READ THROUGH THE SCRIPT BEFORE RUNNING IT* *USE AT YOUR OWN RISK*

Code: Select all
####################################################################
#  Compare current vCD Org Catalog Templates (converted to vSphere #
#  Folders) to current Veeam backup job vSphere folder objects     #
####################################################################
#Start Logging
Start-Transcript -Path "C:\Veeam\Catalog Backup Script Log\vCDTemplateBackup$(get-date -format MM-dd-yy).log" -Force -Append -NoClobber

#Email and Error log variables
$MailServer = "{SMTP_SERVER or IP goes here}"
$ErrorFile = "C:\Veeam\Catalog Backup Script Log\ERROR_$(get-date -format MM-dd-yy).log"

###################################################################
#Load all snapins
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
Add-PsSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Add-PsSnapin -Name VMware.VimAutomation.Cloud -ErrorAction SilentlyContinue

###################################################################
#Connect to vCloud instance
Write-Output "Connecing to vCloud"
Connect-CIServer -Server "{VCLOUDSERVERNAME or IP goes here}"
Write-Output "`r`n"
###################################################################

#Get vCenter Server from Veeam
$vCenterServer = Get-VBRServer | Where {$_.Type -eq “VC”}


###################################################################

#vCloud Director - Get all vApp Tempaltes in all catalogs per $Org
$Orgs = Get-Org

foreach ($Org in $Orgs)
    {
        Write-Output "####################################################`r`n"
        Write-Output "Processing $Org.........`r`n"
        $VeeamBackupJob = Get-VBRJob -Name "Backup Job - $Org - TEMPLATES"
if ($VeeamBackupJob -eq $NULL)
{
Write-Output -WarningAction Continue "No Backup Backup Job exists for $Org.   Please create one if backups are required"
            Write-Output " "
    #CREATE JOB or continue
continue
}
        ### FILTER OUT unwanted catalogs here: ARCHIVE and TEST catalogs ###
$AllOrgTemplates = Get-Org $Org | Get-Catalog | ? { $_.Name -notlike "Test*" -and $_.Name -notlike "*Staging" -and $_.Name -notlike "Archive" } | Get-CIVAppTemplate
if ($AllOrgTemplates -eq $NULL)
{
Write-Output -WarningAction Continue "$Org has no Templates to backup."
            Write-Output " "
    #CREATE JOB or continue
continue
}

        $vCDTemplatesList = @()


        foreach ($Template in $AllOrgTemplates)
        {
            $TemplateFullName = $Template.Name + " (" + $Template.Id.Substring(24) + ")"
            $vCDTemplatesList += $TemplateFullName
        }

    ###################################################################


    ###################################################################

        #Veeam - Get all objects in  - Template Backup job
        $VeeamBackupVMFoldersInfo = $VeeamBackupJob.GetObjectsInJob() | ? {$_.Role -eq "EInclude"}
$VeeamBackupVMFolderNameList = @()
if ($VeeamBackupVMFoldersInfo -eq $NULL)
{
Write-Output -WarningAction Continue "$VeeamBackupJob has no VMFolders defined."   
}
else
{
foreach ($VMFolderPath in $VeeamBackupVMFoldersInfo)
{
                $VMFolderName = $VMFolderPath.Location.Split("\")[-1]
$VeeamBackupVMFolderNameList += $VMFolderName
}
}
      #######################################################################
       
        #Compare the 2 arrays and add New vCD templates that are not present in Veeam BU Job


        $VeeamBackupVMFolderListDifferences = Compare-Object $vCDTemplatesList $VeeamBackupVMFolderNameList
        $VeeamBackupVMFolderToAdd = @()
        $VeeamBackupVMFolderToRemove = @()

        if($VeeamBackupVMFolderListDifferences -eq $NULL)
            {
                Write-Output -WarningAction Continue "Nothing New Here. No need to continue.  Processing next Org."
                Write-Output " "
                continue
            }
       
        foreach ($DifferentVMFolder in $VeeamBackupVMFolderListDifferences)
            {
           
                if($DifferentVMFolder.SideIndicator -eq "=>")
                    {
                        $VeeamBackupVMFolderToRemove += $DifferentVMFolder.InputObject
                        Write-Output "$DifferentVMFolder needs to be DELETED from job"
                    }
                else
                    {
               
                        $VeeamBackupVMFolderToAdd += $DifferentVMFolder.InputObject
                        Write-Output "$DifferentVMFolder needs to be ADDED to job"
                    }
            }

        ###################################################################
       
        #Load vCenterServer/FoldersandVMs view to find Template folder and add it to the Template backup job
        $LoadvCenterFoldersAndVMs = ((New-Object -typename Veeam.Backup.Core.InfrastructureTree.HostsAndClustersLoader).LoadHierarchy($vCenterServer.Info)).FoldersAndVms()

        #Add New vCDTemplates (VMFolders) to Veeam Backup Job
        $AddvCenterVMFoldersToVeeamBackupList = @()

        #Add space between delete/add list
        Write-Output " "

        #Delete VMFolders From Veeam Backup Job.  This must be done first since renaming catalog templates only changes the name and location but not the "Reference:" property
        #thus deleting newly added templates when ran second.
       
        foreach ($VeeamVMFolder in $VeeamBackupVMFolderToRemove)
        {
            Write-Output "## Deleting $VeeamVMFolder from Backup Job - $Org - TEMPLATES ##"
            Get-VBRJobObject -Job $VeeamBackupJob -Name $VeeamVMFolder | Remove-VBRJobObject -Completely -Verbose
            Write-Output "#########################################################################"
            Write-Output " "
            Write-Output " "
        }

        #Add has to be done second since we are adding a different folder name with the same "Reference:" property

        foreach ($vCenterVMFolder in $VeeamBackupVMFolderToAdd)
        {
            if($vCenterVMFolder -eq $NULL)
            {
 Write-Output "$vCenterVMFolder is NULL... continuing"
 Return
            }
            Write-Output "## Adding $vCenterVMFolder to Backup Job - $Org - TEMPLATES ##"
            $AddVMFolder = Find-VBRViEntity -Server $vCenterServer -VMsAndTemplates -Name $vCenterVMFolder

                if($AddVMFolder -eq $NULL)
                {                   
                    Write-Host "**ERROR**`r`n$vCenterVMFolder does not exist in vSphere.`r`nVerify that the template name matches the corresponding vSphere folder.`r`nTo check this go to the catalog of the $Org Organization >> Find, then right-click on $vCenterVMFolder >> choose Open in vSphere Web Client.`r`nIf the 2 values do not mathc contact the Org Admins of $Org and ask them to rename the template.`r`n" -foregroundcolor "Red"
                    Write-Output "$Org Org Template ::$vCenterVMFolder:: was not found.`r`nvSphere folder name does not match the vCloud template name."  | Out-File "C:\Veeam\Catalog Backup Script Log\ERROR_$(get-date -format MM-dd-yy).log"
                    Continue
                }
                else
                {
                    $AddVMFolder | Add-VBRViJobObject -Job $VeeamBackupJob -Verbose
                    Write-Output "#######################################################################"
                    Write-Output " "
                }
        }
    Write-Output "Finsihed with $Org`r`n"
    Write-Output "####################################################`r`n"
    }
#Checkif there is an error file, if so, email contents to Admins
if (Test-Path $ErrorFile)
{   #Send content of error file to DevOps Admins
    Send-MailMessage -From "veeam_service@yourwork.com" -To "vCloudAdmins@yourwork.com" -Subject "Error On Template Backup Script" -body (Get-Content "C:\Veeam\Catalog Backup Script Log\ERROR_$(get-date -format MM-dd-yy).log" | Out-String) -dno onSuccess, onFailure -smtpServer $MailServer
}
else
{
    Write-Output "No errors found... this time`r`n"
}

#End Logging
Stop-Transcript
jgreenback
Enthusiast
 
Posts: 31
Liked: 11 times
Joined: Thu Sep 19, 2013 9:26 pm
Full Name: Jason Greenback

Re: Veeam 7 and vCD Catalog Templates

Veeam Logoby jmarlhioud » Thu Jul 14, 2016 1:33 pm

Is this feature planned for a future release?
jmarlhioud
Service Provider
 
Posts: 4
Liked: 2 times
Joined: Wed Nov 10, 2010 4:40 am
Full Name: Janick Marlhioud

Re: Veeam 7 and vCD Catalog Templates

Veeam Logoby Vitaliy S. » Thu Jul 14, 2016 3:07 pm

Yes, it is still logged for our next updates, just checked its status in the tracking system.
Vitaliy S.
Veeam Software
 
Posts: 19545
Liked: 1099 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Veeam 7 and vCD Catalog Templates

Veeam Logoby jgreenback » Thu Jul 14, 2016 4:22 pm

I've been looking forward to this feature for a while. Thanks for the update Vitaliy.
jgreenback
Enthusiast
 
Posts: 31
Liked: 11 times
Joined: Thu Sep 19, 2013 9:26 pm
Full Name: Jason Greenback

Re: Veeam 7 and vCD Catalog Templates

Veeam Logoby jmarlhioud » Thu Nov 24, 2016 3:52 pm

Vitaliy S. wrote:Yes, it is still logged for our next updates, just checked its status in the tracking system.


Looks like it didn't make it into 9.5, can you give us an update as when this could be available?
jmarlhioud
Service Provider
 
Posts: 4
Liked: 2 times
Joined: Wed Nov 10, 2010 4:40 am
Full Name: Janick Marlhioud

Re: Veeam 7 and vCD Catalog Templates

Veeam Logoby Vitaliy S. » Thu Nov 24, 2016 4:23 pm

As far as I see, it is still pending for the next major releases. Do not have an ETA yet.
Vitaliy S.
Veeam Software
 
Posts: 19545
Liked: 1099 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Veeam 7 and vCD Catalog Templates

Veeam Logoby mattbrown80 » Tue May 23, 2017 5:40 pm

Hi

We have been waiting for this feature for quite a while - is it still on the roadmap?
Using 'vSphere' backups for vCloud Director Catalogs isn't an acceptable workaround long term.

Thanks
mattbrown80
Service Provider
 
Posts: 9
Liked: 3 times
Joined: Wed Nov 26, 2014 9:34 pm
Full Name: Matt Brown

Previous

Return to VMware vSphere



Who is online

Users browsing this forum: No registered users and 14 guests