[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eThe Datastore emulator allows you to export data from your database instance and load it into the emulator, as well as export data from the emulator and load it into your Datastore mode database.\u003c/p\u003e\n"],["\u003cp\u003eTo import entities into the emulator, a \u003ccode\u003ePOST\u003c/code\u003e import request must be sent, which involves specifying the project ID and the path to the \u003ccode\u003eoverall_export_metadata\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eWhen importing or exporting, you can filter entities by specific kinds or namespaces using an entity filter in the request.\u003c/p\u003e\n"],["\u003cp\u003eTo export entities, send a \u003ccode\u003ePOST\u003c/code\u003e export request to the emulator, specifying the project ID and the directory for the exported files.\u003c/p\u003e\n"],["\u003cp\u003eData exported from the emulator can be loaded into a Datastore mode database, but the entity export files must first be uploaded to a Cloud Storage bucket.\u003c/p\u003e\n"]]],[],null,["# Exporting and importing emulator data\n\nUsing the import and export features of the Datastore emulator, you\ncan export data from your database instance and load it into the emulator. You\ncan also export data from the emulator and load it into your\nDatastore mode database.\n\nBefore you begin\n----------------\n\nBefore you use the import or export features of the Datastore emulator,\ncomplete the following:\n\n- [Start the Datastore emulator.](/datastore/docs/tools/datastore-emulator)\n\n The import and export features are available for `cloud-datastore-emulator`\n versions 2.1.0 and greater. You may need to [update your Google Cloud CLI\n components](/sdk/docs/components#updating_components).\n- For import operations, make sure your entity export files are on the same\n machine as the emulator.\n\nImport entities into the emulator\n---------------------------------\n\nThe emulator's import feature lets you load entities from a set of entity export\nfiles into the emulator. The entity export files can come from an export of\nyour Datastore mode database or of an emulator instance.\n\nTo import entities into the emulator, send a `POST` import request to the\nemulator. You can use [curl](https://curl.haxx.se/) or a similar tool. For\nexample, the following request will import all entities from a set of entity\nexport files into the emulator: \n\n### Protocol\n\n```sh\ncurl -X POST localhost:8081/v1/projects/[PROJECT_ID]:import \\\n-H 'Content-Type: application/json' \\\n-d '{\"input_url\":\"[ENTITY_EXPORT_FILES]\"}'\n```\nModify `localhost:8081` if the emulator uses a different port.\n\nwhere:\n\n- `[PROJECT_ID]` is the ID of your project.\n- `[ENTITY_EXPORT_FILES]` is the path to the `overall_export_metadata` file of your\n entity export files. For example:\n\n `{\"input_url\":\"/home/user/myexports/2019-02-04T19:39:33_443/2019-02-04T19:39:33_443.overall_export_metadata\"}`\n\n### Import entities from specific kinds and namespaces\n\nYou can specify an entity filter to import entities from only specific kinds or\nnamespaces. You can specify an entity filter only if the export was created\nusing an entity filter.\n\nSpecify kinds or namespaces in an entity filter: \n\n### Protocol\n\n```sh\ncurl -X POST localhost:8081/v1/projects/[PROJECT_ID]:import \\\n-H 'Content-Type: application/json' \\\n-d '{\"input_url\":\"[ENTITY_EXPORT_FILES]\",\n\"entity_filter\":{\"kinds\":[[KIND_NAMES]], \"namespace_ids\":[[NAMESPACES]]}}'\n```\nModify `localhost:8081` if the emulator uses a different port.\n\nwhere:\n\n- `[PROJECT_ID]` is the ID of your project.\n- `[ENTITY_EXPORT_FILES]` is the path to the `overall_export_metadata` file of your\n entity export files. For example:\n\n `{\"input_url\":\"/home/user/myexports/2019-02-04T19:39:33_443/2019-02-04T19:39:33_443.overall_export_metadata\"}`\n- `[KIND_NAMES]` is a list of kinds: `\"kinds\":[\"KIND_1\", \"KIND_2\"]`\n\n- `[NAMESPACES]` is a list of namespace IDs:\n\n `\"namespace_ids\":[\"NAMESPACE_1\", \"NAMESPACE_2\"]`\n\nExport entities in the emulator\n-------------------------------\n\nThe emulator's export feature lets you save entities in the emulator into a\nset of entity export files. You can then use an import operation to load the\nentities in the entity export files into your Datastore mode database or\ninto an emulator instance.\n\nTo export entities in an emulator instance, send a `POST` export request to the\nemulator. You can use [curl](https://curl.haxx.se/) or a similar tool. For\nexample, the following request will export all entities in the emulator: \n\n### Protocol\n\n```sh\ncurl -X POST localhost:8081/v1/projects/[PROJECT_ID]:export \\\n-H 'Content-Type: application/json' \\\n-d '{\"output_url_prefix\":\"EXPORT_DIRECTORY\"}'\n```\nModify `localhost:8081` if the emulator uses a different port.\n\nwhere:\n\n- `[PROJECT_ID]` is the ID of your project.\n- `[EXPORT_DIRECTORY]` specifies the directory where the emulator saves the\n entity export files. This directory must not already contain a set of\n entity export files. For example:\n\n `{\"output_url_prefix\":\"/home/user/myexports/2019-02-04/\"}`\n\n| **Note:** If you intend to use an entity filter when importing entities from your entity export files, you must [specify an entity filter in your export\n| operation](#export-with-entity-filter).\n\n\n### Export entities from specific kinds and namespaces\n\n\nYou can specify an entity filter to export entities from only specific kinds or\nnamespaces.\n\n\nSpecify kinds or namespaces in an entity filter:\n\n### Protocol\n\n```sh\ncurl -X POST localhost:8081/v1/projects/[PROJECT_ID]:export \\\n-H 'Content-Type: application/json' \\\n-d '{\"output_url_prefix\":\"EXPORT_DIRECTORY\",\n\"entity_filter\":{\"kinds\":[[KIND_NAMES]], \"namespace_ids\":[[NAMESPACES]]}}'\n```\nModify `localhost:8081` if the emulator uses a different port.\n\nwhere:\n\n\n- `[PROJECT_ID]` is the ID of your project.\n- `[EXPORT_DIRECTORY]` specifies the directory where the emulator saves the\n entity export files. This directory must not already contain a set of\n entity export files. For example:\n\n {\"output_url_prefix\":\"/home/user/myexports/2019-02-04/\"}\\`\\`\n- `[KIND_NAMES]` is a list of kinds: `\"kinds\":[\"KIND_1\", \"KIND_2\"]`\n\n- `[NAMESPACES]` is a list of namespace IDs:\n\n `\"namespace_ids\":[\"NAMESPACE_1\", \"NAMESPACE_2\"]`\n\n\n### Load emulator data into your database\n\n\nEntity export files created by the emulator are compatible with the\nmanaged import feature for Datastore mode databases.\n\n\nBefore you can load entities exported from the emulator into your database, you\nmust [upload your entity export files to a Cloud Storage\nbucket](/storage/docs/uploading-objects). The managed import feature reads only\nfrom Cloud Storage buckets.\n\nOnce your entity export files are available in a Cloud Storage bucket, you\ncan import the data into your database as described in\n[Exporting and importing entities](/datastore/docs/export-import-entities)."]]