PowerShell script exchange
Post Reply
HothLord88
Lurker
Posts: 2
Liked: never
Joined: Oct 05, 2022 12:53 pm
Full Name: Sam Rosenberg
Contact:

Powershell to set Storage level corruption guard and File backup maintenance

Post by HothLord88 »

Hi Chaps,

There is a similar post from 2016 however i am having issues converting it to do what I need and am hoping you can help.

On the advanced settings under "Target" on a backup copy i need to Enable Storage-level Corruption guard, ticket the box that says " Perform backup files heath check" and set this to Last Saturday of the month

AND

Full Backup File Maintenance and tick "Remove deleted Items data after "30 days" and Defragment and compact full backup file to the last Sunday of the month.

This needs to be done based on a "foreach" bases based on backup copy name i have in a csv.

The original code looks like this:

Code: Select all

$days=@("Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday")
$weeks=@("First", "Second", "Third", "Fourth", "Last")

$d=0
$w=0

$jobs= get-vbrjob | ? {$_.JobType -eq "Backup"} | sort Name
foreach ($job in $jobs) {
  write-host $job.Name $days[$d] $weeks[$w]

  $Options=$job.getoptions()
  $Options.GenerationPolicy.RecheckScheduleKind = "Monthly"
  $Options.GenerationPolicy.RecheckBackupMonthlyScheduleOptions.DayOfWeek = $days[$d]
  $Options.GenerationPolicy.RecheckBackupMonthlyScheduleOptions.DayNumberInMonth = $weeks[$w]
  $Options.GenerationPolicy.EnableRechek = $true
  $job.SetOptions($Options) | out-null
  
  $d++
  if ($d -ge $days.count) { $d = 0 ; $w++ }
  if ($w -ge $weeks.count) { $w = 0 }
}


im not 100% sure it would do the second bit but i do believe it should be able to do "Full Backup File Maintenance and tick "Remove deleted Items data after "30 days" and Defragment and compact full backup file to the last Sunday of the month."

i have changed this to:

Code: Select all

$days=@("Saturday")
$weeks=@("Last")



$jobs=  import-csv C:\script\test.csv
foreach ($i in $jobs) {
  #write-host $job.bc-name $days $weeks

  $Options=$job.getoptions()
  $Options.GenerationPolicy.RecheckScheduleKind = "Monthly"
  $Options.GenerationPolicy.RecheckBackupMonthlyScheduleOptions.DayOfWeek = $days
  $Options.GenerationPolicy.RecheckBackupMonthlyScheduleOptions.DayNumberInMonth = $weeks
  $Options.GenerationPolicy.EnableRechek = $true
  $job.SetOptions($Options) | out-null
  
  $d++
  if ($d -ge $days.count) { $d = 0 ; $w++ }
  if ($w -ge $weeks.count) { $w = 0 }
}
but im getting

Code: Select all

Cannot find an overload for "SetOptions" and the argument count: "1".
At line:16 char:3
+   $job.SetOptions($Options) | out-null
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest
 

any ideas - if it need to be totally redone then so bit it :)

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

Re: Powershell to set Storage level corruption guard and File backup maintenance

Post by oleg.feoktistov »

Hi Sam,

The error you encountered basically means that the method SetOptions() no longer accepts precisely one argument. Now it also requires info on command initiator. But the method is quite old, and now there are some other approaches. Besides, I don't see that any part of your code interacts with full backup file maintenance options.

For the most options you mentioned you no longer need to use .NET reflections meaning the majority of tweaks can be now done with cmdlets. For health check and compact full configuration use the cmdlets below:

Code: Select all

$monthlyHealthCheck = New-VBRMonthlyOptions -DayNumberInMonth Last -DayOfWeek Saturday
$monthlyCompact = New-VBRMonthlyOptions -DayNumberInMonth Last -DayOfWeek Sunday
$job = Get-VBRJob -Name 'Backup Copy Job 1'
Set-VBRJobOptions -Job $job -Options $options
Set-VBRJobAdvancedOptions -Job $job -EnableHealthCheck `
-HealthCheckMonthlyOptions $monthlyHealthCheck -EnableCompactFull `
-CompactFullMonthlyOptions $monthlyCompact
Unfortunately, you cannot control 'Remove deleted items data after' box with the cmdlets.
Also, looks like -RetainDays parameter (deleted items retention) for Set-VBRJobAdvancedOptions cmdlet didn't work for me, so here is a quick workaround to manage both of the options:

Code: Select all

$job = Get-VBRJob -Name 'Backup Copy Job 1'
$options = Get-VBRJobOptions -Job $job
$options.GenerationPolicy.EnableDeletedVMDataRetention = $true
$options.GenerationPolicy.DeletedVMsDataRetentionPeriodDays = 30
Set-VBRJobOptions -Job $job -Options $options
Hope it helps,
Oleg
HothLord88
Lurker
Posts: 2
Liked: never
Joined: Oct 05, 2022 12:53 pm
Full Name: Sam Rosenberg
Contact:

Re: Powershell to set Storage level corruption guard and File backup maintenance

Post by HothLord88 »

Oleg,

Thank you so much! I will try this out today.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests