PowerShell script exchange
Post Reply
jgrote
Influencer
Posts: 13
Liked: 4 times
Joined: Jul 13, 2010 12:14 am
Full Name: Justin Grote
Contact:

Handy Powershell One-Liners - Veeam Backup Coverage Reports

Post by jgrote »

A few one liners we give to our NOC techs to quickly inspect customer Veeam systems and generate coverage reports. Handy for quick cut and paste checks. Hope these are useful as slightly more advanced "getting started" examples.

WARNING: There is a minor flaw in that synthetic full backups count as full backups, even if the VM hasn't been backed up from the source. I'm working on the best way to filter those out in a simple manner.

Prerequisites
These assume Powershell v3 or later, and you have the veeam snapin running.

Code: Select all

Add-PSSnapin veeampssnapin -registered
Some assume you also have VMware PowerCLI, if you are running Powershell 5.0 or later you can quickly install and start with this command:

Code: Select all

install-module vmware.powercli -scope currentuser;connect-viserver
These work in a powershell remoting session if you want to remote from your workstation, for example:

Code: Select all

etsn mybackupserver1
Get the latest valid backup date (excluding Replicas) of all current restore points, sorted by VM Name

Code: Select all

Get-VBRRestorePoint | where type -notmatch 'Snapshot' | where isConsistent | group name | sort name | foreach {$PSItem | % Group | sort creationtime -descending | select -first 1 name,type,creationtime}
Get VMs that haven't backed up in the last 3 days (but have backed up at least once before)
This one is handy if you set up as a daily or hourly check and have it mail you the results

Code: Select all

Get-VBRRestorePoint | where type -notmatch 'Snapshot' | group name | sort name | foreach {$PSItem | % Group | sort creationtime -descending | select -first 1 name,type,creationtime} | where creationtime -lt (get-date).adddays(-3) 
Get the latest backup date of all Powered On VMs in vCenter, sorted by VM name (assumes PowerCLI)
Note: We tried to "filter left" on this one and only retrieve restore points on a per-VM basis, but the Veeam per-VM queries take forever, much faster to just get all restore points up front and have Powershell do the filtering work. If you have a massive infrastructure (50k+ restore points I guess) you may need more memory to run this script but it should work fine)

Code: Select all

$RPs = get-vbrrestorepoint | where isconsistent;get-vm | where powerstate -match 'PoweredOn' | sort name | foreach {$RPItem = $RPs | where vmname -match $PSItem.name | sort creationtime -descending | select -first 1 name,type,creationtime; if ($RPItem) {$RPItem} else {[PSCustomObject]@{Name=$PSItem.Name;Type="NOTBACKEDUP";CreationTime="NOTBACKEDUP"}}}
And pulling it all together...
Get Powered On VMs in vCenter that have not been backed up in the last 3 days (assumes PowerCLI)

Code: Select all

$RPs = get-vbrrestorepoint | where isconsistent;get-vm | where powerstate -match 'PoweredOn' |sort name | foreach {$RPItem = $RPs | where vmname -match $PSItem.name | sort creationtime -descending | select -first 1 name,type,creationtime; if ($RPItem) {$RPItem} else {[PSCustomObject]@{Name=$PSItem.Name;Type="NOTBACKEDUP";CreationTime="NOTBACKEDUP"}}} | where {$PSItem.creationtime -lt (get-date).adddays(-3) -or $PSItem.type -match 'NOTBACKEDUP'}
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests