---
schema_version: "1"
id: 6350de47abf81345db7806cdb620b09513b778ef6f8cb8b10c8ff35d2dc2f26e
title: 示例：编写迁移计划脚本
collection: tableau
version: next
locale: zh-cn
portal_url: https://docs.salesforce.com/tableau/next/zh-cn/server-linux/cmt-scripting_migration_example.md
canonical_url: https://help.tableau.com/v0.0/server-linux/zh-cn/cmt-scripting_migration_example.htm
source_site: help.tableau.com
content_type: documentation
content_hash: ee42b9dc60f7511d6cefdf3e8b779c7394432a29af79d8708e800b9dd4e5c424
description: Sample script for scripting a multi-plan migration with the Content Migration Tool console runner.
---
[跳转到主要内容](#main-content)

# 示例：编写迁移计划脚本

**注意：**本主题包括一个示例脚本，您可以以其为基础来编写可满足您的需求和环境要求的多计划迁移脚本。此脚本仅用作示例，而不是按原样运行。有关运行控制台运行程序的详细说明，请参见[使用 Tableau Content Migration Tool 控制台运行程序](https://help.tableau.com/v0.0/server-linux/zh-cn/cmt-deployment_console_runner.htm)。

可以使用用于运行迁移的 Tableau Content Migration Tool 命令行实用工具，通过外部计划程序（例如 Windows 任务计划程序）或自定义脚本来自动运行迁移计划。控制台运行程序一次仅运行一个迁移计划（存储在 .edt 文件中）。如果有一组要成组运行的迁移计划，则可以将自定义脚本与 Content Migration Tool 控制台运行程序结合使用。

下面的示例使用 PowerShell 编写，并使用控制台运行程序来成组执行一系列迁移计划。

下面的示例代码演示了：

- 使用控制台运行程序成组运行多个迁移计划。
- 根据需要在组中的任何单个迁移失败时立即停止部署一组计划。
- 使用控制台运行程序的退出代码确定迁移是否失败或记录了警告。

\# 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"
	}
}

## 谁可以执行此操作

为了编写迁移计划脚本，您必须具有以下所有各项：

- Content Migration Tool 计算机上的管理员权限。
- 具有 Explorer 角色或更高级别角色的 Tableau 站点用户帐户。
- 源站点上的“查看和下载工作簿”/“保存副本”权限。
- 目标站点的“发布”权限。