Example: Scripting Migration Plans

Note: This topic includes a sample script you can use as the basis for scripting a multi-plan migration that satisfies your needs and environment. This script is intended to be used as a sample only, and not to be run as-is. For detailed instructions on using the console runner, see Using the Tableau Content Migration Tool Console Runner.

Tableau Content Migration Tool command line utility for running migrations can be used to automate the running of a migration plan from an external scheduler (such as Windows Task Scheduler) or from a custom script. The console runner only runs one migration plan (stored in a .edt file) at a time. If you have a group of migration plans you want to run as a group, then you can use a custom script in combination with the Content Migration Tool console runner.

The example below is written in PowerShell and uses the console runner to execute a list of migration plans as a group.

The following example code demonstrates:

  • Running multiple migration plans as a group using the console runner.
  • Optionally halting deployment of the group of plans immediately when any single migration in the group fails.
  • Using the console runner’s exit code to determine whether the migration failed or logged warnings.

 

# List of migration plans to execute as a group.
$planFiles = @(
	'customer 1.tcmx',
	'customer 2.tcmx'
)

# True of false whether to continue with the next plan if a migration fails.
$continueOnFailure = $false
			
# Path to the CMT console runner executable
$runnerExe = 'C:\Program Files (x86)\Tableau\Tableau Content Migration Tool\tabcmt-runner.exe'

# Store the exit code from the previously run migration plan.
$lastResult = -1
			
# Loop through and run each migration plan one at a time.
$planFiles | % {
	$file = $_
			
	if ($lastResult -ge 2 -and -not($continueOnFailure)) {
		Write-Warning "Skipping plan because previous migration failed. `nSkipped plan: $file"
		return
	}
			
	Write-Verbose "Running migration plan: $file"
	& $runnerExe $file
       $lastResult = $LASTEXITCODE
 
 	if ($lastResult -ge 2) {
		Write-Error "Migration failed. See output or log file for error details.`nPlan: $file" -ErrorAction 'Continue'
	}
	elseif ($lastResult -eq 1) {
		Write-Warning "Migration completed with warnings. See output or log file for warning details.`nPlan: $file"
	}
}

Who can do this

To script migration plans, you must have all the following:

  • Administrator permissions on the Content Migration Tool machine.
  • Tableau site user account with an Explorer role or higher.
  • View and Download Workbook/Save a Copy permissions on the source site.
  • Publishing rights for the destination site.
Thanks for your feedback!Your feedback has been successfully submitted. Thank you!