PowerShell script exchange
Geoffroi
Lurker
Posts: 2
Liked: 3 times
Joined: Mar 23, 2015 3:43 pm
Full Name: Geoffroi Genot
Contact:

Re: Script to Verify VM's are backed up?

Post by Geoffroi »

Hi Glamic,

Honestly I didn't tried to run on an other server. The issues is that VEEAM PowerCLI doesn't allow to remote connect to a VEEAM server like VMWARE PowerCLI.

See this topic : http://forums.veeam.com/powershell-f26/ ... t7443.html

As suggested in this topic, you could try to use

Code: Select all

Invoke-Command -ComputerName "VBR-01" -ScriptBlock "asnp VeeamPSSnapin; #some code, using semicolons instead of line breaks#"
To execute "Get-VBRBackupSession"

Unfortunately I'm not able to test because only my VEEAM host is in Windows
michaelryancook
Expert
Posts: 116
Liked: 14 times
Joined: Nov 26, 2013 6:13 pm
Full Name: Michael Cook
Contact:

Re: Script to Verify VM's are backed up?

Post by michaelryancook »

Hi Geoffroi. I am curious where your script gets $FullVM from as I don't see that anywhere else in your script or in vCheck.
michaelryancook
Expert
Posts: 116
Liked: 14 times
Joined: Nov 26, 2013 6:13 pm
Full Name: Michael Cook
Contact:

Re: Script to Verify VM's are backed up?

Post by michaelryancook »

Nvm, I had not run vCheck yet.
michaelryancook
Expert
Posts: 116
Liked: 14 times
Joined: Nov 26, 2013 6:13 pm
Full Name: Michael Cook
Contact:

Re: Script to Verify VM's are backed up?

Post by michaelryancook »

In the section below, shouldn't it be "$Result | where {$_.backed_up -eq $false}"?

As $VMObj.backed_up = $true when the VMs status is not equal to failed. Then the result is currently looking for when $_.backup_up = $true to display the unprotected VMs. When it shoudl be looking for $_.backed_up = $false to display unprotected VMs.

Code: Select all

# Find all successfully backed up VMs in selected sessions (i.e. VMs not ending in failure) and update status to "Protected"
foreach ($session in $vbrsessions) {
    foreach ($vm in ($session.gettasksessions() | Where-Object {$_.Status -ne "Failed"} | ForEach-Object { $_ | Select-object @{Name="VMname";Expression={$_.Name}}})) {
      $VMObj = $Result | where {$_.VMName -eq $vm.VMname }
      if ($VMObj){
         $VMObj.backed_up = $true
      }
    }
}

$Result | where {$_.backed_up -eq $true}
mobyzone
Lurker
Posts: 1
Liked: never
Joined: Jun 04, 2015 2:07 pm
Full Name: Dan
Contact:

[MERGED] : Powershell - Identify VM's not added to a Backup

Post by mobyzone »

Hi there,

Does anyone know if it is possible to do a scan on vCenter for all VM's and see if they are added into a backup job? Reason being we have around 300 VM's and we had an issue with one of the VM's that needed to be restored but it wasn't being backed up at all.

Is it possible using powershell that I can run a scheduled task daily?

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

Re: Script to Verify VM's are backed up?

Post by veremin »

Hi, Dan,

Kindly, see the scripts provided in this topic; should be something you're looking for.

Thanks.
Brad.Morris
Enthusiast
Posts: 43
Liked: 2 times
Joined: Sep 01, 2014 10:29 pm
Full Name: Brad Morris
Location: Melbourne, Australia
Contact:

[MERGED] : How to list all backup points for a Guest

Post by Brad.Morris »

Hi there,

I would like to know how I can get a report of all the backup points for a particular server from all backup sources.

For example.
I have a server called Server1. I have several different backup jobs that have backed this server up over time. So if I go into Backups and search for Server1. I can see several jobs that have backed this server up. And each job might have several restore points.

What I would like to do is to be able to run a script that will report back to me a list of all the jobs and restore points in those jobs for this server.

Hope this makes sense.

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

Re: Script to Verify VM's are backed up?

Post by veremin »

Check either Protected VMs report available in Veeam ONE or one of the scripts provided above and see whether it meets your expectations. Thanks.
albertwt
Veteran
Posts: 942
Liked: 53 times
Joined: Nov 05, 2009 12:24 pm
Location: Sydney, NSW
Contact:

Re: Script to Verify VM's are backed up?

Post by albertwt »

Gatoo wrote:Hi,

I tried the dev script and everything works perfect! No more errors. Exclusions are ok, colors ok.

Some adds possible :
- Sort the result in alphabetical order (A-Z)
- Mail sending
- Export to html

Congrats!
Which script was working ?
--
/* Veeam software enthusiast user & supporter ! */
battles
Service Provider
Posts: 31
Liked: 1 time
Joined: Apr 07, 2017 2:03 pm
Full Name: Battles
Contact:

[MERGED] Get list of VMs protected - by host

Post by battles »

Hello,

I'd like to get a quick list of VMs that are currently getting backed up with Veeam - split out by host since we have many hosts connected to the Veeam B&R server.

TIA
nielsengelen
Product Manager
Posts: 5797
Liked: 1215 times
Joined: Jul 15, 2013 11:09 am
Full Name: Niels Engelen
Contact:

Re: Get list of VMs protected - by host

Post by nielsengelen »

There are multiple posts about this subject already; have a look at post241577.html?hilit=vm%20backed%20up#p241577
Personal blog: https://foonet.be
GitHub: https://github.com/nielsengelen
itlicenses
Lurker
Posts: 1
Liked: never
Joined: Oct 19, 2017 2:58 pm
Full Name: IT Licenses
Contact:

[MERGED] last backup result and date for a particular VM

Post by itlicenses »

Hi,

First of all, I'm quite new to Veean and Powershell. I've already been writing some PowerShell scripts and everthing seems to work fine, but I wanted to know if the following is possible.

I'd like to monitor the last backup status and date for individual hosts. In particular, we use zabbix to monitor our hosts, and it would be great if I could have a trigger that told me that a successful backup has not been made for a host for more than X days. Now, we don't have jobs per host, but per area and network.

So, in my way of thinking, I'd use zabbix to get the hostname and then, probably, use Get-VBRBackupSession to start looking for VM's inside the jobs listed there. Is that the correct approach? Would I be able to look for particular VM's and know if they were successful, had warnings or had errors? I read Get-VBRBackupSession is quite demanding to run, so perhaps, also, there's a more efficient way to get this information?

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

Re: Script to Verify VM's are backed up?

Post by veremin »

Kindly, check scripts provided above; should give you some thoughts on how to automate that.

Unfortunately, you wouldn't be able to avoid usage of Get-VBRBackupSession cmdlet (which indeed sometimes might work rather slow), but saving sessions to hash table and working with it afterwards should speed up the process.

Thanks.
drtalbert
Lurker
Posts: 1
Liked: never
Joined: Nov 10, 2017 11:51 pm
Contact:

[MERGED] Last successful

Post by drtalbert »

I am trying to find a way in powershell to pull the date of the last successful backup. So if I have a backup that runs daily and the last three days it has failed I would like to know the last date that it succeeded. I was able to find the last status for the sessions but that just shows failed for the failing ones. Any help would be great!
Shestakov
Veteran
Posts: 7328
Liked: 781 times
Joined: May 21, 2014 11:03 am
Full Name: Nikita Shestakov
Location: Prague
Contact:

Re: Script to Verify VM's are backed up?

Post by Shestakov »

Hi and welcome to the community!
Please review scripts provided above in the topic.
Thanks!
marius roma
Veteran
Posts: 459
Liked: 5 times
Joined: Feb 01, 2012 12:04 pm
Full Name: Mario
Contact:

[MERGED] Listing all VMs processed by jobs

Post by marius roma »

I need to list all the VMs processed by all my backup jobs.
Is there any sample I can start from?
Please consider that many jobs are not configured to backup single VMs but folders instead.
I started from a simple code like:

Code: Select all

Asnp VeeamPSSnapin
Get-VBRJob -Name "My_job_name" | Get-VBRJobObject
When I run the code I get a list of the folders backed up, while I need a list of the VMs.
Is there anything better I can start from?
Regards
marius
Vitaliy S.
VP, Product Management
Posts: 27377
Liked: 2800 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Script to Verify VM's are backed up?

Post by Vitaliy S. »

Hi Marius, If your goal is to know what VMs are protected (processed by a job) feel free to use script examples provided in this thread or take a look at Veeam ONE built-in functionality. Hope this helps!
Encinmat
Lurker
Posts: 1
Liked: never
Joined: Aug 05, 2020 3:53 am
Contact:

Re: Script to Verify VM's are backed up?

Post by Encinmat »

tsightler wrote: Jul 30, 2012 7:43 pm Just wanted to let people know that I have posted a development version of this script on my blog that includes the following enhancements:

- Proper handling of VMs with duplicate names in different datacenters
- VMs missing from jobs are listed first in the script output
- VMs that are found in backups also display Job Name in which they are found
- Simple wildcards are now support for exclusion list (for example *_replica to exlcude replica VMs)
- Parameter to define length of history to look for VMs in backup jobs (default 24 hours).

If anyone out there using this script can test this version in their environment and report their results that would be great. I'm pretty happy with the data that is currently being provided so assuming there are no major bugs my next step would be to update the output to support an simple HTML report and email options.

The development version can be found in this blog posting.
Hello,

Do you have the script? because the blog doesn't still exist.
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Script to Verify VM's are backed up?

Post by oleg.feoktistov »

Hi @Encinmat and Welcome to the Community Forums!

Well, it's been 8 years. Things change, blogs disappear :wink:
Anyway, what specific info you are after?

Thanks,
Oleg
jmke79
Novice
Posts: 9
Liked: 3 times
Joined: Aug 13, 2020 1:17 pm
Full Name: JM
Contact:

Re: Script to Verify VM's are backed up?

Post by jmke79 »

internet archive got you covered
One of the common report request that comes up on the Veeam forums is a method to report which VMs in the environment are being properly backed up. Currently Veeam has no built in report to compare the VMs in your environment to the VMs that are currently in your backup job, and while comparing this list is pretty easy if you have 20-30 VMs, it can quickly become a challenge as the environment gets larger and becomes more dynamic. This is my attempt to address the situation and learn some Powershell at the same time.

This script finds all VMs on a single vCenter server and looks through all Backup job sessions in the defined time period (currently 24 hours) and reports if they were successfully backed up or not.

The current “stable” version of this script can be downloaded here (7/3/2012). This version has to following limitations:

Tested only on vCenter/VMware environments
Duplicate VM names trip it up
Supports only a single vCenter at a time.
The current “development” version of this script is available here (7/30/2012). The primary enhancements of the development version when compared to the “stable” version are as follows:

Proper handling of VMs with duplicate names in different datacenters
VMs missing from jobs are listed first in the script output
VMs that are found in backups also display Job Name in which they are found
Simple wildcards are now support for exclusion list (for example *_replica to exlcude replica VMs)
Parameter to define length of history to look for VMs in backup jobs (default 24 hours).

Code: Select all

asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue

####################################################################
# Configuration
#
# vCenter server
$vcenter = "vc01.notyourdomain.com"
#
# To Exclude VMs from report add VM names to be excluded as follows
# simple wildcards are supported:
# $excludevms=@("vm1","vm2", "*_replica")
$excludevms = @()
#
# This variable sets the number of hours of session history to
# search for a successul backup of a VM before considering a VM
# "Unprotected".  For example, the default of "24" tells the script
# to search for all successful/warning session in the last 24 hours
# and if a VM is not found then assume that VM is "unprotected".
$HourstoCheck = 24
####################################################################

$vcenterobj = Get-VBRServer -Name $vcenter
$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine"}
$jobobjids = [Veeam.Backup.Core.CHierarchyObj]::GetObjectsOnHost($vcenterobj.id) | Where-Object {$_.GetItem().Type -eq "Vm"}

# Convert exclusion list to simple regular expression
$excludevms_regex = (‘(?i)^(‘ + (($excludevms | ForEach {[regex]::escape($_)}) –join “|”) + ‘)$’) -replace "\\\*", ".*"

foreach ($vm in $vmobjs) {
    $jobobjid = ($jobobjids | Where-Object {$_.ObjectId -eq $vm.Id}).Id
    if (!$jobobjid) {
        $jobobjid = $vm.FindParent("Datacenter").Id + "\" + $vm.Id
    }
    $vm | Add-Member -MemberType NoteProperty "JobObjId" -Value $jobobjid
}    
    
# Get a list of all VMs from vCenter and add to hash table, assume Unprotected
$vms=@{}
foreach ($vm in ($vmobjs | where {$_.Name -notmatch $excludevms_regex}))  {
	if(!$vms.ContainsKey($vm.JobObjId)) {
		$vms.Add($vm.JobObjId, @("!", [string]$vm.GetParent("Datacenter"), $vm.Name))
    }
}

# Find all backup job sessions that have ended in the last 24 hours
$vbrjobs = Get-VBRJob | Where-Object {$_.JobType -eq "Backup"}
$vbrsessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).addhours(-$HourstoCheck)}

if (!$vbrsessions) {
    write-host "No backup sessions found in last" $HourstoCheck "Hours!"
    exit
}

# Find all successfully backed up VMs in selected sessions (i.e. VMs not ending in failure) and update status to "Protected"
foreach ($session in $vbrsessions) {
    foreach ($vm in ($session.gettasksessions() | Where-Object {$_.Status -ne "Failed"} | ForEach-Object { $_ })) {
        if($vms.ContainsKey($vm.Info.ObjectId)) {
            $vms[$vm.Info.ObjectId][0]=$session.JobName
        }
    }
}

$vms = $vms.GetEnumerator() | Sort-Object Value

# Output VMs in color coded format based on status.
foreach ($vm in $vms)
{
  if ($vm.Value[0] -ne "!") {
      write-host -foregroundcolor green (($vm.Value[1]) + "\" + ($vm.Value[2])) "is backed up in job:" $vm.Value[0]
  } else {
      write-host -foregroundcolor red (($vm.Value[1]) + "\" + ($vm.Value[2])) "is not found in any backup session in the last" $HourstoCheck "hours"
  }
}
before trying it out, I would definitely go through the script, review the command used and validate
don't blindly run an 8 year old PS script on your 2020 env ;)


and that blog points to another blog
https://blog.smasterson.com/2017/12/22/ ... ort-9-5-3/

which has some nice script too;

down the internet rabbit hole we go
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Script to Verify VM's are backed up?

Post by oleg.feoktistov » 1 person likes this post

which has some nice script too;
@jmke79, or you can just find it on GitHub.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests