Scripting examples > Job control scripts > Changing the compression setting for an existing job

Changing the compression setting for an existing job

The following sample script will change the compression setting for an existing job. 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 change the compression settings for an existing 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"

 

# 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

 

# Enable compression using one of the following combinations

# level = -1 Compression is disabled

# level = 0 and algorithm = 10 Compression is enabled at low level

# level = 1 and algorithm = 21 Compression is enabled at medium level

# level = 2 and algorithm = 31 Compression is enabled at high level

$DtJob.Options.CoreConnectionOptions.ConnectionStartParameters.CompressionLevel.Level=1

$DtJob.Options.CoreConnectionOptions.ConnectionStartParameters.CompressionLevel.Algorithm=21

 

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

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

$DtJob.Options.Workload=$DtWorkload

 

# 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 activity completion status is not InProgress, the confirmation is complete.

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

 

# If the completion status 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.