Veeam: Change Restore points and deleted VMs retention period


If you want to change the amount of restore points and the deleted VMs retention period, you can do this for your backup jobs by hand. But if you need to change a lot of Veeam Backup & Replication Jobs like I needed to do. You can find these settings in the Backup Job properties:

image

If you’re a reader of my blog, you know I like to automate this kind of jobs with Powershell. So I created a function to perform this change for me.

The function:

#requires -pssnapin VeeamPSSnapIn
Function Change-RestorePoints{
<#
.SYNOPSIS
    Change the Backup restore points and deleted VMs retention period
.DESCRIPTION

.NOTES
    Authors: Arne Fokkema
.PARAMETER JobName
    A Backup Job in Veeam Backup & Replication
.PARAMETER RetainDays
    The amount of restore points
.PARAMETER RetainCycles
    The amount of days for Deleted VMs retention period    
.EXAMPLE
    PS> Change-RestorePoints -JobName "Job-01" -RetainDays "21" -RetainCycles "21"
#>
    param(
        [parameter(valuefrompipeline = $true,
            position = 0,
            Mandatory = $true,
            HelpMessage = "Enter a Veeam B&R JobName")]
            $JobName,
        [parameter(valuefrompipeline = $true,
            position = 0,
            Mandatory = $true,
            HelpMessage = "Enter the amount of restore points to keep on disk")]
            $RetainDays,
        [parameter(valuefrompipeline = $true,
            position = 0,
            Mandatory = $true,
            HelpMessage = "Enter a deleted VMs retention period in days")]
            $RetainCycles
    )

    begin{
        $vbrjob = Get-VBRJob  | where {$_.Name -eq $JobName} 
    }
    
    process{
        $options = $vbrjob.GetOptions()
        $options.RetainDays = $RetainDays
        $options.RetainCycles = $RetainCycles
        Write-Host "Changing RetainDays: $($RetainDays) and RetainDays: $($RetainCycles) for job: $($vbrjob.Name)"
        $vbrjob.SetOptions($options)
    }
}

To change a particular job on a Veeam Backup & Replication server you can use the following one-liner:

Change-RestorePoints -JobName "Job-01" -RetainDays "30" -RetainCycles "30"

To change all the jobs on a particular Veeam Backup & Replication Server you can use the following foreach loop:

foreach($job in (Get-VBRJob | Sort Name)){
    Change-RestorePoints -JobName $job.Name -RetainDays "14" -RetainCycles "14"
}

The output will look like this:

image

Veeam: How to change the Job notification settings with Powershell


Today just a quick post about how Powershell can help you change the VM attribute option in Veeam Backup & Replication. Imaging that you have 20 backup jobs and you want or need to change the VM attribute settings. You can do this for every job with 10 mouse clicks or you can do it in five seconds by running the script from this post.

This is the setting I am talking about from the GUI:

image

When you change the “Notes” value to some custom field in you environment, the script will apply this setting for you.

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

$vbrserver = Get-VBRServer | Where {$_.Type -eq "VC"}
Foreach($vbrjob in (Get-VBRJob)){    
    $options = $vbrjob.GetOptions()
    $options.VmAttributeName = "Notes"
    $options.SetResultsToVmNotes = $true
    $vbrjob.SetOptions($options)
}

The first three lines of code checked if the VeeamPSSnapIn is loaded, if this is not the case it will be loaded via the Add-PSSnapin.

  • The backup options will be loaded via the .GetOptions() method.
  • VmAttibuteName is the value which you normally enter in the attribute field.
  • SetResultsToVmNotes is the checkbox to enable this setting.
  • via .SetOptions() method you can apply the new settings.

Veeam: Change the Veeam Storage Optimization with Powershell


In Veeam Backup and Replication you can choose three different types of Storage optimization.

image

See the blog post on the Veeam website for more info: http://www.veeam.com/blog

From @gostev I received the following tip:

Note that storage optimization will not take effect until next full backup. Setting is used for newly created backup storage only.

There is no standard cmdlet to change this settings, so we have to find the property of the Storage optimization settings. With some trial and error I found the stgBlockSize property. This property can be found inside the vbrjob options.

You can view this properties via:

$vbrjob = Get-VBRJob | where {$_.Name -eq "<vbrjobname>"}
$options = $vbrjob.GetOptions()

and via the StgBlockSize property you are able to find the actual value of this setting.

$options.StgBlockSize

I have tried the three options from the screenshot and found the following three values:

    $localtarget = "KbBlockSize1024"
    $lantarget = "KbBlockSize512"
    $wantarget = "KbBlockSize256"

Now we have found the properties we need to change the settings via PowerShell. We can build some scripts.

If you want to change the Storage option to LAN target on all your backup jobs. You can run the following script on your Veeam Backup and Replication server. Don’t forget to change the StgBlockSize value with the variable you want to use.

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

$vbrjobs = Get-VBRJob 

foreach($vbrjob in $vbrjobs){

    #Storage optimization 
    $localtarget = "KbBlockSize1024"
    $lantarget = "KbBlockSize512"
    $wantarget = "KbBlockSize256"

    #Change Job Options
    $options = $vbrjob.GetOptions()
    $options.StgBlockSize = $lantarget

    $vbrjob.SetOptions($options)
}

Or if you want to change just a couple of your jobs, you can use the following script:

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn"
}

$vbrjobs = "<Job1>","<Job2>"

foreach($vbrjobname in $vbrjobs){

    #Storage optimization 
    $localtarget = "KbBlockSize1024"
    $lantarget = "KbBlockSize512"
    $wantarget = "KbBlockSize256"

    #Change Job Options
    $vbrjob = Get-VBRJob  | where {$_.Name -eq $vbrjobname} 
    $options = $vbrjob.GetOptions()
    $options.StgBlockSize = $lantarget

    $vbrjob.SetOptions($options)
}

So with the Powershell toolkit for Veeam you can perform every change you want and can do via the GUI. You can expect some more posts about automating Veeam Backup and Replication with Powershell.

Veeam Powershell Toolkit: Changing the Processing Mode


Before I start with the actual post I want to start with a little tip. Before you can run Veeam Powershell Toolkit scripts, you need to add the VeeamPSSnapin. You can do this via the following code:

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn" 
}

So now you’re able to load the snapin, you can run your Veeam Powershell Toolkit scripts. In this post I want to show how to change the Processing Mode. You probably know the three modes:

image

You can find the Processing Mode options via the following Powershell script:

$vbrjobname = "Production"
$vbrjob = Get-VBRJob | Where {$_.Name -eq $vbrjobname}
$vbrjob.Info.Options.VDDKMode

So now you know which modes there are, but how do you change this option with Powershell? Well you can do this with the next script:

