Scripting examples > Job creation scripts > Creating a files and folders migration job for Windows

Creating a files and folders migration job for Windows

The following sample script will create a simple files and folders migration 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 create a simple data migration 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"

 

     # Type of workload you will be migrating and type of job you will be creating

     $DtWorkloadType = "MoveDataOnlyMigration"

     $DtJobType = "MoveDataOnlyMigration"

 

     # Paths on the source to migrate

     $DtSourceMigrationPath1 = "C:\Dir1\"

     $DtSourceMigrationPath2 = "C:\Dir2\"

 

     # Path mapping that will be used when the job is created

     $DtSourcePath = "C:\"

     $DtTargetPath = "C:\Dir3\"

 

# 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

 

# Create a workload

$DtWorkloadGUID = New-DtWorkload -ServiceHost $DtSource -WorkloadTypeName $DtWorkloadType

 

# Specify the files and folders to migrate

$DtMigrationPath1 = New-Object DoubleTake.Common.Contract.PhysicalRule -Property @{Path=$DtSourceMigrationPath1}

$DtMigrationRule1 = Add-DtPhysicalRule -ServiceHost $DtSource -WorkloadId $DtWorkloadGuid -Rule $DtMigrationPath1

$DtMigrationPath2 = New-Object DoubleTake.Common.Contract.PhysicalRule -Property @{Path=$DtSourceMigrationPath2}

$DtMigrationRule2 = Add-DtPhysicalRule -ServiceHost $DtSource -WorkloadId $DtWorkloadGuid -Rule $DtMigrationPath2

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

 

# Get the default job options that will be used to create the job

$DtJobOptions = Get-DtRecommendedJobOptions -ServiceHost $DtTarget -Source $DtSource -JobType $DtJobType -Workload $DtWorkload

 

# Sets the path mapping on the target to an all-to-one location

$DtJobOptions.JobOptions.CoreConnectionOptions.PathTransformations[0].SourcePath = $DtSourcePath

$DtJobOptions.JobOptions.CoreConnectionOptions.PathTransformations[0].TargetPath = $DtTargetPath

 

# Create the job

$DtJobGuidForDataMigration = New-DtJob -ServiceHost $DtTarget -Source $DtSource -JobType $DtJobType -JobOptions $DtJobOptions.JobOptions

 

# Start the job

Start-DtJob -ServiceHost $DtTarget -JobId $DtJobGuidForDataMigration

 

# 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.