databricks-serverless-migration-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseServerless Migration API
Serverless Migration API
FIRST: Use the parent skill for CLI installation, authentication, and profile selection.
databricks-coreUse the Compute Migrations API through the Databricks CLI to migrate a job to serverless. The service analyzes the job, backs it up, builds a serverless working copy, and optionally runs it in the background. Your part is to track the migration, review the working copy, present the changes to the user, and carry out their decision. Applying the changes to the original job requires the user's explicit approval.
首先:使用父级 skill 进行 CLI 安装、身份验证和 profile 选择。
databricks-core通过 Databricks CLI 使用 Compute Migrations API 将作业迁移到 serverless。该服务会分析作业、创建备份、构建 serverless 工作副本,并可选地在后台运行工作副本。你负责跟踪迁移、审查工作副本、向用户展示变更,并根据用户的决定执行相应操作。将变更应用到原始作业需要获得用户的明确批准。
When to Use This Skill
何时使用此 Skill
Use it when the user asks you to:
- migrate one job or many jobs to serverless,
- write a script that starts and tracks migrations,
- check on, approve, reject, or cancel migrations already in progress, or
- find the backup a migration took of a job.
Use for direct code edits, notebooks, pipelines, JAR tasks, or a job this service cannot migrate. For job definitions maintained in source control, read Jobs managed from source.
databricks-serverless-migrationSee the migration guide for supported workloads and limits. A successful starts the migration; it does not establish that the workload is compatible. Incompatibilities can be discovered during planning or working-copy creation.
createMigrate One Job
迁移单个作业
- Check the prerequisites once per workspace.
- Confirm the job and whether to set or
auto_approve(see Settings chosen at creation).run_validation - Start the migration with , and record its migration ID and
create.request_id - Track progress until it reaches a review gate or a terminal state.
- At each review gate, review the working copy, present your findings to the user, and approve or reject as the user decides.
- After , verify the original job and report the result and the backup folder.
MIGRATION_COMPLETE
For a list of jobs, use Bulk migration to repeat this workflow and track each job's decisions.
Prerequisites
前提条件
- CLI v1.24.0 or newer: check and
databricks --version. The command group and the verbs below must be available. If a command is missing, upgrade usingdatabricks compute-migrations --help.databricks-core - Compute Agent preview enabled in the workspace. A workspace admin enables it under Previews. Without it, every call fails with ("Migration APIs are not enabled for this workspace").
PERMISSION_DENIED - CAN_MANAGE on each job you migrate.
The CLI help is generated from the API and is authoritative for command names, arguments, and flags. Run before first use of each command. Pass request bodies with and read responses with .
databricks compute-migrations <command> --help--json-o json- CLI v1.24.0 或更高版本:检查 和
databricks --version。必须存在此命令组及下述动词。如果缺少某个命令,请使用databricks compute-migrations --help升级。databricks-core - workspace 中已启用 Compute Agent 预览版。工作区管理员可在 Previews 下启用。如果未启用,所有调用都会失败并返回 ("Migration APIs are not enabled for this workspace")。
PERMISSION_DENIED - 对每个要迁移的作业拥有 权限。
CAN_MANAGE
CLI 帮助信息由 API 生成,是命令名称、参数和标志的权威依据首次使用每个命令前,请运行 。使用 传递请求正文,并使用 读取响应。
databricks compute-migrations <command> --help--json-o jsonLifecycle
生命周期
Prepare working copy
→ TRANSLATION_READY (skipped when auto_approve=true)
→ Optional validation run (run_validation=true)
→ MIGRATION_REVIEW (execution approval required)
→ Apply changes → MIGRATION_COMPLETE- Planning. The service reads the job, its notebooks and files, and its cluster configuration, and works out the serverless changes: compute, dependencies, Spark configs, and code changes. The working copy is the first thing you review.
- Backup and working copy. The service saves a backup of the job and its workspace files (see Backups), then creates a working copy: a new job named , tagged
[Serverless Migration - <timestamp>] <job name>, running copies of the job's notebooks and files. The original job is not modified until you approve execution.serverless_migration_source_job_id=<original job id> - Gate 1, . Skipped when
TRANSLATION_READY. Otherwise, review the working copy. Approve to continue, or reject with a reason to request changes.auto_approve=true - Validation run (only with ). Databricks runs the working-copy job once. The outcome is recorded in
run_validation. A failed run does not stop the migration: it moves tovalidation_reportwithMIGRATION_REVIEW.passed: false - Gate 2, . Final approval to update the original job. Approving execution starts applying the working copy's settings and file contents to the original job, keeping its job ID, schedule, and permissions.
MIGRATION_REVIEW - Complete. Verify the original job (see After completion).
Use either rejection command to request changes, with a specific . The same migration returns to planning and revises its working copy. Read again and review the current copy before approving it. Revisions are limited, and repeated rejections eventually fail the migration. When the user wants to stop the migration, use (see Cancellation).
rejection_reasonmigration_reportcancel-migrationPrepare working copy
→ TRANSLATION_READY (skipped when auto_approve=true)
→ Optional validation run (run_validation=true)
→ MIGRATION_REVIEW (execution approval required)
→ Apply changes → MIGRATION_COMPLETE- 规划。 服务读取作业、其 notebook 和文件以及集群配置,并确定 serverless 变更,包括计算资源、依赖项、Spark 配置和代码变更。工作副本是首先要审查的对象。
- 备份和工作副本。 服务保存作业及其 workspace 文件的备份(请参阅备份),然后创建一个工作副本:这是一个名为 的新作业,带有
[Serverless Migration - <timestamp>] <job name>标签,并包含该作业 notebook 和文件的运行副本。在批准执行之前,原始作业不会被修改。serverless_migration_source_job_id=<original job id> - 审批节点 1:。 当
TRANSLATION_READY时跳过此节点。否则应审查工作副本。批准后继续执行,或拒绝并提供原因以请求修改。auto_approve=true - 验证运行(仅在启用 时)。Databricks 会运行工作副本作业一次。结果记录在
run_validation中。运行失败不会停止迁移:迁移会进入validation_report,并带有MIGRATION_REVIEW。passed: false - 审批节点 2:。 这是更新原始作业前的最终批准。批准执行后,会开始将工作副本的设置和文件内容应用到原始作业,同时保留其作业 ID、调度计划和权限。
MIGRATION_REVIEW - 完成。 验证原始作业(请参阅完成后)。
使用任一拒绝命令来请求修改,并提供具体的 。同一个迁移会返回规划阶段并修订其工作副本。再次读取 ,并在批准前审查当前副本。修订次数有限,反复拒绝最终会导致迁移失败。如果用户希望停止迁移,请使用 (请参阅取消)。
rejection_reasonmigration_reportcancel-migrationSettings Chosen at Creation
创建时选择的设置
auto_approverun_validationfalse| Field | Effect | Risk |
|---|---|---|
| Skips gate 1 ( | With |
| Runs the working-copy job once before gate 2. | The run is real: see below. |
A validation run is not sandboxed. The working copy runs in the same workspace against the same tables, volumes, checkpoints, and external systems as the original job, with the agent's changes applied. If the job is not idempotent, or has side effects, the validation run produces them. Examples: overwriting or appending to production tables, merges, sending emails or notifications, calling external APIs, triggering downstream jobs, or advancing streaming offsets and checkpoints. Enable only after the user confirms that one extra run of this job, right now, is safe, for example because the job is idempotent or writes only to test outputs. Never turn it on across a batch of jobs without that confirmation for each job.
run_validationauto_approverun_validationfalse| 字段 | 效果 | 风险 |
|---|---|---|
| 跳过审批节点 1( | 与 |
| 在审批节点 2 前运行一次工作副本作业。 | 该运行是真实运行:详见下文。 |
验证运行不是沙箱环境。 工作副本会在同一 workspace 中运行,并访问与原始作业相同的表、volume、checkpoint 和外部系统,同时应用 Agent 的变更。如果作业不具备幂等性或会产生副作用,验证运行也会产生这些副作用。例如:覆盖或追加生产表、执行合并、发送电子邮件或通知、调用外部 API、触发下游作业,或者推进流式 offset 和 checkpoint。只有在用户确认当前立即额外运行该作业一次是安全的,才应启用 ,例如作业具备幂等性或仅写入测试输出。绝不能在未逐一获得每个作业确认的情况下,对一批作业启用此选项。
run_validationCommands
命令
| Operation | Command | Notes |
|---|---|---|
| Start | | |
| Read one | | Current state, reports, |
| Read many | | Returns a JSON array with |
| Gate 1 | | Reject takes the reason as a positional argument or as |
| Gate 2 | | Same arguments and flags as gate 1. |
| Stop | | Any non-terminal state. Optional |
| Remove record | | Hides the record and frees the job for a new migration. Rolls nothing back and cleans nothing up. Use |
All commands are under . Start a migration:
databricks compute-migrationsbash
databricks compute-migrations create -o json --request-id "<uuid>" --json '{
"asset_type": "JOB",
"asset_uri": "jobs/<job_id>",
"auto_approve": false,
"run_validation": false
}'Generate a fresh per job and reuse it when retrying that job's after a timeout or network error. The server returns the existing migration instead of creating a duplicate.
request_idcreatePass the from your latest on every approve, reject, and cancel, so the call fails rather than acting on a state you have not seen:
etaggetbash
databricks compute-migrations reject-migration-translation <migration_id> -o json --json '{
"etag": "<etag>",
"rejection_reason": "Keep the existing output table names; task ingest writes to a different table in the working copy."
}'| Error | Meaning | Action |
|---|---|---|
| The job has a migration in progress, or one that already migrated it. | Find and confirm the existing migration as described below. |
| Bad request, or the job cannot be migrated. | Read the message; do not retry unchanged. |
| No CAN_MANAGE on the job, or the preview is not enabled. | Report to the user. |
| Gate call made in the wrong state. | |
| The | |
After , take the migration ID from the error and confirm its and state with . If the existing migration is , report the job as already migrated. Do not delete the record and create another migration unless the user explicitly requests it.
ALREADY_EXISTSasset_urigetMIGRATION_COMPLETE| 操作 | 命令 | 备注 |
|---|---|---|
| 启动 | | |
| 读取一个 | | 返回当前状态、报告和 |
| 读取多个 | | 使用 |
| 审批节点 1 | | 拒绝命令可通过位置参数或 |
| 审批节点 2 | | 参数和标志与审批节点 1 相同。 |
| 停止 | | 可用于任何非终态。可选提供 |
| 删除记录 | | 隐藏记录并释放作业以进行新迁移。不会回滚任何内容,也不会清理任何资源。如需停止正在进行的迁移,请使用 |
所有命令均位于 下。启动迁移:
databricks compute-migrationsbash
databricks compute-migrations create -o json --request-id "<uuid>" --json '{
"asset_type": "JOB",
"asset_uri": "jobs/<job_id>",
"auto_approve": false,
"run_validation": false
}'为每个作业生成新的 ,并在超时或网络错误后重试该作业的 时复用它。服务器会返回现有迁移,而不是创建重复迁移。
request_idcreate每次执行批准、拒绝或取消操作时,都要传入最新一次 返回的 ,这样如果操作所基于的状态已发生变化,调用就会失败:
getetagbash
databricks compute-migrations reject-migration-translation <migration_id> -o json --json '{
"etag": "<etag>",
"rejection_reason": "Keep the existing output table names; task ingest writes to a different table in the working copy."
}'| 错误 | 含义 | 操作 |
|---|---|---|
| 该作业有正在进行的迁移,或已有迁移完成了迁移。 | 按照下文所述查找并确认现有迁移。 |
| 请求无效,或该作业无法迁移。 | 阅读错误消息;不要在未修改参数的情况下重试。 |
| 对作业没有 | 向用户报告。 |
| 在错误状态下调用了审批节点命令。 | 执行 |
| | 执行 |
出现 后,从错误中获取迁移 ID,并使用 确认其 和状态。如果现有迁移为 ,则报告该作业已完成迁移。除非用户明确要求,否则不要删除记录并创建另一个迁移。
ALREADY_EXISTSgetasset_uriMIGRATION_COMPLETETracking Progress
跟踪进度
Migrations take minutes to hours: planning and building the working copy usually take several minutes, and a validation run takes as long as the job. Use your harness's monitoring capabilities to track progress. returns the current migration state; for many migrations, use and confirm each one with before acting.
getlistget| State | What to do |
|---|---|
| Planning is in progress. |
| Working-copy creation is in progress. |
| Validation is in progress. |
| Migration is in progress. |
| Review the working copy, present it to the user, then approve or reject gate 1. |
| Review the working copy and |
| Verify the original job. |
| The job cannot be migrated automatically. Report the reason from |
| Report the reason from |
| Report the cancellation and check for applied changes or active validation runs as described in Cancellation. |
| Any other state | Read the migration again with |
state_historytransition_timeuser_commentinternal_comment迁移可能耗时数分钟到数小时:规划和工作副本创建通常需要几分钟,验证运行的耗时则与作业本身相同。使用你的 harness 监控功能跟踪进度。 返回当前迁移状态;对于多个迁移,请使用 ,并在采取操作前分别使用 确认。
getlistget| 状态 | 应执行的操作 |
|---|---|
| 规划正在进行。 |
| 正在创建工作副本。 |
| 验证正在进行。 |
| 迁移正在进行。 |
| 审查工作副本,向用户展示内容,然后批准或拒绝审批节点 1。 |
| 审查工作副本和 |
| 验证原始作业。 |
| 该作业无法自动迁移。报告 |
| 报告 |
| 报告取消情况,并按照取消中的说明检查已应用的变更或仍在运行的验证任务。 |
| 任何其他状态 | 使用 |
state_historytransition_timeuser_commentinternal_commentCancellation
取消
Cancellation does not undo changes already applied to the original job or files, or side effects of validation runs. An operation already in progress may finish after the migration reports ; that state alone does not confirm that all work has stopped.
CANCELLEDIf execution was approved, or includes or , inspect the original job and files against the saved review record and backup. Report which changes are present and anything you cannot verify. Check active working-copy runs separately with . Retain the recovery artifacts if the result is unverified or work may still be active.
state_historyMIGRATION_PENDINGMIGRATION_RUNNINGdatabricks jobs list-runs --job-id <working_copy_job_id> --active-only -o json取消不会撤销已应用到原始作业或文件的变更,也不会撤销验证运行产生的副作用。迁移报告 后,已经开始的操作仍可能完成;仅凭该状态无法确认所有工作都已停止。
CANCELLED如果已批准执行,或者 包含 或 ,请将原始作业和文件与保存的审查记录及备份进行比较。报告已存在的变更,以及任何无法验证的内容。另使用 检查活动的工作副本运行。如果结果未经验证或工作可能仍在进行,请保留恢复工件。
state_historyMIGRATION_PENDINGMIGRATION_RUNNINGdatabricks jobs list-runs --job-id <working_copy_job_id> --active-only -o jsonReviewing a Working Copy
审查工作副本
The API returns links to the working copy, not a diff, so build the comparison yourself:
- the migration.
getis the working-copy job's ID.migration_report.primary_asset.id - Compare job settings: against
databricks jobs get <original_job_id> -o json. Expect classic compute (databricks jobs get <working_copy_job_id> -o json,job_clusters,new_cluster) to be replaced by serverless settings (existing_cluster_idandenvironments), libraries to move into environment dependencies, unsupported Spark configs and init scripts to be removed, and possibly a performance mode to be set. The job name prefix, theenvironment_keytag, and task paths pointing at the copied notebooks are expected differences.serverless_migration_source_job_id - Compare code. The working-copy job's task settings name the notebooks and files it runs. Match its tasks to the original job's by , and take each task's path (
task_keyornotebook_task.notebook_path) from both jobs. Forspark_python_task.python_file, inspect its innerfor_each_tasktoo. Export each to a separate local file withtaskand diff them. Also inspect utility notebooks invoked by the task notebooks for changes, such as throughdatabricks workspace export <path> --format SOURCE --file <local_file>or%run.dbutils.notebook.run - If a validation run happened, report ,
validation_report.passed, andrun_status. For a failed run, inspect it withrun_url. Take the run ID fromdatabricks jobs get-run <run_id> -o json.run_url - Summarize the changes per task, including which tasks will migrate and which will stay on classic. Flag anything beyond a compatibility fix: changed business logic, different output tables or paths, removed steps, or dropped dependencies.
- Before approving execution, save the reviewed job settings and exported code, including utility notebooks, in a local folder for this migration ID. Include the original task paths, the working-copy-to-original path mapping, and the tasks approved for migration or intentionally kept on classic. This review record is needed after the working copy is deleted. Refresh it after any revision and review.
- Get the user's decision. A rejection reason should name the task and the specific change to make.
Rules while a migration is in progress:
- Approve gate 2 only with explicit user approval covering that job ID. A single decision may approve an explicitly identified set of jobs; the approval must cover the reviewed changes for each job.
- Do not edit the original job. Approving execution replaces its settings and files with the working copy's, discarding later edits.
- Do not edit the working copy to change the outcome. Reject with a reason instead.
API 返回工作副本的链接,而不是差异对比,因此需要自行构建比较:
- 执行 获取迁移。
get是工作副本作业的 ID。migration_report.primary_asset.id - 比较作业设置:执行 ,并与
databricks jobs get <original_job_id> -o json的结果进行比较。预期 classic 计算资源(databricks jobs get <working_copy_job_id> -o json、job_clusters、new_cluster)会被 serverless 设置(existing_cluster_id和environments)替换,库会移入环境依赖项,不受支持的 Spark 配置和初始化脚本会被移除,并且可能会设置性能模式。作业名称前缀、environment_key标签以及指向已复制 notebook 的任务路径属于预期差异。serverless_migration_source_job_id - 比较代码。工作副本作业的任务设置会指定其运行的 notebook 和文件。通过 将其任务与原始作业中的任务匹配,然后从两个作业中获取每个任务的路径(
task_key或notebook_task.notebook_path)。对于spark_python_task.python_file,还需检查其内部的for_each_task。使用task将每个文件导出到单独的本地文件并进行差异对比。还应检查任务 notebook 调用的 utility notebook 是否发生变化,例如通过databricks workspace export <path> --format SOURCE --file <local_file>或%run调用的 notebook。dbutils.notebook.run - 如果执行了验证运行,请报告 、
validation_report.passed和run_status。对于失败的运行,使用run_url检查详情。从databricks jobs get-run <run_id> -o json获取运行 ID。run_url - 按任务汇总变更,包括哪些任务将迁移、哪些任务将继续使用 classic。除兼容性修复外,还应标记以下情况:业务逻辑变更、输出表或路径不同、步骤被移除或依赖项被丢弃。
- 批准执行前,将审查过的作业设置和导出的代码(包括 utility notebook)保存在此迁移 ID 对应的本地文件夹中。内容应包括原始任务路径、工作副本到原始作业的路径映射,以及批准迁移或有意保留在 classic 上的任务。工作副本删除后仍需要此审查记录。每次修订并审查后都要刷新此记录。
- 获取用户的决定。拒绝原因应指明具体任务以及需要进行的具体修改。
迁移进行期间应遵循以下规则:
- 只有在获得覆盖该作业 ID 的用户明确批准后,才能批准审批节点 2。单次决定可以批准明确标识的一组作业;批准必须涵盖每个作业已审查的变更。
- 不要编辑原始作业。批准执行会使用工作副本的设置和文件替换原始作业的设置和文件,从而丢弃后续编辑。
- 不要通过编辑工作副本来改变结果。请改为拒绝并提供原因。
After Completion
完成后
When the API reports , verify the original job before reporting success:
MIGRATION_COMPLETE- Read and compare it with the saved review record. Tasks approved for migration must have the reviewed serverless settings; tasks intentionally left on classic must retain their reviewed configuration. Account for the original job name and task paths, and removal of the working-copy tag.
databricks jobs get <job_id> -o json - Export the original task notebooks and files, including those used by nested tasks, along with the reviewed utility notebooks. Compare them with the saved reviewed code.
If approved changes are missing or differ from the review record, report the mismatch and offer to restore from the backup. Before retrying, restore any job settings or files changed by this migration from the pre-migration backup, with the user's approval. Then the migration (which frees the job) and create a new one. If the review record is unavailable, explain which parts of the result you could verify and which remain unverified.
deleteThe working-copy job or its copied files may remain after a successful migration. Report any leftovers and offer cleanup.
Report the migration ID, final state, original job, what changed, tasks left on classic, and the backup folder.
当 API 报告 后,在报告成功前验证原始作业:
MIGRATION_COMPLETE- 读取 ,并将其与保存的审查记录进行比较。获准迁移的任务必须采用审查过的 serverless 设置;有意保留在 classic 上的任务必须保留审查过的配置。比较时应考虑原始作业名称、任务路径以及工作副本标签被移除等预期差异。
databricks jobs get <job_id> -o json - 导出原始任务 notebook 和文件,包括嵌套任务使用的 notebook 和文件,以及审查过的 utility notebook。将其与保存的已审查代码进行比较。
如果已批准的变更缺失或与审查记录不同,请报告不一致情况,并提供从备份恢复的选项。重试前,应在获得用户批准后,使用迁移前备份恢复此次迁移更改过的所有作业设置或文件。然后删除迁移记录(这会释放作业)并创建新的迁移。如果无法获取审查记录,请说明哪些结果已验证,以及哪些仍未验证。
迁移成功后,工作副本作业或其复制的文件可能仍然存在。报告任何残留内容,并提供清理选项。
请报告迁移 ID、最终状态、原始作业、发生的变更、保留在 classic 上的任务以及备份文件夹。
Backups
备份
Before building the working copy, the service writes a backup to the workspace home of the identity that created the migration.
Files that tasks load from a Git repository are not copied; they stay in the repository. A new timestamped backup folder is written each time the service builds a working copy. Migrations never delete backups. Give the user the backup folder for every migration that reached or later.
TRANSLATION_READYThere is no rollback command. For the backup location and file layout, restore instructions, and working-copy cleanup, follow Backups and rollback.
在构建工作副本前,服务会将备份写入创建迁移的身份所对应的 workspace 主目录。
任务从 Git 仓库加载的文件不会被复制,而是继续保留在仓库中。每次服务构建工作副本时,都会写入一个新的带时间戳的备份文件夹。迁移绝不会删除备份。对于到达 或更晚阶段的每次迁移,都应向用户提供备份文件夹。
TRANSLATION_READY没有回滚命令。有关备份位置和文件布局、恢复说明以及工作副本清理方式,请参阅备份与回滚。
Bulk Migration
批量迁移
For multiple jobs, follow Bulk migration. It applies the single-job workflow to each migration, with separate tracking, settings, review records, and approval decisions.
对于多个作业,请遵循批量迁移中的说明。该流程将单作业工作流应用于每个迁移,并分别跟踪状态、设置、审查记录和批准决定。
Jobs Managed from Source
源码管理的作业
A migration changes the job in the workspace. If the job's definition comes from source, the next deploy reverts the migration. This covers jobs deployed from a Declarative Automation Bundle ( is ) and jobs managed by Terraform or CI. For these jobs, tell the user before creating a migration. Either migrate the source (, ), or use the reviewed working copy as the reference for changes to make in the source.
settings.deployment.kindBUNDLEdatabricks-serverless-migrationdatabricks-dabs迁移会更改 workspace 中的作业。如果作业定义来自源代码,下一次部署会撤销此次迁移。这包括通过 Declarative Automation Bundle 部署的作业( 为 ),以及由 Terraform 或 CI 管理的作业。对于这些作业,请在创建迁移前告知用户。可以迁移源代码(使用 、),也可以将审查过的工作副本作为参考,对源代码进行相应更改。
settings.deployment.kindBUNDLEdatabricks-serverless-migrationdatabricks-dabsDocumentation
文档
- Serverless migration guide, including the migration agent: https://docs.databricks.com/en/compute/serverless/migration
- Serverless compute limitations: https://docs.databricks.com/en/compute/serverless/limitations
- Serverless jobs: https://docs.databricks.com/en/jobs/run-serverless-jobs
- Serverless 迁移指南,包括 Migration Agent:https://docs.databricks.com/en/compute/serverless/migration
- Serverless 计算限制:https://docs.databricks.com/en/compute/serverless/limitations
- Serverless 作业:https://docs.databricks.com/en/jobs/run-serverless-jobs