通过使用检查点重新启动包Restart Packages by Using Checkpoints

适用对象:是SQL Server,包含 Linux 版 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server, including on Linux yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

Integration ServicesIntegration Services 可以从失败点重新启动失败的包,而不是重新运行整个包。can restart failed packages from the point of failure, instead of rerunning the whole package. 如果包配置为使用检查点,则关于包执行的信息会写入检查点文件中。If a package is configured to use checkpoints, information about package execution is written to a checkpoint file. 当重新运行失败的包时,可以使用检查点文件从失败点重新启动该包。When the failed package is rerun, the checkpoint file is used to restart the package from the point of failure. 如果包成功运行,则会删除该检查点文件,然后在下次运行包时会重新创建相应的检查点文件。If the package runs successfully, the checkpoint file is deleted, and then re-created the next time the package is run.

在包中使用检查点可以提供下列好处:Using checkpoints in a package can provide the following benefits.

  • 避免重复下载和上载大型文件。Avoid repeating the downloading and uploading of large files. 例如,对于每次下载都使用 FTP 任务下载多个大型文件的包,如果下载单个文件失败,则可以重新启动该包,只下载该失败的文件。For example, a package that downloads multiple large files by using an FTP task for each download can be restarted after the downloading of a single file fails and then download only that file.

  • 避免重复加载大量数据。Avoid repeating the loading of large amounts of data. 例如,对于为每个维度使用不同的大容量插入任务向数据仓库中的维度表执行大容量插入的包,如果某一维度表的插入失败,则可以重新启动该包,只重新加载该失败的维度。For example, a package that performs bulk inserts into dimension tables in a data warehouse using a different Bulk Insert task for each dimension can be restarted if the insertion fails for one dimension table, and only that dimension will be reloaded.

  • 避免重复聚合值。Avoid repeating the aggregation of values. 例如,如果包需要计算多个聚合,例如求平均值和求和,而且使用不同的数据流任务执行每个聚合,则在计算一个聚合失败时,可以重新启动该包,只重新计算该失败的聚合。For example, a package that computes many aggregates, such as averages and sums, using a separate Data Flow task to perform each aggregation, can be restarted after computing an aggregation fails and only that aggregation will be recomputed.

如果包配置为使用检查点, Integration ServicesIntegration Services 将捕获检查点文件中的重新启动点。If a package is configured to use checkpoints, Integration ServicesIntegration Services captures the restart point in the checkpoint file. 失败的容器类型以及功能(例如事务)的实现都会影响在检查点文件中所记录的重新启动点。The type of container that fails and the implementation of features such as transactions affect the restart point that is recorded in the checkpoint file. 检查点文件中还捕获变量的当前值。The current values of variables are also captured in the checkpoint file. 但是,数据类型为 Object 的变量的值不保存在检查点文件中。However, the values of variables that have the Object data type are not saved in checkpoint files.

定义重新启动点Defining Restart Points

封装单个任务的任务宿主容器是可以重新启动的最小原子工作单元。The task host container, which encapsulates a single task, is the smallest atomic unit of work that can be restarted. Foreach 循环容器和事务处理容器也被视为原子工作单元。The Foreach Loop container and a transacted container are also treated as atomic units of work.

如果在事务处理容器运行时停止某个包,则该事务将会结束,并且将回滚该容器执行的所有工作。If a package is stopped while a transacted container is running, the transaction ends and any work performed by the container is rolled back. 当重新启动该包时,会重新运行失败的容器。When the package is restarted, the container that failed is rerun. 检查点文件中不记录事务处理容器的任何子容器的完成情况。The completion of any child containers of transacted container is not recorded in the checkpoint file. 因此,当重新启动包时,会再次运行事务处理容器及其子容器。Therefore, when the package is restarted, the transacted container and its child containers run again.

备注

在同一个包中使用检查点和事务可能会导致意外的结果。Using checkpoints and transactions in the same package could cause unexpected results. 例如,当包失败并从某个检查点重新启动时,该包可能会重复已成功提交的事务。For example, when a package fails and restarts from a checkpoint, the package might repeat a transaction that has already been successfully committed.

不为 For 循环和 Foreach 循环容器保存检查点数据。Checkpoint data is not saved for For Loop and Foreach Loop containers. 当重新启动包时,会再次运行 For 循环和 Foreach 循环容器及其子容器。When a package is restarted, the For Loop and Foreach Loop containers and the child containers are run again. 如果循环中的子容器已成功运行,则不会将其记录在检查点文件中,而是重新运行子容器。If a child container in the loop runs successfully, it is not recorded in the checkpoint file, instead it is rerun. 有关解决方法的详细信息,请参阅 不为 For 循环和 Foreach 循环容器项采用 SSIS 检查点For more information and a workaround, see SSIS Checkpoints are not honored for For Loop or Foreach Loop container items.

在重新启动包时,不会重新加载包配置,包使用写入检查点文件中的配置信息。If the package is restarted the package configurations are not reloaded, instead the package uses the configuration information written to the checkpoint file. 这就确保包在重新运行时使用的是与失败时相同的配置。This ensures that the package uses the same configurations when it is rerun as the time it failed.

包只能在控制流级重新启动。A package can be restarted only at the control flow level. 您无法重新启动处于数据流中间的包。You cannot restart a package in the middle of a data flow. 为了避免重新运行整个数据流,可以将包设计为包括多个数据流,每个数据流使用不同的数据流任务。To avoid rerunning the whole data flow, the package might be designed to include multiple data flows, each one using a different Data Flow task. 这样,在重新启动包时,将只需重新运行一个数据流任务。This way the package can be restarted, rerunning only one Data Flow task.

将包配置为重新启动Configuring a Package to Restart

检查点文件包括所有已完成的容器的执行结果、系统变量和用户定义的变量的当前值以及包配置信息。The checkpoint file includes the execution results of all completed containers, the current values of system and user-defined variables, and package configuration information. 该文件还包括包的唯一标识符。The file also includes the unique identifier of the package. 若要成功重新启动包,检查点文件中的包标识符和包必须匹配,否则重新启动将失败。To successfully restart a package, the package identifier in the checkpoint file and the package must match; otherwise the restart fails. 这样可以防止包使用其他包版本所写的检查点文件。This prevents a package from using a checkpoint file written by a different package version. 如果包成功运行,则在包重新启动后,将会删除该检查点文件。If the package runs successfully, after it is restarted the checkpoint file is deleted.

下表列出了可设置为实现检查点的包属性。The following table lists the package properties that you set to implement checkpoints.

属性Property 描述Description
CheckpointFileNameCheckpointFileName 指定检查点文件的名称。Specifies the name of the checkpoint file.
CheckpointUsageCheckpointUsage 指定是否使用检查点。Specifies whether checkpoints are used.
SaveCheckpointsSaveCheckpoints 指示包是否保存检查点。Indicates whether the package saves checkpoints. 此属性必须设置为 True,才能从失败点重新启动包。This property must be set to True to restart a package from a point of failure.

另外,对于包中要标识为重新启动点的所有容器,必须将 FailPackageOnFailure 属性设置为 trueAdditionally, you must set the FailPackageOnFailure property to true for all the containers in the package that you want to identify as restart points.

可以使用 ForceExecutionResult 属性测试包中检查点的使用情况。You can use the ForceExecutionResult property to test the use of checkpoints in a package. 通过将容器或任务的 ForceExecutionResult 设置为 Failure,可以模拟实时的失败。By setting ForceExecutionResult of a task or container to Failure, you can imitate real-time failure. 当重新运行包时,将重新运行失败的任务和容器。When you rerun the package, the failed task and containers will be rerun.

检查点用法Checkpoint Usage

CheckpointUsage 属性可设置为下列值:The CheckpointUsage property can be set to the following values:

ReplTest1Value 描述Description
从不Never 指定不使用检查点文件,包从包工作流的起点开始运行。Specifies that the checkpoint file is not used and that the package runs from the start of the package workflow.
始终Always 指定始终使用检查点文件,包从上一次执行失败的点重新启动。Specifies that the checkpoint file is always used and that the package restarts from the point of the previous execution failure. 如果找不到检查点文件,则包失败。If the checkpoint file is not found, the package fails.
IfExistsIfExists 指定如果存在检查点文件则使用该文件。Specifies that the checkpoint file is used if it exists. 如果检查点文件存在,则包从上一次执行失败的点重新启动;如果检查点文件不存在,则包从包工作流的起点开始运行。If the checkpoint file exists, the package restarts from the point of the previous execution failure; otherwise, it runs from the start of the package workflow.

备注

dtexec 的 /CheckPointing on 选项等效于将包的 SaveCheckpoints 属性设置为 True,并将 CheckpointUsage 属性设置为 Always。The /CheckPointing on option of dtexec is equivalent to setting the SaveCheckpoints property of the package to True, and the CheckpointUsage property to Always. 有关详细信息,请参阅 dtexec UtilityFor more information, see dtexec Utility.

保护检查点文件Securing Checkpoint Files

包级别的保护不包括保护检查点文件,必须单独保护这些文件。Package level protection does not include protection of checkpoint files and you must secure these files separately. 检查点数据只能存储在文件系统中,应当使用操作系统访问控制列表 (ACL) 来保护用于存储该文件的位置或文件夹。Checkpoint data can be stored only in the file system and you should use an operating system access control list (ACL) to secure the location or folder where you store the file. 重要的是务必保护检查点文件,因为它们包含了有关包状态的信息,包括变量的当前值。It is important to secure checkpoint files because they contain information about the package state, including the current values of variables. 例如,变量可能包含由很多行私人数据(如电话号码)组成的记录集。For example, a variable may contain a recordset with many rows of private data such as telephone numbers. 有关详细信息,请参阅 访问包使用的文件For more information, see Access to Files Used by Packages.

配置检查点以重新启动失败的包Configure Checkpoints for Restarting a Failed Package

通过设置应用于检查点的属性,可以将 Integration ServicesIntegration Services 包配置为从失败点重新启动,而不是重新运行整个包。You configure Integration ServicesIntegration Services packages to restart from a point of failure, instead of rerunning the entire package, by setting the properties that apply to checkpoints.

将包配置为重新启动To configure a package to restart

  1. SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT)中,打开要配置的包所在的 Integration ServicesIntegration Services 项目。In SQL Server Data Tools (SSDT)SQL Server Data Tools (SSDT), open the Integration ServicesIntegration Services project that contains the package you want to configure.

  2. 在“解决方案资源管理器” 中,双击该包将其打开。In Solution Explorer, double-click the package to open it.

  3. 单击 “控制流” 选项卡。Click the Control Flow tab.

  4. 右键单击控制流设计图面背景中的任意位置,然后单击“属性” 。Right-click anywhere in the background of the control flow design surface, and then click Properties.

  5. 将 SaveCheckpoints 属性设置为 TrueSet the SaveCheckpoints property to True.

  6. 在 CheckpointFileName 属性中键入检查点文件的名称。Type the name of the checkpoint file in the CheckpointFileName property.

  7. 将 CheckpointUsage 属性设置为以下两个值之一:Set the CheckpointUsage property to one of two values:

    • 选择 Always ,始终从检查点重新启动包。Select Always to always restart the package from the checkpoint.

      重要

      如果检查点文件不可用,将出现错误。An error occurs if the checkpoint file is not available.

    • 选择 IfExists ,仅当检查文件可用时才重新启动包。Select IfExists to restart the package only if the checkpoint file is available.

  8. 配置包可以从中重新启动的任务和容器。Configure the tasks and containers from which the package can restart.

    • 右键单击任务或容器,然后单击“属性” 。Right-click a task or container and click Properties.

    • 将每个所选任务和容器的 FailPackageOnFailure 属性设置为 TrueSet the FailPackageOnFailure property to True for each selected task and container.

外部资源External Resources