用于在不同环境之间迁移 Databricks 资产的工具
NOTE: For a more extensive and maintained cross-workload migration solution, please use the Databricks Terraform Exporter, which creates Infrastructure-as-a-Code replicas for the entire manually-configured Databricks Workspaces.
This is a migration package to log all Databricks resources for backup and/or migrating to another Databricks workspace. Migration allows a Databricks organization to move resources between Databricks Workspaces, to move between different cloud providers, or to move to different regions / accounts.
This package is based on python 3.6 and DBR 6.x+ releases.
Python 3.7 or above is recommended if one is also exporting/importing MLflow objects.
Note: This tool does not support windows currently since path resolution is different from mac / linux.
This package also uses credentials from the Databricks CLI.
To use this migration tool, you'll need:
Click to expand & collapse tasks
Generate Access Tokens for both the old and new databricks accounts
Be sure to keep a file with the url for both the old and new databricks account Add the old and new token and the old and new Instance ID if applicable. You'll need easy access to all of these things when running the migration tool.
In order to run the migration tool from your linux shell
Create a profile for the old workspace by typing:
databricks configure --token --profile oldWSIn this case oldWS is the profile name you'll refer to for running the migration tool export_db.py file within the old databricks account.
When you use the databricks cli configure command, you'll be prompted for 2 things
Databricks Host (should begin with https://): When this happens, enter the old databricks workspace URL that you captured in your file above.Token: When this happens, paste in the token you generated for the old databricks account.Repeat the steps above for the new databricks account and change the oldWS profile name to something like newWS in order to keep track of which account you're exporting FROM and which account you're importing TO.
Create a profile for the New workspace by typing:
databricks configure --token --profile newWSIn this case newWS is the profile name you'll refer to for running the migration tool import_db.py file within the new databricks account.
In order to set up the python environment, clone this repository and python3 setup.py install from the top-level project directory.
To use the migration tool see the details below to start running the tool in the order recommended to properly migrate files.
Support Matrix for Import and Export Operations:
| Component | Export | Import |
|---|---|---|
| Users / Groups | Supported | Supported |
| Clusters (w/ ACLs) | Supported | Supported |
| Notebooks (w/ ACLs) | Supported | Supported |
| Repos (w/ ACLs) | Supported | Supported* |
| Metastore | Supported | Supported |
| Jobs (w/ ACLs) | Supported | Supported |
| Libraries | Supported | Unsupported |
| Secrets | Supported | Supported |
| Table ACLs | Supported | Supported |
| DBFS Mounts | Supported | Unsupported |
| ML Models | Supported* | Supported* |
Note on MLFlow Migration:
MLFlow asset migration is currently only partially supported; Feature Store and Model Registry will not be migrated, for example. See mlflow-export-import for comprehensive MLflow migrations.
Note on DBFS Data Migration:
DBFS is a protected object storage location on AWS and Azure. Please contact your Databricks support team for information about migrating DBFS resources.
Note on User Migration:
During user / group import, users will be notified of the new workspace and account by default. To disable this behavior, please contact your Databricks account team.
Note on Repos: Private repos cannot be imported. These should be added manually using the original user credentials.
The recommended method of exporting and importing is by using the Pipeline contained in migration_pipeline.py. This pipeline performs all export and import steps sequentially, and includes checkpointing parallelization features.
…To export a workspace, run:
python3 migration_pipeline.py --profile $SRC_PROFILE --export-pipeline --use-checkpoint [--session $SESSION_ID]
Where $SRC_PROFILE is the Databricks profile for the source workspace, as configured during Setup, and $SESSION_ID is an optional session identifier used for subsequent checkpoint runs. All data is exported to a folder named according to the $SESSION_ID value under the logs folder - “logs/$SESSION_ID”. If $SESSION_ID is not specified, a random value will be generated.
As a starting point, we recommend using the following parameter values:
These can be adjusted per your scenario if needed; in general, if API limits are being hit, you can increase retry-backoff, decrease num-parallel, or both.
If script failure occurs, you can safely rerun the same command with --use-checkpoint and --session $SESSION_ID to let the migration pick up from the previous checkpoint and rerun.
If your source and destination workspaces are in different accounts, you will need to update the Instance Profile ARN accordingly during the migration. To do this, run the following command after exporting the workspace assets:
python3 export_db.py --profile $SRC_PROFILE --use-checkpoint --old-account-id $OLD_AWS_ACCT_ID --update-account-id $NEW_AWS_ACCT_ID --set-export-dir $EXPORT_DIR/$SESSION_IDWhere EXPORT_DIR/SESSION_ID is the directory and session ID used by your export job, SRC_PROFILE is the profile used to export the source workspace, OLD_AWS_ACCT_ID is the source AWS account ID, and NEW_AWS_ACCT_ID is the destination AWS account ID. Note that this will only update the ARN in the Instance Profiles; the same instance profiles must still exist in the destination workspace.
To import into a target workspace, run:
python3 migration_pipeline.py --profile $DST_PROFILE --import-pipeline --use-checkpoint [--session $SESSION_ID]
The same recommended parameters as above apply in the import workflow, and similarly, if a failure occurs, --use-checkpoint can be used to rerun from the last checkpoint.
Simple workspace object validation can be performed once the import is completed by first exporting the contents of the target workspace:
python3 migration_pipeline.py --profile $DST_PROFILE --export-pipeline --use-checkpoint --cluster-name
And then running the validate_pipeline.sh script:
./validate_pipeline.sh $SRC_EXPORT_SESSION_ID $DST_EXPORT_SESSION_ID
Once this completes, check the console summary, as well as the logs folder (where a new folder should be generated).
Import using step-by-step tools (not recommended)
If desired, export_db.py and import_db.py can be run in a stepwise fashion. This is the legacy mode of running the tools, and in general is not recommended. If running the scripts separately, the following order of operations applies:
By default, artifacts are stored in the logs/ directory, and azure_logs/ for Azure artifacts.
This is configurable with the --set-export-dir flag to specify the log directory.
……This section uses the SCIM API to export / import
user and groups.
Instance Profiles API used
to export instance profiles that are tied to user/group entitlements.
For AWS users, this section will log the instance profiles used for IAM access to resources.
To export users / groups, use the following: (The profile name DEMO will be replaced with the profile you defined for your old databricks account)
python export_db.py --profile DEMO --usersTo import these users:
python import_db.py --profile NEW_DEMO --usersIf you plan to use this tool to export multiple workspaces, you can set the --set-export-dir directory to log
artifacts into separate logging directories.
The section uses the Clusters APIs
python export_db.py --profile DEMO --clustersThis will export the following:
python import_db.py --profile NEW_DEMO --clustersIf you experience errors when you try to import the clusters, it may be that you need to modify the clusters file from the logs directory to include the new instance profile if it's not the same as the one in the old databricks account.
To make changes to a cluster name to match the new databricks account
you must edit the clusters log file after export. You do this by looking at the clusters file and identifying the old cluster instance profile which will include the old account number and the name of the instance profile.
OLD profile text from an AWS Databricks account:
arn:aws:iam::111111111111:instance-profile/profileName
The account number (111111111111) and profileName need to be found and replaced to migrate to the new account which may have a different account number and instance profile.
To modify the clusters.log file run this sed operation
sed -i 's/old-text/new-text/g' input.txtThis section uses the Workspace API
This part is a 3 part process.
python export_db.py --profile DEMO --workspace
python export_db.py --暂无开放 Issues,或尚未同步最近议题。