Use PowerShell to Create a Scheduled Task that Uses PowerShell to Pause and Resume AppAssure Core Replication
In this scenario there are multiple AppAssure Core servers, one at each physical location that is used to backup the local servers. Each AppAssure Core server is setup to replicate its data to an offsite AppAssure Core server at a separate physical location across a wide area network for disaster recovery purposes. Due to bandwidth constraints, you want to pause the replication between the AppAssure Core servers during normal business hours.
All of the AppAssure Core servers in this scenario are running Windows Server 2008 R2, they all have PowerShell version 3 installed, PowerShell remoting enabled, and AppAssure 5.3.1 or higher installed.
First, we'll create a PSSession to the remote AppAssure Core server that we want to create the scheduled tasks on so we don't have the overhead of setting up and tearing down multiple remote PowerShell sessions to the same server:
1$session = New-PSSession -ComputerName AppAssureCoreServerName -Credential (Get-Credential)
I've specified the Credential
parameter and used the Get-Credential
cmdlet so this script will
prompt me for credentials since I'm running PowerShell as a user that doesn't have access to the
remote AppAssure Core server. These are the credentials that our scripts will run as in this
scenario:
This script will create a scheduled task that will run at 7:30am seven days a week. The scheduled
task runs a PowerShell command which pauses the AppAssure replication from the server it is run on
to the one that is specified via the Outgoing
parameter of the Suspend-Replication
cmdlet. The
credentials it is prompting us for are the credentials the scheduled task will run as (they will be
saved as part of the scheduled task):
1Invoke-Command -Session $session {
2 Register-ScheduledJob -Name 'AppAssure - Pause Replication' -Credential (Get-Credential) -ScriptBlock {
3 Suspend-Replication -Outgoing AppAssureCoreServerNameReplicatedTo
4} -Trigger (New-JobTrigger -Daily -At "7:30 AM") -ScheduledJobOption (New-ScheduledJobOption -RunElevated)}
Similar to the above script, the following PowerShell script creates a scheduled task on the
AppAssure Core server that we created the PSSession to in the first command. The scheduled task runs
at 6:30pm seven days a week. This scheduled task runs a PowerShell cmdlet (Resume-Replication
)
which resumes the AppAssure replication to the server that is specified in the Outgoing
parameter.
1Invoke-Command -Session $session {
2 Register-ScheduledJob -Name 'AppAssure - Resume Replication' -Credential (Get-Credential) -ScriptBlock {
3 Resume-Replication -Outgoing AppAssureCoreServerNameReplicatedTo
4} -Trigger (New-JobTrigger -Daily -At "6:30 PM") -ScheduledJobOption (New-ScheduledJobOption -RunElevated)}
When you're finished, don't forget about removing the PSSession. The following command will remove all PSSessions:
You can see the scheduled tasks on the AppAssure Core server that the scripts shown in the previous examples were run against:
By having the scheduled task execute the PowerShell cmdlet directly, the dependency of an external script that could get accidentally moved or modified is eliminated.
µ