Esportazione e importazione dei dati dell'emulatore
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Utilizzando le funzionalità di importazione ed esportazione dell'emulatore Datastore, puoi esportare i dati dall'istanza del database e caricarli nell'emulatore. Puoi anche esportare i dati dall'emulatore e caricarli nel database in modalità Datastore.
Prima di iniziare
Prima di utilizzare le funzionalità di importazione o esportazione dell'emulatore Datastore,
completa quanto segue:
Le funzionalità di importazione ed esportazione sono disponibili per cloud-datastore-emulator
le versioni 2.1.0 e successive. Potresti dover aggiornare i componenti di Google Cloud CLI.
Per le operazioni di importazione, assicurati che i file di esportazione delle entità si trovino sulla stessa macchina dell'emulatore.
Importa le entità nell'emulatore
La funzionalità di importazione dell'emulatore ti consente di caricare le entità da un insieme di file di esportazione delle entità nell'emulatore. I file di esportazione delle entità possono provenire da un'esportazione del database in modalità Datastore o di un'istanza dell'emulatore.
Per importare le entità nell'emulatore, invia una richiesta di importazione POST all'emulatore. Puoi utilizzare curl o uno strumento simile. Ad esempio, la seguente richiesta importerà tutte le entità da un insieme di file di esportazione delle entità nell'emulatore:
Puoi specificare un filtro delle entità per importare entità solo da tipi o spazi dei nomi specifici. Puoi specificare un filtro delle entità solo se l'esportazione è stata creata utilizzando un filtro delle entità.
Specifica tipi o spazi dei nomi in un filtro delle entità:
[KIND_NAMES] è un elenco di tipi: "kinds":["KIND_1", "KIND_2"]
[NAMESPACES] è un elenco di ID spazio dei nomi:
"namespace_ids":["NAMESPACE_1", "NAMESPACE_2"]
Esportare le entità nell'emulatore
La funzionalità di esportazione dell'emulatore ti consente di salvare le entità nell'emulatore in un insieme di file di esportazione delle entità. Puoi quindi utilizzare un'operazione di importazione per caricare le entità nei file di esportazione delle entità nel database in modalità Datastore o in un'istanza dell'emulatore.
Per esportare le entità in un'istanza dell'emulatore, invia una richiesta di esportazione POST all'emulatore. Puoi utilizzare curl o uno strumento simile. Ad esempio, la seguente richiesta esporta tutte le entità nell'emulatore:
Modifica localhost:8081 se l'emulatore utilizza una porta diversa.
dove:
[PROJECT_ID] è l'ID del tuo progetto.
[EXPORT_DIRECTORY] specifica la directory in cui l'emulatore salva i file di esportazione delle entità. Questa directory non deve contenere già un insieme di file di esportazione delle entità. Ad esempio:
Una volta che i file di esportazione delle entità sono disponibili in un bucket Cloud Storage, puoi importare i dati nel tuo database come descritto in Esportare e importare entità.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-08 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)."]]