Scripting examples > Job control scripts > Editing a files and folders job for Windows

Editing a files and folders job for Windows

The following sample script will edit an existing files and folders job for Windows. You will need to modify this script to fit your environment and configuration.

Be sure and expand your screen wide enough so that lines in the script file do not wrap.

 

# Sample script to edit an existing files and folders Double-Take job

 

# Specify the variables to be used in the script

 

     # Source server and credentials

     $DtSourceName = "alpha"

     $DtSourceUserName = "domain\administrator"

     $DtSourcePassword = "password"

 

     # Target server and credentials

     $DtTargetName = "beta"

     $DtTargetUserName = "domain\administrator"

     $DtTargetPassword = "password"

 

     # Changes to the job

     $DtJobDirectory = "C:\NewDirectory"

     $DtJobFileToExclude = "C:\NewDirectory\*.txt"

 

# Import the Double-Take PowerShell module

# This may be \Service\ or \Console\ depending on your installation

Import-Module "C:\Program Files\Vision Solutions\Double-Take\Console\DoubleTake.PowerShell.dll"

 

# Create source and target objects

$DtSource = New-DtServer -Name $DtSourceName -UserName $DtSourceUserName -Password $DtSourcePassword

$DtTarget = New-DtServer -Name $DtTargetName -UserName $DtTargetUserName -Password $DtTargetPassword

 

# Identify the job, based on the source server name

$DtJob = Get-DtJob -ServiceHost $DtTarget | Where-Object { $_.Statistics.CoreConnectionDetails.SourceMachineName -eq $DtSourceName}

 

# Create a workload object on the source to edit the current workload rules

$DtWorkloadGUID = New-DtWorkload -ServiceHost $DtSource -Workload $DtJob.Options.Workload

 

# Specify the additional files and folders to protect

$DtNewRule = Add-DtPhysicalRule -ServiceHost $DtSource -WorkloadId $DtWorkloadGuid -Path $DtJobDirectory

 

# Specify files to exclude from protection, in this example .txt files in the new protection rule

$DtExcludeTxtRule = Add-DtPhysicalRule -ServiceHost $DtSource -WorkloadId $DtWorkloadGuid -Path $DtJobFileToExclude -Exclude

 

# Update the workload rules in the job options with the new modifications

$DtWorkload = Get-DtWorkload -ServiceHost $DtSource -WorkloadId $DtWorkloadGuid

$DtJob.Options.Workload=$DtWorkload

 

# Update the path mapping of the replicated data on the target based on the current recommendations

$DtTargetPath = Get-DtRecommendedPathTransform -ServiceHost $DtSource -WorkloadId $DtWorkloadGuid

$DtJob.Options.CoreConnectionOptions.PathTransformations = $DtTargetPath

 

# If you do not want to use the one-to-one path mapping in the default recommended options,

# you can configure the job to use specific locations, similar to the following lines.

# $DtJob.Options.CoreConnectionOptions.PathTransformations[0].SourcePath = "C:\"

# $DtJob.Options.CoreConnectionOptions.PathTransformations[0].TargetPath = "C:\ReplicatedData\"

 

# Verify the new job options on the existing job.

$DtConfirmation = Confirm-DtJobOptions -ServiceHost $DtTarget -JobId $DtJob.Id -JobOptions $DtJob.Options

do

{

          # Poll every second for the confirmation status

          Start-Sleep -Seconds 1

          $DtConfirmStatus = Get-DtVerificationStatus -ServiceHost $DtTarget -Token $DtConfirmation

          # When the ActivityCompletionStatus is not InProgress, the confirmation is complete.

}

while ($DtConfirmStatus.Steps.Status -eq 0)

 

# If the ActivityCompletionStatus is Error, print out the steps reporting an Error.

if ($DtConfirmStatus.Steps.Status -eq 3)

{

          Write-Error "The following job validation errors were detected:"

          $DtConfirmStatus.Steps | ForEach-Object

          {

                    if ($_.Status -eq 3)

                    {

                              Write-Error "$($_.Id) : $($_.TitleKey) : $($_.MessageKey)"

                    }

          }

          # Terminate so the job is not edited with invalid options

          throw "Job validation failure."

}

 

# Apply new job options with the updated workload rules, forcing a remirror.

Edit-DtJob -ServiceHost $DtTarget -JobId $DtJob.Id -JobOptions $DtJob.Options

 

# Close the connections for the server objects

Disconnect-DtServer -ServiceHost $DtSource

Disconnect-DtServer -ServiceHost $DtTarget

 

If you want to hide your user credentials in your script, use the Windows PowerShell Get-Credential cmdlet. The password will not be visible because Windows stores an encrypted password. See Hiding your password in a PowerShell script for basic details on using this cmdlet. See your Windows PowerShell documentation for detailed instructions.