PowerShell script exchange
Post Reply
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by Kiranpn »

Hi Team,
We need to check the increment and full restore points to check. For
instance, one of our VM has 10 daily increment without any full, we need to
check it manually at the moment and it is very time consuming.
We would like Powershell script to print these all in csv file.
We have created one powershell script by modifying (already made by someone
in this forum for their environment). This is working but it is taking lots
of time and giving all unnecessary information.
Is there any way to make it faster by modifying this script?

Code: Select all

Disconnect-VBRServer  #Disconnect Server


Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue   # Adding
VeeamSnapin
Connect-VBRServer -Server "localhost"-Port "9392"                          
     # To connect Veeam Server

remove-item "desktop\FolderData3.csv" -force
$veeam_vms = Find-VBRViEntity | Where-Object {$_.id -like "*_vm*"} | sort
name
$backupcheckdate = (get-date).AddDays(-31)
$colrestorepoints= @()
foreach($vm in $veeam_vms)
{
$veeamrestorepoints = $null
$vmname = $vm.name
#write-host "Checking $vmname"
write-host "working on $vmname"
$veeamrestorepoints = Get-VBRRestorePoint -Name $vmname | Where-Object
{($_.GetBackup().JobType -eq "") -AND ($_.creationtime -ge
$backupcheckdate)} | Sort-Object $_.creationtime -Descending
$colrestorepoints += $veeamrestorepoints
}

$colrestorepoints | Export-Csv -Path desktop\FolderData3.csv
-NoTypeInformation -Append # Saves Result in Csv file
PetrM
Veeam Software
Posts: 3261
Liked: 526 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr Makarov
Location: Prague, Czech Republic
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by PetrM » 1 person likes this post

Hi Kiran,

Mind me asking to clarify your use case, in particular, how it turned out that fulls are missing in some of incremental chains and why do you need to check it on regular basis? Basically, any incremental run will be failed and won't create a restore point if there is no full.

Thanks!
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by oleg.feoktistov » 1 person likes this post

Hi Kiran,

As for the script itself - on every loop run you invoke Get-VBRRestorePoint cmdlet and apply filtering using dynamic method (GetBackup()).
That's the main reason of such low performance. Try getting all restore points at once first and then filtering them on a loop cycle by vm name using cached value from $veeamrestorepoints:

Code: Select all

Disconnect-VBRServer  #Disconnect Server


Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue   # Adding
VeeamSnapin
Connect-VBRServer -Server "localhost"-Port "9392"                          
     # To connect Veeam Server

remove-item "desktop\FolderData3.csv" -force
$veeam_vms = Find-VBRViEntity | Where-Object {$_.id -like "*_vm*"} | sort Name
$backupcheckdate = (get-date).AddDays(-31)
$veeamrestorepoints = Get-VBRRestorePoint | where {($_.GetBackup().JobType -eq "") -AND ($_.creationtime -ge `
$backupcheckdate)} | Sort-Object $_.creationtime -Descending
$colrestorepoints= @()
foreach($vm in $veeam_vms)
{
$vmname = $vm.name
#write-host "Checking $vmname"
write-host "working on $vmname"
$veeamrestorepoint = $veeamrestorepoints | where {$_.Name -eq $vmname}
$colrestorepoints += $veeamrestorepoint
}

$colrestorepoints | Export-Csv -Path C:\FolderData3.csv -NoTypeInformation -Append # Saves Result in Csv file
I've just tested both scripts in my lab and can say that upon refactoring execution time has dropped tremendously: 8 mins vs. 10 seconds now.

Thanks,
Oleg
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by Kiranpn »

PetrM wrote: Apr 29, 2021 11:04 am Hi Kiran,

Mind me asking to clarify your use case, in particular, how it turned out that fulls are missing in some of incremental chains and why do you need to check it on regular basis? Basically, any incremental run will be failed and won't create a restore point if there is no full.

Thanks!

Hi PetrM
We have been having this issue for a long time, not sure the reason.
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by Kiranpn »

oleg.feoktistov wrote: Apr 29, 2021 12:37 pm Hi Kiran,

As for the script itself - on every loop run you invoke Get-VBRRestorePoint cmdlet and apply filtering using dynamic method (GetBackup()).
That's the main reason of such low performance. Try getting all restore points at once first and then filtering them on a loop cycle by vm name using cached value from $veeamrestorepoints:

Code: Select all

Disconnect-VBRServer  #Disconnect Server


Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue   # Adding
VeeamSnapin
Connect-VBRServer -Server "localhost"-Port "9392"                          
     # To connect Veeam Server

remove-item "desktop\FolderData3.csv" -force
$veeam_vms = Find-VBRViEntity | Where-Object {$_.id -like "*_vm*"} | sort Name
$backupcheckdate = (get-date).AddDays(-31)
$veeamrestorepoints = Get-VBRRestorePoint | where {($_.GetBackup().JobType -eq "") -AND ($_.creationtime -ge `
$backupcheckdate)} | Sort-Object $_.creationtime -Descending
$colrestorepoints= @()
foreach($vm in $veeam_vms)
{
$vmname = $vm.name
#write-host "Checking $vmname"
write-host "working on $vmname"
$veeamrestorepoint = $veeamrestorepoints | where {$_.Name -eq $vmname}
$colrestorepoints += $veeamrestorepoint
}

$colrestorepoints | Export-Csv -Path C:\FolderData3.csv -NoTypeInformation -Append # Saves Result in Csv file
I've just tested both scripts in my lab and can say that upon refactoring execution time has dropped tremendously: 8 mins vs. 10 seconds now.

Thanks,
Oleg
Thank you, Oleg. It is working as intended and a lot quicker than before. I am still waiting for the final CSV file. I will update asap once it is done.

Regards,
Kiran Pradhan
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by Kiranpn »

Hi Team,
Thank you very much for correcting my script, is there anyway to get only those VM who has Incremental without full backup for last 7 days.

Regards,
Kiran
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by Kiranpn »

Hi Team,
I am trying to get the only those VM who doesn't have "full" backup for last 7 days.
Currently, with above script I am getting all vm list which has full and incremental backup.
In our environment, it is thousands of VM and very time consuming to go through each of them.
We want to check if there is at least one full backup in one week.

Regards,
Kiran
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by soncscy »

Hey Kiran,

This is really something you should separate out into another bit of code, but luckily it looks like Oleg's edit more or less makes an ordered list for you.

Code: Select all

$vmname = $vm.name
#write-host "Checking $vmname"
write-host "working on $vmname"
$veeamrestorepoint = $veeamrestorepoints | where {$_.Name -eq $vmname}
$colrestorepoints += $veeamrestorepoint
In this code block, you can add in a validation on $veeamrestorepoint with the GetFull() method. Since the first item in the array should be the most recent, you can add the following validation:

Code: Select all

$vRP = Veeamrestorepoint | sort-object -property CreationTime -Descending | select -First 1
$lastFull =  $vRP.GetFull()
if($lastFull.CreationTime.Date -gt (Get-Date).Date.AddDays(-7)){
do action
}
You can add it to the same array, or initialize a separate one like $BackupsWithoutRecentFull = @() and add the VM name to that, or whatever you want.

Edit: Small edit as I guess we do have to sort still -- seems the select for $veeamrestorepoint returns the objects unordered, so have to add in a sort.
Kiranpn
Enthusiast
Posts: 27
Liked: 2 times
Joined: Mar 18, 2021 4:48 am
Full Name: Kiran Pradhan
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by Kiranpn »

Thank you, Soncsy
I think I have done something wrong with your instruction. Got only a few vm but came with the Full and incremental.
I am sorry to ask you again but would you mind where to put these above code in my below script.

Code: Select all

Disconnect-VBRServer  #Disconnect Server


Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue   # Adding VeeamSnapin
Connect-VBRServer -Server "localhost"-Port "9392"                          
     # To connect Veeam Server

remove-item "desktop\FolderData3.csv" -force
$veeam_vms = Find-VBRViEntity | Where-Object {$_.id -like "*_vm*"} | sort Name
$backupcheckdate = (get-date).AddDays(-7)
$veeamrestorepoints = Get-VBRRestorePoint | where {($_.GetBackup().JobType -eq "") -AND ($_.creationtime -ge `
$backupcheckdate)} | Sort-Object $_.creationtime -Descending
$colrestorepoints= @()
foreach($vm in $veeam_vms)
{
$vmname = $vm.name
#write-host "Checking $vmname"
write-host "working on $vmname"
$veeamrestorepoint = $veeamrestorepoints | where {$_.Name -eq $vmname}
$colrestorepoints += $veeamrestorepoint
}

$colrestorepoints | Export-Csv -Path C:\FolderData3.csv -NoTypeInformation -Append # Saves Result in Csv file
Regards,
Kiran Pradhan
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Trying to get restore points for last few days to check if there are increment back up without any full backup

Post by soncscy » 1 person likes this post

I promise only teasing slightly Kiran, but since we call on $veeamrestorepoint to sort, I guess it better go after we initialized it, right? ;)

So in the last code block after $veeamrestorepoint is where you'd add this new logic.

Probably you can shorten it to a single line, but for now as you're learning, I think keep it as is.

Again, though, you have two competing logics here:

Original script with Oleg's edits is intended to print out backups for last 30 days for all VMs
New code is a special flag that prints only VMs without a Full for last 7 days.

So I think you need to either:

1. Write a parameter flag to trigger this logic only if you want to find backups without a recent full
2. Write a separate version of the same script that as this logic.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests