Area: Deployment
Sub-Area: Data Migration
Applies to: OSS + Cloud
Issue
After you migrate DataHub from one environment to another, some tables or datasets are missing in the new environment, even though they exist in the source.
You Might Be Asking
- Why are some of my tables missing after migration?
- How do I move DataHub metadata between environments?
- Can I use
datahub putanddatahub getto export and import metadata?
Cause
datahub put and datahub get can't copy a whole environment. datahub put writes one aspect to one URN. It needs --urn, -a and -d, and it has no -f option and no wildcard support. datahub get fetches one exact URN and takes no wildcards. A migration built on these commands leaves entities behind.
The documented ways to move metadata between instances are:
- The
datahubingestion source, which migrates metadata from one DataHub instance to another. - A backup and restore of the
metadata_aspect_v2table, followed by restoring the search indexes or rebuilding them from SQL.
DataHub keeps versioned aspects in the SQL table and keeps search indexes and graph relationships in Elasticsearch or OpenSearch. After you restore only the SQL table on a self-hosted instance, you must also restore the indexes or rebuild them from SQL.
Solution
The steps below apply to self-hosted DataHub. DataHub Cloud customers don't have access to the database, Kafka or search cluster, and the datahub source needs direct access to them. If you run DataHub Cloud, contact DataHub Support to plan a migration.
Option 1: Use the datahub ingestion source
The datahub source needs direct access to the source instance's database, Kafka broker and schema registry. It should have an index on metadata_aspect_v2(createdon). It doesn't ingest data produced after the job starts. It writes to the sink you configure, such as a datahub-rest sink with the destination GMS server and token. See the datahub source documentation for the recipe options. Run the recipe with datahub ingest.
Option 2: Back up and restore the database
-
Dump the versioned metadata table from the source database:
mysqldump -u <username> -p datahub metadata_aspect_v2 > metadata_aspect_v2_backup.sql -
Restore it into the target database:
mysql -h <host> -u <user> -p datahub < metadata_aspect_v2_backup.sql -
Bring the search and graph indexes in line with the restored data. Either restore Elasticsearch or OpenSearch snapshots of all DataHub indices, or rebuild the indices from SQL:
- Quickstart:
datahub docker quickstart --restore-indices - Docker:
./docker/datahub-upgrade/datahub-upgrade.sh -u RestoreIndices - Helm:
kubectl create job --from=cronjob/<release>-datahub-restore-indices-job-template <name> - CLI:
datahub check restore-indices --urn <urn or % pattern>
If you use a filesystem snapshot repository, set
path.repoinelasticsearch.ymlon all nodes first. Don't restrict the snapshot to indices that start withdatahub. With the default emptyINDEX_PREFIX, indices such asdatasetindex_v2andgraph_service_v1don't start withdatahub. - Quickstart:
See Backup & Restore and Restoring indices.
Check for missing entities
To check one entity, fetch it by its exact URN in both environments and compare the output:
datahub get --urn "<dataset urn>"
Leave out -a to get all aspects. If you pass -a, the CLI first checks that the URN exists and raises urn <urn> not found if it doesn't.