Scripting examples > Job creation scripts > Creating a full server to ESX job for Linux

Creating a full server to ESX job for Linux

The following sample script will create a simple full server to ESX job for Linux. 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 full server to ESX appliance job

 

# Specify the variables to be used in the script

 

     # Source server and credentials

     # Be sure to include the communication port with the source server

     $DtSourceName = "112.42.7.63:6325"

     $DtSourceUserName = "root"

     $DtSourcePassword = "password"

 

     # Target appliance and credentials

     # Be sure to include the communication port with the target

     $DtTargetName = "112.42.9.93:6325"

     $DtTargetUserName = "root"

     $DtTargetPassword = "password"

 

     # ESX host and credentials

     # If you are using vCenter, specify your vCenter.

     # Only specify an ESX host if you are using ESX standalone.

     $DtHostName = "112.42.56.14"

     $DtHostUserName = "root"

     $DtHostPassword = "password"

 

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

     $DtWorkloadType = "Lvra"

     $DtJobType = "Lvra"

 

     # VM display name

     # This name must be unique within your environment and different

     # from the existing directory location name if you are reusing an existing disk

     $DisplayName = "Name"

 

     # Datastore location - GUID assigned to the datastore

     # You can find this GUID in your vSphere or VMware web client

     $DatastoreLocation = "/vmfs/volumes/529a027d-b4ba1124-b1c0-614c42bc0717"

 

     # Existing disk - Specify only if you want to reuse an existing disk

     # If your disks are mounted directly (without using LVM2), specify the mount name and location

     # If your disks are in an LVM2 volume group, specify the LVM name and location

     # If you are using both, specify both

     $MountName = "/boot"

     $MountLocation = "Dir1/DiskName__boot.vmdk"

     $LvmName1 = "VG_Name"

     $LvmLocation1 = "Dir1/DiskName_VG_Name_PhysicalVolume0.vmdk"

     $LvmName2 = "VG_Name"

     $LvmLocation2 = "Dir1/DiskName_VG_Name_PhysicalVolume1.vmdk"

 

# 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 ESX host appliance object

# If you are using vCenter, specify your vCenter.

# Only specify an ESX host if you are using ESX standalone.

$VimTarget = New-DtServer -Name $DtHostName -Username $DtHostUserName -Password $DtHostPassword -Role TargetVimServer

$OtherServers = @($VimTarget)

 

# Create a workload

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

 

# Determine what you want to protect

# Get the logical items associated with the workload

$DtLogicalItems = Get-DtLogicalItem -ServiceHost $DtSource -WorkloadId $DtWorkloadGUID

# Add each logical item available on the server, for example, each volume on the server

$DtProtectionItem = @()

foreach ($item in $DtLogicalItems)

     {

          $DtProtectionItem += Set-DtLogicalItemSelection -ServiceHost $DtSource -WorkloadId $DtWorkloadGuid -LogicalPath $item.Path

     }

# Get the workload definition including the workload and logical items

$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 -OtherServers $OtherServers -JobType $DtJobType -Workload $DtWorkload

 

# Set the display name

$DtJobOptions.JobOptions.VraOptions.ReplicaVmInfo.DisplayName = $DisplayName

 

# Set the location where you want the VM config files to be located

$DtJobOptions.JobOptions.VRAOptions.ReplicaVMInfo.Path = $DatastoreLocation

 

# Uncomment and use the following block only if you want to reuse an existing disk

# Specify the existing disk to use

<#

     $ExistingDisks = @()

     $ExistingDisksDatastoreLocation = $ReplicaVmDatastoreLocation

     $ExistingDisks += @{ mountPoint = $MountName; dsLoc = $ExistingDisksDatastoreLocation; vmdkPath = $MountLocation }

     $ExistingDisks += @{ vgName = $LvmName1; dsLoc = $ExistingDisksDatastoreLocation; vmdkPath = $LvmLocation1 }

     $ExistingDisks += @{ vgName = $LvmName2; dsLoc = $ExistingDisksDatastoreLocation; vmdkPath = $LvmLocation2 }

 

     $modifiedVolumeGroups = @{}

     foreach($existingDisk in $ExistingDisks)

     {

          if ($existingDisk.ContainsKey("mountPoint"))

          {

               $mntpt = $existingDisk["mountPoint"]

               if ($mntpt)

               {

                    foreach($mountedPartition in $DtJobOptions.JobOptions.VRAOptions.Volumes)

                    {

                         if ($mntpt -eq $mountedPartition.Name)

                        {

                              $mountedPartition.VirtualDiskPath = $existingDisk["dsLoc"]

                              $mountedPartition.PreexistingDiskPath = $existingDisk["vmdkPath"]

                              break

                         }

                    }     

               }

          }

          elseif ($existingDisk.ContainsKey("vgName"))

          {

               # Find the matching VolumeGroup object, clearing any PhysicalVolume instances defined

               # by Get-DtRecommendedJobOptions

               $vgName = $existingDisk["vgName"]

               $matchingVG = $null

               if ($modifiedVolumeGroups.ContainsKey($vgName))

               {

                    $matchingVG = $modifiedVolumeGroups[$vgName]

               }

               else

               {

                   foreach ($vg in $DtJobOptions.JobOptions.VRAOptions.LvmOptions.VolumeGroup)

                    {

                         if ($vg.Name -eq $vgName)

                         {

                              $matchingVG = $vg

                              $matchingVG.PhysicalVolume = @()

                              $modifiedVolumeGroups[$vgName] = $matchingVG

                              break

                         }

                    }

               }

               # Add this existing disk to the VolumeGroup as a PhysicalVolume

               if ($matchingVG)

               {

                    $newPV = New-Object -TypeName DoubleTake.Core.Contract.UVRA.PhysicalVolume

                    $newPV.VirtualDiskPath = $existingDisk["dsLoc"]

                    $newPV.PreexistingDiskPath = $existingDisk["vmdkPath"]

                    $matchingVG.PhysicalVolume += $newPV

               }

               else

               {

                    Write-Error "Volume Groups not found for " + $matchingVG

               }

          }

     }

#>

 

# Create the job

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

 

# Start the job

Start-DtJob -ServiceHost $DtTarget -JobId $DtJobGuidForLVRA

 

# Close the connections for the server objects

Disconnect-DtServer -ServiceHost $DtSource

Disconnect-DtServer -ServiceHost $DtTarget

Disconnect-DtServer -ServiceHost $VimTarget

 

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.