The following tool can be used to synchronize cron
schedules from one Clustered Data ONTAP cluster to another (even if they are on a different ONTAP version.)
The tool can be run in a variety of ways. The example
below is run from simply double clicking a BAT file - no prompts need to be
answered:
Image: Example
running Sync-Cron.ps1 using a BAT file
The Script -
Sync-Cron.ps1
##
To run in a BAT file (switches optional):
#
Powershell.exe .\Sync-Cron.ps1
##
To create $SecurePasswordString run:
#
PS> (Read-Host -AsSecureString) | ConvertFrom-SecureString
#
N.B. This string only works when logged in as the same Windows user that
created it.
Param([String]$ClusterUser,[String]$PrimaryCluster,[String]$SecondaryCluster,[String]$SecurePasswordString,[Switch]$SkipPressEnter)
If($SecurePasswordString){
$Password = $SecurePasswordString | ConvertTo-SecureString }
FUNCTION
Wr { Param([String]$ToDisplay,[String]$Color = "WHITE")
IF($ToDisplay){ Write-Host $ToDisplay
-ForegroundColor $Color -NoNewLine } ELSE { Write-Host } }
Wr
"+++++ Cron Schedule Cluster to Cluster Synchronizer +++++" MAGENTA;
Wr; Wr
Wr
"Cluster Login User : "
CYAN; If($ClusterUser){ Wr $ClusterUser; Wr }else{ $ClusterUser = Read-Host }
Wr
"Cluster Login Password : " CYAN; If($Password){ Wr
"*****"; Wr }else{ $Password = Read-Host -AsSecureString }
Wr
"Cluster - Primary : "
CYAN; If($PrimaryCluster){ Wr $PrimaryCluster; Wr }else{ $PrimaryCluster =
Read-Host }
Wr
"Cluster - Secondary : "
CYAN; If($SecondaryCluster){ Wr $SecondaryCluster; Wr }else{ $SecondaryCluster
= Read-Host }; Wr
$Credential
= New-Object System.Management.Automation.PsCredential($ClusterUser,$Password)
FUNCTION
PressEnterToContinue{ If(!$SkipPressEnter){ Wr "Press to
exit ..." CYAN; Read-Host }; EXIT }
FUNCTION
Load-DataOntapPSTK {
If(Get-Module DataONTAP){ RETURN }
[Void](Import-Module DataONTAP -ErrorAction
SilentlyContinue)
If(!(Get-Module DataONTAP)){ Wr "Unable
to load the DataONTAP PowerShell Toolkit - exiting!" RED; Wr; Wr;
PressEnterToContinue }
Wr "Loaded the Data ONTAP PowerShell
Toolkit!" GREEN; Wr; Wr }
FUNCTION
Connect-ToCluster {
Param([String]$ClusterName)
$Connect = Connect-NcController -Name
$ClusterName -Credential $Credential -ErrorAction SilentlyContinue
If(!$Connect){ Wr "Unable to connect to
$ClusterName!" RED; Wr; Wr; PressEnterToContinue }
Wr "Connected to $ClusterName"
GREEN; Wr; Wr }
[Void](Load-DataOntapPSTK)
[Void](Connect-ToCluster
$PrimaryCluster)
$SourceCronJobs
= Get-NcJobCronSchedule;
Wr
"++ Collected cron jobs from $PrimaryCluster ++"; Wr; Wr
[Void](Connect-ToCluster
$SecondaryCluster)
$SourceCronJobs
| foreach { $_.NcController = $null; [Void]( $_ | Add-NcJobCronSchedule
-ErrorAction SilentlyContinue ) }
$SourceCronJobs
| foreach { $_.NcController = $null; [Void]( $_ | Set-NcJobCronSchedule -ErrorAction
SilentlyContinue ) }
Wr
"++ Applied cron jobs to $SecondaryCluster ++"; Wr; Wr
PressEnterToContinue
Comments
Post a Comment