PowerShell script exchange
Post Reply
Kiranpn
Novice
Posts: 4
Liked: never
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: 1210
Liked: 189 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: 904
Liked: 319 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
Novice
Posts: 4
Liked: never
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
Novice
Posts: 4
Liked: never
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

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests