PowerShell script exchange
Post Reply
manuel.aigner
Enthusiast
Posts: 37
Liked: 6 times
Joined: Sep 25, 2017 8:25 am
Full Name: Manuel Aigner
Contact:

Add pre-freeze/post-thaw script for Win PG in Appaware settings

Post by manuel.aigner »

Hi there,

I'm struggling with adding Pre/Post freeze scripts to a Windows Agent Protection Group in app aware settings of a Windows Agent Job.
All ideas Veeam AI delivers to me are not functional.

Code: Select all

# Define the name of the backup job and the pre-freeze script path
$jobName = "Windows Agent Backup Job"
$preFreezeScriptPath = "C:\Scripts\PreFreezeScript.ps1"

# Get the backup job
$job = Get-VBRComputerBackupJob -Name $jobName

# Get the protection group
$protectionGroup = Get-VBRProtectionGroup -Name "Windows Servers"

# Get the application aware settings
$appAwareSettings = $protectionGroup.Options.ApplicationAwareProcessing

# Define the pre-freeze script
$appAwareSettings.PreFreezeScript = $preFreezeScriptPath

# Apply the updated settings to the protection group
Set-VBRProtectionGroupOptions -ProtectionGroup $protectionGroup -Options $protectionGroup.Options

Write-Output "Pre-Freeze Script has been defined for the protection group: Windows Servers"
In this example:
$protectionGroup.Options.ApplicationAwareProcessing is not a valid sub property

I got lot of these, where either invalid sub properties are used, or incompatible cmdlets where chained.


My latest personal approach was this here

Code: Select all

	# Setting Pre/Post Scripts in Backup Job
	$paramNewVBRScriptProcessingOptions = @{
		ScriptPrefreezeCommand = "D:\VeeamScripts\preFreeze.bat"
		ScriptPostthawCommand  = "D:\VeeamScripts\postFreeze.bat"
		ProcessingAction	   = 'IgnoreFailures'
	}
	
	$ErrorObject | Add-Member -Force -NotePropertyName paramNewVBRScriptProcessingOptions -NotePropertyValue $paramNewVBRScriptProcessingOptions
	$scriptOptions = New-VBRScriptProcessingOptions @paramNewVBRScriptProcessingOptions
	#	$JobOptions = Set-VBRApplicationProcessingOptions -ScriptProcessingOptions $scriptOptions
	#$pgInJob = Get-VBRJobObject -Job $job #| Where-Object { $_.Name -eq $ProtectionGroupParams['Name'] }
	$pgInJob = Get-VBRProtectionGroup -Name $ProtectionGroupParams['Name'] 
	$ProcessOptions = New-VBRApplicationProcessingOptions -BackupObject $pgInJob -Enable -ScriptProcessingOptions $scriptOptions -OSPlatform Windows -GeneralTransactionLogAction ProcessLogsWithJob
	$null = Set-VBRApplicationProcessingOptions -Options $ProcessOptions -Enable -GeneralTransactionLogAction ProcessLogsWithJob
	$AllRes += Write-CSDLog -LogText "$($MyInvocation.MyCommand)~Created Pre/Post Script object" -Severity I -Object $TemplateJob
	
	$null = Enable-VBRComputerBackupJob -Job $job
	$AllRes += Write-CSDLog -LogText "$($MyInvocation.MyCommand)~Job enabled" -Severity I -Object $TemplateJob

This one doesn't thow any errors. But my desired settings are also not set.
Any ideas what I'm doing wrong?
david.domask
Veeam Software
Posts: 2838
Liked: 648 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Add pre-freeze/post-thaw script for Win PG in Appaware settings

Post by david.domask » 1 person likes this post

Hi Manuel,

Sure, this should be all you need to configure pre-freeze and post-thaw scripts for Veeam Agent for Windows job:

Code: Select all

$newScriptOpts = @{
	ScriptPrefreezeCommand = "D:\VeeamScripts\preFreeze.bat"
	ScriptPostthawCommand  = "D:\VeeamScripts\postFreeze.bat"
	ProcessingAction	   = "IgnoreFailures"
}

$pgJob = Get-VBRComputerBackupJob -Name "dd-vaw-ps-test" #replace with your own or write logic to find correct job
$protGroup = Get-VBRProtectionGroup -Name "dd-win-pg" #replace with correct protection group or write logic to find correct PG - you can pass individual computers too
$scriptOpts = New-VBRScriptProcessingOptions @newScriptOpts
$appProcOpts = New-VBRApplicationProcessingOptions -BackupObject $protGroup  -Enable -ScriptProcessingOptions $scriptOpts -OSPlatform Windows -GeneralTransactionLogAction ProcessLogsWithJob
Set-VBRComputerBackupJob -Job $pgJob -ApplicationProcessingOptions $appProcOpts
The general workflow is as above, though likely you will want to customize it so you don't have to manually enter a Protection Group and Job name manually each time. Please note that this will only work for NON-WORKSTATION jobs; if you process the protection group as workstations, you will need to configure the application settings in the UI.
David Domask | Product Management: Principal Analyst
manuel.aigner
Enthusiast
Posts: 37
Liked: 6 times
Joined: Sep 25, 2017 8:25 am
Full Name: Manuel Aigner
Contact:

Re: Add pre-freeze/post-thaw script for Win PG in Appaware settings

Post by manuel.aigner » 1 person likes this post

Hi David,
thanks for your quick response. That works for me :)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests