Script to Verify VM's are backed up?

PowerShell script exchange

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

Veeam Logoby Gatoo » Mon Aug 20, 2012 2:09 pm 1 person likes this post

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!
Gatoo
Service Provider
 
Posts: 6
Liked: 1 time
Joined: Fri Jul 06, 2012 4:55 pm
Full Name: Gatien GHEZA

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

Veeam Logoby tsightler » Mon Aug 20, 2012 3:15 pm 1 person likes this post

Find-VBRObject : Cannot validate argument on parameter 'Server'. The argument is null. Supply a non-null argument and try the command again.
At C:\sources\powershell\Veeam\vm_backup_status_dev.ps1:23 char:33
+ $vmobjs = Find-VBRObject -Server <<<< $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine"}


This error indicates that it didn't properly locate the vCenter server object which implies that the $vCenter server parameter didn't match the name of the vCenter as it was added to VMware. The only lines of code involved are as follows:

Code: Select all
# vCenter server
$vcenter = "<vcenter_name>"
$vcenterobj = Get-VBRServer -Name $vcenter
$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine"}


These lines aren't really different between the development version and the older versions. The "<vcenter_name>" must match the name of the VM as it's shown within Veeam so that the $vcenterobj will be populated. Any chance you had a typo in the vCenter server name?
tsightler
Veeam Software
 
Posts: 4767
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

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

Veeam Logoby Gatoo » Mon Aug 20, 2012 3:23 pm

I edited my message but too slowly appearently ;)

Sorry, I put the fqdn of my server instead of it's netbios name (as it's registered in the VEEAM server).
Gatoo
Service Provider
 
Posts: 6
Liked: 1 time
Joined: Fri Jul 06, 2012 4:55 pm
Full Name: Gatien GHEZA

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

Veeam Logoby tsightler » Mon Aug 20, 2012 4:39 pm

Gatoo wrote: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


Thanks for testing. The mail and HTML options are planned as soon as I get time. The current results should be sorted by Job Name A-Z, are you saying you also want the VMs within the jobs to be sorted this way or are you seeing some other sorting behavior?
tsightler
Veeam Software
 
Posts: 4767
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

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

Veeam Logoby Gatoo » Tue Aug 21, 2012 4:41 pm

Oh yeah you sort by JOB so all the VM are in order of the job.

I was speaking about VM order absolutely, but that's a details and it's not a "must have".

EDIT : just launch the script again and you're right, it's definitely more practical to sort by jobs than by vms ;)
Gatoo
Service Provider
 
Posts: 6
Liked: 1 time
Joined: Fri Jul 06, 2012 4:55 pm
Full Name: Gatien GHEZA

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

Veeam Logoby Gatoo » Thu Sep 13, 2012 8:39 pm

Hey! Do you have any update about this dude?
Gatoo
Service Provider
 
Posts: 6
Liked: 1 time
Joined: Fri Jul 06, 2012 4:55 pm
Full Name: Gatien GHEZA

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

Veeam Logoby Vitaliy S. » Thu Sep 13, 2012 8:55 pm

Hi Gatien, I guess Tom has put this script on hold, since this report and other requested functionality will be available in Veeam ONE natively. If you're going to VMworld in Barcelona make sure you stop at our booth to see everything yourself.
Vitaliy S.
Veeam Software
 
Posts: 19539
Liked: 1097 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

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

Veeam Logoby tsightler » Thu Sep 13, 2012 11:55 pm 1 person likes this post

Yes, I'll admit I haven't spent much time on this lately due to exactly that reason. The code as is met the immediate need I was trying to address and actually exceeded my original goals, and while I may still enhance this code in the future (perhaps not everyone will purchase Veeam ONE, though we can hope), I just haven't had the time to work on it lately.
tsightler
Veeam Software
 
Posts: 4767
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

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

Veeam Logoby Marshawnm » Wed Apr 24, 2013 7:06 pm

Great script! I am still learning ps, so I wanted to know if the out put can be sent to Out-File instead of writing to the screen?
Marshawnm
Novice
 
Posts: 3
Liked: 1 time
Joined: Thu Aug 16, 2012 6:04 pm
Full Name: Marshawn McLeod

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

Veeam Logoby v.Eremin » Thu Apr 25, 2013 10:32 am

Great script! I am still learning ps, so I wanted to know if the out put can be sent to Out-File instead of writing to the screen?

Yep, it can be done easily with a few modifications:

Code: Select all
$String = foreach ($vm in $vms.Keys)
{
  if ($vms[$vm] -eq "Protected") {
      write-output "$vm was backed up in the past $DaysToCheck day(s)"
  } else {
      Write-Output "$vm was NOT backed up in the past $DaysToCheck day(s)"
   }
}
$String > D:\Test.txt


Thus, in the end of the script .txt-file will be created, containing all information regarding protected VMs.

If we tried to be a little bit more creative, we could put into use the following example:

Code: Select all
$FilePath = 'D:\VMProtectedReport\'+("{0:yyyy-MM-dd}" -f (get-date))+'.txt'
New-Item -Path $filepath -ItemType file -Force
$String > $filepath


In this case, VMProtectedReport folder will be created and corresponding report file will fall into it. Additionally, this file will be named in a certain way (date when the script is executed).

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

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

Veeam Logoby v.Eremin » Thu Apr 25, 2013 10:36 am 1 person likes this post

Furthermore, it might be worth taking a look at special report available in VeeamOne, called Protected VMs report. It shows what VMs in your virtual environment are protected with backups and replicas. It provides information on the latest backup/replica state and shows the number of stored restore points for every protected VM.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

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

Veeam Logoby cerede2000 » Wed Sep 10, 2014 9:23 am 1 person likes this post

Hello,

More simply for compare ?
Code: Select all
$esx=Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | foreach{$_.Name} | Sort-Object
$backup=Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -or $_.JobType -eq "Replica" -and $_.EndTime}|foreach{$_.gettasksessions() | Where-Object {$_.Status -ne "Failed"}} |foreach{$_.Name} | Sort-Object | Get-Unique
Compare-Object $esx $backup
cerede2000
Influencer
 
Posts: 16
Liked: 1 time
Joined: Tue Sep 09, 2014 2:24 pm
Full Name: Benjamin CEREDE

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

Veeam Logoby Andreas Neufert » Mon Dec 15, 2014 1:25 pm

I searched for a way to output a single VM status from a job and found this topic. I place this example here for those who just want to find this out.

Code: Select all
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
$JobName = "YourJobName"
$JobVMName = "YourVMNameinthatJob"
$JobObjectSession = Get-VBRBackupSession | Where-Object  {$_.JobName -eq $JobName } | Sort CreationTime -Descending | Select -First 1
$JobObjectSessionLastVM = $JobObjectSession.gettasksessions() | Where-Object {$_.Name -eq $JobVMName}
[string]$JobObjectSessionLastVM.Status

Output is "Success", "Warning", "InProgress", "Failed" or "" (Empty).
It can be empty when the job never runned or the actual job running but do not process this VM.
Andreas Neufert
Veeam Software
 
Posts: 2198
Liked: 357 times
Joined: Wed May 04, 2011 8:36 am
Location: Germany
Full Name: @AndyandtheVMs Veeam PM

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

Veeam Logoby Geoffroi » Mon Mar 23, 2015 4:01 pm 3 people like this post

Hello,

Inspired by the script of tsighlter I've made a plugin for vCheck ( https://github.com/alanrenouf/vCheck-vSphere )

Code: Select all
#Verify if Virtual Machines have been backed up
#Writed by Geoffroi Genot based on the work of tsighlter on VEEAM Forum (http://forums.veeam.com/powershell-f26/script-to-verify-vm-s-are-backed-up-t12714.html)

# Start of Settings
# List of VM to exclude (by name) separated by a comma i.e: @("vm1","vm2")
$excludevms=@()
# Number of days to check, if a VM is not backed up within this interval it will be considered as not backed up         
$DaysToCheck= 7
# End of Settings

#Try to load VEEAM snapin, otherwise stop the process
asnp "VeeamPSSnapIn" -ErrorAction Stop

# Build hash table with excluded VMs
$excludedvms=@{}
foreach ($vm in $excludevms) {
    $excludedvms.Add($vm, "Excluded")
}

# Get a list of all VMs from vCenter and add to hash table, assume Unprotected
$Result=@()
foreach ($vm in ($FullVM | Where { $_.Runtime.PowerState -eq "poweredOn" } | ForEach-Object {$_ | Select-object @{Name="VMname";Expression={$_.Name}}}))  {
   if (!$excludedvms.ContainsKey($vm.VMname)) {
        $vm | Add-Member -MemberType NoteProperty -Name "backed_up" -Value $False
        $Result += $vm
    }
}

# Find all backup job sessions that have ended in the last week
$vbrsessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -or $_.JobType -eq "Replica" -and $_.EndTime -ge (Get-Date).adddays(-$DaysToCheck)}

# 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 $false}
$Title = "Running VMs that were not backed up in the last $DaysToCheck day(s)"
$Header =  "Running VMs that were not backed up in the last $DaysToCheck day(s)"
$Comments = "The following VMs were not backed up in the last $DaysToCheck day(s). They are probably not in a backup job or were in a failure state"
$Display = "Table"
$Author = "Geoffroi Genot"
$PluginVersion = 1.0
$PluginCategory = "VEEAM"


I hope it will be useful :)
Geoffroi
Lurker
 
Posts: 2
Liked: 3 times
Joined: Mon Mar 23, 2015 3:43 pm
Full Name: Geoffroi Genot

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

Veeam Logoby glamic26 » Tue Apr 21, 2015 12:18 pm 1 person likes this post

Thanks Geoffroi that could be really useful to me. Out of interest how do you get this to run as part of your vCheck without it running on you Veeam server? I only seem to be able to run the Veeam Powershell commands from the Veeam Backup Server. I tried to install the Veeam Powershell plugin on the server that runs our vCheck script but it won't install it without Veeam B&R installed.
glamic26
Service Provider
 
Posts: 18
Liked: 9 times
Joined: Tue Apr 21, 2015 12:10 pm

PreviousNext

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests