PowerShell script exchange
Post Reply
swizzle
Novice
Posts: 8
Liked: never
Joined: Jun 11, 2010 9:28 pm
Full Name: Peter Mott
Location: New Zealand
Contact:

Detecting incomplete backups

Post by swizzle »

Does anybody have a script that checks if a Veeam snapshot exists on a vm before attempting to backup?

Bad things happen if Veeam attempts to backup a vm that is already being backed up (by another instance) or is in an incomplete state due to a previous failed backup.

My idea is to test the state of each vm in the script and either wait for the snapshot(s) to be deleted before continuing, or skip the vm (potentially returning to it at the end of the backup run).
Gostev
Chief Product Officer
Posts: 31806
Liked: 7300 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: Detecting incomplete backups

Post by Gostev »

swizzle wrote:Bad things happen if Veeam attempts to backup a vm that is already being backed up (by another instance) or is in an incomplete state due to a previous failed backup.
v6 has no issues with either scenario, so bad things don't happen.
jkcouch
Enthusiast
Posts: 30
Liked: never
Joined: Jun 26, 2011 7:02 pm
Full Name: Jeff Couch
Contact:

Re: Detecting incomplete backups

Post by jkcouch »

What version of Veeam are you using & how are you building your jobs? By that I mean are you using folders in vcenter, datastores or individual virtual machines?

In my environment, I use v6 and only backup by VM object. This way I can easily determine what job my vm is in on the same server. I use the following script as a check to ensure that I don’t backup an object twice by mistake. I run this daily after another script polls vCenter for new VMs. You can schedule it and send the output to email if there are any duplicate vm objects to report. I hope you can find it useful.

Code: Select all

Function Get-Duplicate {
    param($array, [switch]$count)
    begin {
        $hash = @{}
    }
    process {
        $array | %{ $hash[$_] = $hash[$_] + 1 }
        if($count) {
            $hash.GetEnumerator() | ?{$_.value -gt 1} | %{
                New-Object PSObject -Property @{
                    Value = $_.key
                    Count = $_.value
                }
            }
        }
        else {
            $hash.GetEnumerator() | ?{$_.value -gt 1} | %{$_.key}
        }
    }
}

$Jobs = Get-VBRJob

# get all objects in Jobs
$JobObjectReport = @()
foreach ($job in $jobs){
	$Objects = Get-VBRJobobject -job $job
		Foreach ($Object in $Objects){
	$JobObjects = "" | select Name, JobName, ApproxSize
	$JobObjects.Name = $Object.Name
	$JobObjects.JobName = $job.Name
	$JobObjects.ApproxSize = ($Object.ApproxSizeString).split(' ')[0]
	$JobObjectReport += $JobObjects 
	}
}


$VMObjects = New-Object System.Collections.ArrayList 
foreach ($VMObject in $JobObjectReport){
	[Void] $VMObjects.Add($VMobject.Name)
	}

$DuplicateReport = @()
foreach ($Item in $Duplicates){
	foreach ($VMObject in $JobObjectReport){
		if ($Item -eq $VMobject.Name){
			$DuplicateReport +=$VMobject
			}
		}
	}
	
$DuplicateReport

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests