Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Dengan menggunakan fitur impor dan ekspor emulator Datastore, Anda
dapat mengekspor data dari instance database dan memuat data tersebut ke dalam emulator. Anda juga dapat mengekspor data dari emulator dan memuat data tersebut ke dalam database mode Datastore.
Sebelum memulai
Sebelum menggunakan fitur impor atau ekspor emulator Datastore, selesaikan hal berikut:
Fitur impor dan ekspor tersedia untuk cloud-datastore-emulator
versi 2.1.0 dan yang lebih baru. Anda mungkin perlu mengupdate komponen Google Cloud CLI.
Untuk operasi impor, pastikan file ekspor entity Anda berada di mesin yang sama dengan emulator.
Mengimpor entity ke emulator
Fitur impor emulator memungkinkan Anda memuat entity dari sekumpulan file ekspor entity ke dalam emulator. File ekspor entity dapat berasal dari ekspor database mode Datastore atau instance emulator.
Untuk mengimpor entity ke emulator, kirim permintaan impor POST ke
emulator. Anda dapat menggunakan curl atau alat serupa. Misalnya, permintaan berikut akan mengimpor semua entity dari kumpulan file ekspor
entity ke emulator:
Mengimpor entity dari jenis dan namespace tertentu
Anda dapat menentukan filter entity untuk mengimpor entity hanya dari jenis atau
namespace tertentu. Anda hanya dapat menentukan filter entity jika ekspor dibuat menggunakan filter entity.
Tentukan jenis atau namespace dalam filter entity:
[KIND_NAMES] adalah daftar jenis: "kinds":["KIND_1", "KIND_2"]
[NAMESPACES] adalah daftar ID namespace:
"namespace_ids":["NAMESPACE_1", "NAMESPACE_2"]
Mengekspor entity di emulator
Fitur ekspor emulator memungkinkan Anda menyimpan entity di emulator ke dalam
serangkaian file ekspor entity. Selanjutnya, Anda dapat menggunakan operasi impor untuk memuat entity dalam file ekspor entity ke database mode Datastore atau ke instance emulator.
Untuk mengekspor entity dalam instance emulator, kirim permintaan ekspor POST ke
emulator. Anda dapat menggunakan curl atau alat serupa. Misalnya, permintaan berikut akan mengekspor semua entity di emulator:
Ubah localhost:8081 jika emulator menggunakan port yang berbeda.
dengan:
[PROJECT_ID] adalah ID project Anda.
[EXPORT_DIRECTORY] menentukan direktori tempat emulator menyimpan
file ekspor entity. Direktori ini tidak boleh berisi kumpulan file ekspor entity. Contoh:
Setelah file ekspor entity tersedia di bucket Cloud Storage, Anda dapat mengimpor data ke database seperti yang dijelaskan dalam Mengekspor dan mengimpor entity.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-19 UTC."],[[["\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)."]]