Automate yourself out of a (backup) jobJoe HoughesSr. Infrastructure Engineer,FullStackGeek, Lazy Admin
What can automation do for you?
Veeam can be fully automated to deploy, manage and report on all of your backup / backup copy / file copy / VM copy and replication jobs FOR FREE!! **
“Working with Veeam PowerShell cmdlets and scripts in many respects depends on your imagination, skills and expertise in Windows PowerShell.”
**(Caveats on some new features)
Is backup automation for you?
• Should your backups be manual or automated? How about the testing of your backups — manual or automated?
• How are your backups being created currently? Is this sufficient for your needs?
• How are your backups being tested currently? Is this sufficient for your needs?
Ask yourself – How do I maintain control?
• How do you make changes to jobs?
• How do you handle advanced job options?
• How do you make changes to your backup infrastructure?
Testing changes
• Now, how are you testing these changes to your environment?
• How are you tracking changes to your configurations?
• Do you need better control or standard "policy-style" settings to be applied?
Have this need? Automation can provide standardization and ensure more robust Availability for your organization.
Defining success of backups & Availability
Before starting with code, define a goal. Think about the taskand desired result.
Are you turning to automation for the benefit of the business?
In this context, automation isn't solely about speed or performance.
Focus on standardization, validation and efficiencies gained withthe enhanced productivity.
Veeam & PowerShell basics
PowerShell basics for starting out
• Never be afraid to ask for help. Get-Help is not just your friend, it's intended to make your life easier.
• PowerShell is built for pipeline, embrace it and leverage it.
• Stack your cmdlets and results like Legos. Buy yourself a set if you're outdated on this concept.
• Forget what your teachers told you: Cheat and / or look up the answer whenever possible.
Veeam-specific PowerShell tips
• Search Veeam cmdlets specific to your version:Get-VBRCommand [-V95] [-V90] [-V80]
• What is your type? What are your members?
• Now that you know your type, where can it be used?Get-Command -ParameterType *TypeName*
• A little bit of validation… Understand the allowed values of parameters: Look up the Veeam PowerShell enumerations
Starting at the beginning
• Step 1: Start-VBRConfigurationBackupJob
• Step 2: What are you trying to accomplish? Think MVP.
• Step 3: Add-PSSnapIn VeeamPSSnapIn
Let’s see some code
Basic infrastructure deployment
You can fully deploy Veeam infrastructure by adding Windows and Linux servers, proxies, repositories (including SOBR) and credentials, plus virtual hosts / clusters / entities — all from a fresh Veeam install without opening the console.
Steps for a VERY basic Veeam deployment post-installation:(Assumes Veeam Backup & Replication admin role, shared proxy / repository Windows server, 'D:\Backups' as repository folder)
Basic deployment – User input
$VeeamVBRServerName = Read-Host -Prompt "Veeam B&R Server Name"
$VeeamProxyServerName = Read-Host -Prompt "Veeam Proxy Name"
$VeeamVirtualServerName = Read-Host -Prompt "vCenter Server or ESXi Host Name"
$VeeamProxyCreds = Get-Credential -Message "Veeam Proxy Credentials"
$VeeamvCenterCreds = Get-Credential -Message "Veeam vCenter Credentials"
Basic deployment – Connect / creds
#Veeam VBR Setup:Add-PSSnapIn -Name VeeamPSSnapIn
Connect-VBRServer -Server $VeeamVBRServerName
$VBRProxyCred = Add-VBRCredentials -Credential $VeeamProxyCreds-Description "Veeam Proxy Credentials"
$VBRVirtualCred = Add-VBRCredentials -Credential $VeeamvCenterCreds-Description "Veeam vCenter Credentials"
Basic deployment – Servers
#Veeam Managed Server Setup:
$VeeamVirtualServer = Add-VBRvCenter -Name $VeeamVirtualServerName -Description "vCenter Server" -Credentials $VBRVirtualCred
$VeeamWinServer = Add-VBRWinServer -Name $VeeamProxyServerName -Description "Veeam Proxy #1" -Credentials $VBRProxyCred
Basic deployment – Big finish
#Veeam Proxy & Repository Setup$VeeamProxy = Add-VBRViProxy -Server $VeeamWinServer -Description "Veeam Proxy #1”
$VeeamRepository = Add-VBRBackupRepository -Name $($VeeamProxyServerName + "_Repository") -Description "Veeam Repository #1" -Server $VeeamWinServer -Folder "D:\Backups" -Type WinLocal
True, this is a VERY basic Veeam infrastructure relying on some default parameters.
OK, so now what?
Now that Veeam is configured, you need a job to perform actual backup functions.Creating jobs targeting objects are just as easy:• Hosts / clusters / VMs / templates / datastores / res. pools / tags
(VMware)• Hosts / VMs / volumes (Hyper-V)
Pro tip: Leverage vSphere Tagging to drive selection for items to be automatically picked up into existing jobs and schedules — make your backups / backup copies run as a subscription model!
Automated job creation
Create a simple Veeam job to target a VMware Tag:
#Veeam User Input for VMware Tag$VMwareTag = Read-Host -Prompt "VMware tag to be targeted for backup job"
#Veeam Backup Job Setup$VeeamTag = Find-VBRViEntity -Name $VMwareTag -Tags -Server $VeeamVirtualServer
$VeeamBackupJob = Add-VBRViBackupJob -Name 'Demo Backup Job' -Description 'Demo backup job created via script' -BackupRepository $VeeamRepository -Entity $VeeamTag
I don't want to run that manually
Simple job scheduling examples:
Set-VBRJobSchedule -Job $VeeamBackupJob -Daily -At "20:00" -DailyKindEveryday
Set-VBRJobSchedule -Job $VeeamBackupJob -Monthly -At "21:00" -NumberInMonth Last -Days Friday
Set-VBRJobSchedule -Job $VeeamBackupJob -Periodically -FullPeriod 4 -PeriodicallyKind Hours
Veeam Tech Support can help!
Matt Fonnerfrom Veeam Support
What to expect
How does Veeam support automation and scripting
with PowerShell?
What are good resources to test and learn about
Veeam PowerShell?
What are some areas to check if a script is not
working?
What options do I have?
You’ve always got options
$VeeamBackupJobOptions = New-VBRJobOptions –ForBackupJob
$VeeamBackupJobOptions | Get-Member -MemberType Property | Sort-Object Name
$VeeamBackupJobOptions includes the following properties:
Options: This top-level property contains a root node, which will display all job options.At a quick view, this property gives: manual / scheduled runs, backup chain mode, compression / deduplication, email notifications, retention, SAN snapshots / failback, VM deletion, VMware tools quiescence / CBT, etc.).
Backup job options
The other job options and a few samples of the most important properties contained within are:
BackupStorageOptions: Number of restore points, retention period for deleted VMs, compression / deduplication, enabling and scheduling of integrity checks, backup encryptionBackupTargetOptions: Backup chain mode, active full enabling and scheduling, synthetic full enabling and schedulingFailoverPlanOptions: Scripts for pre- and post-failover plan enabled / disabled, script pathsJobOptions: Automatic proxy selection, manual / scheduled runs, WAN accelerator enabling, backup window / termination, backup throttling
Backup job options continued
JobScriptCommand: Scripts for pre- and post-job enabled / disabled, script paths, frequency to run scriptsNotificationOptions: SNMP notification enabling / disabling, email notification enabling / disabling, email settings for success / warning / error, suppress email until last retry, VM attribute to update upon successSanIntegrationOptions: SAN snapshots enabling / disabling, VMs to back up per SAN snapshot, failback to VM snapshot, Hewlett Packard Enterprise / Nimble-specific SAN integration settingsSqlLogBackupOptions: SQL transaction backups enabling / disabling, log backup interval, log retention intervalViSourceOptions: Encrypt LAN traffic, failover to NBD, CBT enabling / disabling, VMware tools quiescence enabling / disabling, VM template backup enabling / disabling, exclusion of swapfile / dirty blocks
Other options to be aware of
GenerationPolicy: (Backup copy jobs settings) Enabling and retention period for deleted VMs, backup copy interval (RPO definition), sync interval start time, GFS retention settings
EpPolicyOptions: (Backup agent settings) Authentication mode, agent / server controlled, backup system state / user folders / specific paths, include file system items, include / exclude masks, retention, backup target
CloudReplicaTargetOptions: Veeam Cloud Connect host and storage
ViCloudReplicaTargetOptions: Veeam Cloud Connect replica enabling / disabling, Veeam Cloud Connect replica host and storage
Replica & Hyper-V options
ReplicaSourceOptions: Option to replicate from backupsReIPRulesOptions: Rules for re-IP of replica VMsViReplicaTargetOptions: (VMware) Replica name suffix / prefixes, replica target folder / resource pool / datastore, re-IP enabling / disabling, VM seeding optionsViNetworkMappingOptions: VMware replica job network mappings
HvSourceOptions: CBT enabled / disabled, Hyper-V quiescence, crash consistency, off-host backup, exclude swap files / dirty blocksHvReplicaTargetOptions: (Hyper-V replicas) Seeding settings, target folder, re-IP on replica, use network mapping options, VM mapping optionsHvNetworkMappingOptions: Networking mappings for Hyper-V host
Moving past the basics
Setting advanced options
Method 1 – Native Veeam cmdlets:• Set-VBRJobAdvancedOptions
• Set-VBRJobAdvancedNotificationOptions
Method 2 – No parameter for Set-VBRJobAdvanced* cmdlet…
Time to kick it old school!
Set options – Direct property update
Some options cannot be set with parameters or built-in cmdlets, but Veeam still gives you a way to work.
Other options are noted as not possible to be enabled with Veeam PowerShell, but they’re still job options:
$JobOptions = $VeeamBackupJob | Get-VBRJobOptions$JobOptions.SanIntegrationOptions.UseSanSnapshots = $false $JobOptions.BackupStorageOptions.RetainDays = '14' $JobOptions.BackupStorageOptions.EnableDeletedVmDataRetention = $trueSet-VBRJobOptions -Job $VeeamBackupJob -Options $JobOptions
Cue the Clarkson – POWER!!!
• When you use your imagination, as prompted in the “Understanding Veeam Cmdlets” page, you can perform some widescale advanced configuration
• This makes proxy / repository maintenance easier for your other scripting and tooling
• Perform functions that are feature requests — backup proxy groups:
$VeeamProxy1 = Get-VBRViProxy -Name 'proxy1'$VeeamProxy2 = Get-VBRViProxy -Name 'proxy2'$VeeamBackupJob | Set-VBRJobProxy -Proxy $VeeamProxy1, $VeeamProxy2
Let’s not forget the physicals/clusters
• Veeam Agents and protection groups can also be controlled in code*• (*Protection group jobs not possible with PowerShell yet)
$VeeamDomain = Get-VBRADDomain -ServerName 'dc2.veeamlab.local' -Credentials $VBRProxyCred
$VeeamDomainComputer = Find-VBRADEntity -Domain $VeeamDomain -Name 'dc.veeamlab.local’ -Recurse
$VeeamADScope = New-VBRADContainer -Domain $VeeamDomain -Entity $VeeamDomainComputer -MasterCredentials $VBRProxyCred -ExcludeVMs:$false -ExcludeComputers:$false
$VeeamProtectionGroup = Add-VBRProtectionGroup -Name "AD Backup" -Description "Physical Server Agent" -Container $VeeamADScope
Enable-VBRProtectionGroup -ProtectionGroup $VeeamProtectionGroup
Takeaways
PowerShell types: https://helpcenter.veeam.com/docs/backup/powershell/veeam_powershell_types.html?ver=95
PowerShell enumerations:https://helpcenter.veeam.com/docs/backup/powershell/enums.html?ver=95
Veeam unattended install:https://github.com/VeeamHub/powershell/tree/master/BR-UnattendedInstall
Digging into PowerShell parameters:https://richardspowershellblog.wordpress.com/2018/03/05/cmdlet-parameters/
Handy PowerShell scripts:https://www.powershellgallery.com/packages/PowerShellCookbook/1.3.6
Thank you
Session Survey Available Now!
Please take the very short (5 question) surveythrough your mobile app now!
Tap on the session
Scroll down past Presenters
Tap Session Feedback Survey