Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Com os recursos de importação e exportação do emulador do Datastore, é possível
exportar dados de sua instância de banco de dados e carregá-los no emulador ou
exportar dados do emulador e carregá-los no
banco de dados do modo Datastore.
Antes de começar
Para usar estes recursos do emulador do Datastore,
faça o seguinte:
Os recursos de importação e exportação estão disponíveis para cloud-datastore-emulator
nas versões 2.1.0 e mais recentes. Talvez seja necessário atualizar os componentes da Google Cloud CLI.
Em operações de importação, verifique se os arquivos de exportação da entidade estão na mesma máquina que o emulador.
Importar entidades para o emulador
O recurso de importação do emulador permite carregar entidades de um conjunto de arquivos de exportação da entidade no emulador. Os arquivos de exportação da entidade podem ser provenientes de uma exportação do
banco de dados do modo Datastore ou de uma instância do emulador.
Para importar entidades para o emulador, envie uma solicitação de importação POST ao emulador. Use curl ou uma ferramenta semelhante. Por exemplo, esta solicitação importará todas as entidades de um conjunto de arquivos de exportação da entidade para o emulador:
Importar entidades de tipos e namespaces específicos
É possível especificar um filtro de entidade para importar entidades apenas de determinados tipos ou namespaces. Você só poderá especificar um filtro de entidade se a exportação tiver sido criada com o uso de um filtro de entidade.
Especifique tipos ou namespaces em um filtro de entidade:
[KIND_NAMES] é uma lista de tipos: "kinds":["KIND_1", "KIND_2"]
[NAMESPACES] é uma lista de IDs de namespace:
"namespace_ids":["NAMESPACE_1", "NAMESPACE_2"]
Exportar entidades no emulador
O recurso de exportação do emulador permite salvar entidades no emulador em um conjunto de arquivos de exportação da entidade. Em seguida, use uma operação de importação para carregar as
entidades nos arquivos de exportação da entidade no banco de dados do modo Datastore ou
em uma instância do emulador.
Para exportar entidades em uma instância de emulador, envie uma solicitação de exportação POST ao emulador. Use curl ou uma ferramenta semelhante. Por exemplo, esta solicitação exportará todas as entidades no emulador:
Modifique localhost:8081 se o emulador usar uma porta diferente.
em que:
[PROJECT_ID] é o ID do projeto;
[EXPORT_DIRECTORY] especifica o diretório em que o emulador salvará os
arquivos de exportação da entidade. Esse diretório não pode conter um conjunto de
arquivos de exportação da entidade. Exemplo:
Quando os arquivos de exportação da entidade estiverem disponíveis em um bucket do Cloud Storage,
importe os dados para o banco de dados, conforme descrito em
Como exportar e importar entidades.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-03 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)."]]