if((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null){
    Add-PSSnapin "VeeamPSSnapIn" 
}

$vbrjobname = "Production"
$vbrjob = Get-VBRJob | Where {$_.Name -eq $vbrjobname}
$DirectSAN = "san;nbd"
$VirtualAppliance = "hotadd;nbd"
$Network = "nbd"

$mode = $VirtualAppliance

if($vbrjob.info.options.VDDKMode -ne $mode){
    $vddk = $vbrjob.GetOptions()
    $vddk.VDDKMode = $mode
    $vbrjob.SetOptions($vddk)
    Write-Host "VDDK mode changed to $mode" -ForegroundColor Green
}
else{
    Write-Host "Nothing to change" -ForegroundColor Yellow
}

Just save the script and change the $mode parameter to the option you want to use. The script will give you the following output:

image

Reconfigure DNS settings and add vSphere hosts to Windows DNS


I needed to change the DNS setup in our vSphere environment. Instead of doing this by hand on every host I decided to create a script. First I needed a script to add the A and PTR records to the Windows DNS servers. I remembered a post by the scripting guys so I took their function and added it to my script. The final step is to change de vSphere host DNS configuration. This one is easy with PowerCLI and a simle for loop.

Warning! If you are using vSphere 4.1 and the vSphere hosts are joined to a Windows domain. You are not able to change the DNS settings!

From the Hey Scripting Guy post I quote the following about the new-dnsrecord function:

I’ve written various scripts in the past to work with individual record types, and I’ve found that each class has slightly different syntax and requirements. This makes life awkward when you want to start automating this process, because you have to have a different script or function for each record type. I decided I wanted a universal script for creating records so that I could create multiple records at the same time from minimal information. The following script shows the function that I came up with to create A, PTR, MX, and CNAME records—these being the most common ones I have to deal with. We will be using the MicrosoftDNS_ResourceRecord class with varying inputs.

I have combined the new-dnsrecord function with some PowerCLI code to accomplish my goal of migrating the DNS settings of all the vSphere hosts and to add all the hosts to the DNS servers. I did this task by running the following script:

Continue reading

Working with the Veeam Powershell toolkit


After the short introduction of the Veeam Powershell toolkit in my earlier post, It was about time to play with the Toolkit. In this post I will show you how to create a Backup Job and how to add VM’s to the backup job.

Lets start to add a new Veeam and Replication backup job called “Production” and add the following VM’s: DC01, VC01 and MC01:

$vbrserver = Get-VBRServer | Where {$_.Type -eq "Local"}
$vbrjobname = "Production"
$vbrfolder = "C:\veeam\production\"
$vbrfile = "production.vbk"
$vbrobjects = "DC01","VC01","MC01"

Add-VBRBackupJob -Name $vbrjobname -Type VDDK -Server $vbrserver `
-Folder $vbrfolder -FileName $vbrfile -Objects $vbrobjects

The backup job is created and the following output will be generated on the console:

image

You can verify the Job settings and the selected VM’s inside the GUI:

image

If you want to add an extra VM to the backup job. You can run the following code to add a VM called NAGIOS:

$vbrjobname = "Production"
$vbrjob = Get-VBRJob | Where {$_.Name -eq $vbrjobname}
$vbrserver = Get-VBRServer | Where {$_.Type -eq "VC"}
$vbrobjects = "NAGIOS"

Add-VBRJobObject -Job $vbrjob -Server $vbrserver -Object $vbrobjects

Annotation: the $vbrserver parameter is different than the first script in this post. When you want to add an Object to an existing job, you need to use the vCenter server as the backup source instead of the Veeam Backup server because you need to add an object from vCenter server to the backup job. See help for more info:

get-help Add-VBRJobObject -Detailed

The output from the command:

NAME

    Add-VBRJobObject

SYNOPSIS

    Add VMs or VM containers to the existing job.

SYNTAX

    Add-VBRJobObject [-Job] <CBackupJob> [-Server] <CHost> [-Objects] <String[]

    > [-WarningAction <ActionPreference>] [-WarningVariable <String>] [<CommonP

    arameters>]

    Add-VBRJobObject [-Job] <CBackupJob> [-Server] <CHost> [-Entities] <CEntity

    []> [-WarningAction <ActionPreference>] [-WarningVariable <String>] [<Commo

    nParameters>]

DESCRIPTION

    Add VMs or VM containers to the existing backup, replication or copy job.

PARAMETERS

    -Job <CBackupJob>

        Provide an object of the existing backup, replication or copy job.

    -Server <CHost>

        Provide an object of the ESX/ESXi server on which VMs or VM containers

        reside.

    -Objects <String[]>

        Provide objects of VMs or containers of VMs that you want to back up, r

        eplicate or copy.

When the command completed successfully you will see the following output:

image

To be continued…

Veeam Backup PowerShell Toolkit


We start with some information from the user guide veeam_backup_5_0_user_guide_pg.pdf :

Veeam Backup & Replication 5.0 comes with PowerShell extension — a snap-in to Microsoft Windows PowerShell 2.0. Windows PowerShell is a powerful command-line tool that allows administrators to automate some Veeam Backup & Replication activities. Veeam extends functionality of Windows PowerShell 2.0, and now administrators may use PowerShell to automate Veeam backup, replication and copy job creation and editing, VMs restores, replica failover and other operations.

Before installing Veeam PowerShell snap-in, make sure that Microsoft Windows PowerShell 2.0 is installed on the Veeam Backup & Replication console. To download Microsoft Windows PowerShell, use the following link: http://support.microsoft.com/kb/968929.

PowerShell uses cmdlets — simple single-function commands that can be run in the command-line shell. Cmdlets are specialized .NET classes that implement specific actions. Veeam PowerShell provides a set of its own cmdlets which correspond to actions you can perform via Veeam Backup & Replication UI. Please keep in mind that actions performed with PowerShell have the same force as actions performed via Veeam Backup & Replication 5.0 — for example, if you delete some job with PowerShell scripts, the job will be removed from the VeeamBackup database, and you will not be able undo changes.

To start the Veeam Backup PowerShell Toolkit, open Veeam Backup and Replication to Tools –> PowerShell:image

The Veeam Backup PowerShell Toolkit starts:

image

There are 75 cmdlets. You can verify this via:

(Get-VBRCommand).Count

image

If you need more information about a cmdlet you can use the get-help cmdlet:

Get-Help Add-VBRBackupJob
Get-Help Add-VBRBackupJob -Full

image

More information about the Veeam Backup PowerShell Toolkit can be found on page 164 of the veeam_backup_5_0_user_guide_pg.pdf user guide,

You can expect some more posts about the Veeam Backup PowerShell Toolkit in the coming weeks.