Area: Best Practices
Sub-Area: Data Protection and Recovery
Applies to: OSS + Cloud
Issue
You want a backup and restore plan for metadata that people edit in DataHub (descriptions, tags, owners, glossary terms, domains and links), so you can recover from accidental changes or loss.
The database, search and Kafka steps below apply only to self-hosted DataHub. DataHub Cloud customers have no database or search-cluster access. If you use DataHub Cloud, contact DataHub Support about backups and restores.
You Might Be Asking
- Which metadata aspects should I back up?
- Does DataHub have a documented backup and restore procedure?
- Can I use the OpenAPI v3 scroll endpoint to export metadata?
- Can I read an earlier version of an aspect?
- How do I move metadata to another DataHub instance?
Cause
DataHub keeps data in two places. Versioned aspects live in the SQL table metadata_aspect_v2 (MySQL or PostgreSQL). Timeseries aspects, search indexes and graph relationships live in Elasticsearch or OpenSearch. A backup plan has to cover the SQL table at a minimum. You can rebuild the search and graph indexes from it.
Solution
1. Choose the aspects to protect
These dataset aspects hold user-edited metadata:
editableDatasetPropertieseditableSchemaMetadataownershipglobalTagsglossaryTermsdomainsinstitutionalMemory
Include institutionalMemory in your list.
2. Back up a self-hosted deployment
The official guide recommends dumping only the metadata_aspect_v2 table, or taking RDS snapshots:
mysqldump -u <username> -p datahub metadata_aspect_v2 > metadata_aspect_v2_backup.sql
Restore it with:
mysql -h <host> -u <user> -p datahub < metadata_aspect_v2_backup.sql
For the search indexes, use one of these:
- Take Elasticsearch or OpenSearch snapshots. For a filesystem repository, first add
path.repo(for example["/mnt/es-backups"]) toelasticsearch.ymlon all nodes. Then register the repository withPUT _snapshot/<repo>and snapshot withPUT _snapshot/<repo>/snapshot_YYYY_MM_DD?wait_for_completion=true. By default, index names do not start withdatahub, so snapshot and restore all DataHub indices, not adatahub*pattern. - Rebuild the search and graph indexes from the restored SQL table. Use
datahub docker quickstart --restore-indicesfor quickstart,./docker/datahub-upgrade/datahub-upgrade.sh -u RestoreIndicesfor Docker, orkubectl create job --from=cronjob/<release>-datahub-restore-indices-job-template <name>for Helm. The CLI also hasdatahub check restore-indices --urn <urn or % pattern>.
For a quickstart instance, datahub docker quickstart --backup writes ~/.datahub/quickstart/backup.sql. datahub docker quickstart --restore restores the database and the search indexes from that file. Quickstart is not for production use.
See the Backup and Restore guide and the restore indices guide.
3. Read or save specific entities
-
datahub get --urn <urn> [-a <aspect>]fetches one exact URN and prints JSON to stdout. Redirect with>to save it. Leave out-ato get all aspects. It takes no wildcard URNs. -
datahub put --urn <urn> -a <aspect> -d <file>writes one aspect to one entity.-dis a plain file path, or-for stdin. It ignores unknown options, so setDATAHUB_GMS_URLandDATAHUB_GMS_TOKEN(or use~/.datahubenv) to point it at the right server. It cannot export data. - In Python,
MetadataChangeProposalWrapperneeds a typed aspect object foraspect, not a plain dict.datahub.emitter.aspect.ASPECT_MAPmaps an aspect name to its aspect class.DataHubRestEmittertakesgms_serverand an optionaltoken.
Test every restore in a non-production environment first.
4. Export in bulk
Paging through the search API stops at 10,000 results by default. For large exports use scroll APIs: OpenAPI v3 scroll or GraphQL scrollAcrossEntities.
POST /openapi/v3/entity/scroll takes count (default 10), query (default *), scrollId, sort (default urn), includeSoftDelete (default false) and pitKeepAlive (default 5m) as query parameters. Do not put count or pitKeepAlive in the JSON body. A v3 filter has this shape, where each element of and holds a criteria list:
{"and": [{"criteria": [{"field": "...", "values": ["..."], "condition": "...", "negated": false}]}]}
Scroll is one export option. It does not replace the SQL backup above.
5. Read an earlier aspect version
In DataHub Cloud v2.4.4, the aspect endpoint GET .../{entityName}/{entityUrn}/{aspectName} accepts a version query parameter that defaults to 0. See the OpenAPI usage guide for batch gets with If-Version-Match.
6. Move metadata to another instance
Use the datahub ingestion source. It needs direct access to the source instance's database, Kafka broker and schema registry. Add an index on metadata_aspect_v2(createdon). See the datahub source docs.
7. DataHub Cloud
You cannot run the SQL, snapshot or restore-indices steps on Cloud. Contact DataHub Support about backup and restore needs.