Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Mit den Import- und Exportfunktionen des Datastore-Emulators können Sie Daten aus der Datenbankinstanz exportieren und in den Emulator laden. Sie können auch Daten aus dem Emulator exportieren und in die Datenbank im Datastore-Modus laden.
Vorbereitung
Führen Sie die folgenden Schritte aus, bevor Sie die Import- oder Exportfunktionen des Datastore-Emulators verwenden:
Die Import- und Exportfunktionen sind für cloud-datastore-emulator Version 2.1.0 und höher verfügbar. Möglicherweise müssen Sie die Google Cloud CLI-Komponenten aktualisieren.
Achten Sie bei Importvorgängen darauf, dass sich die Exportdateien der Entität auf demselben Computer wie der Emulator befinden.
Entitäten in den Emulator importieren
Mit der Importfunktion des Emulators können Sie Entitäten aus einer Reihe von Entitätsexportdateien in den Emulator laden. Die Entitätsexportdateien können aus einem Export der Datenbank im Datastore-Modus oder aus einer Emulatorinstanz stammen.
Senden Sie eine POST-Importanfrage an den Emulator, um Entitäten in den Emulator zu importieren. Dazu können Sie curl oder ein ähnliches Tool verwenden. Mit der folgenden Anfrage werden z. B. alle Entitäten aus einer Reihe von Entitätsexportdateien in den Emulator importiert:
Entitäten aus bestimmten Arten und Namespaces importieren
Sie können einen Entitätsfilter angeben, um Entitäten nur aus bestimmten Arten oder Namespaces zu importieren. Ein Entitätsfilter lässt sich nur dann angeben, wenn der Export mit einem Entitätsfilter erstellt wurde.
Geben Sie Arten oder Namespaces in einem Entitätsfilter an:
[KIND_NAMES] ist eine Liste von Arten: "kinds":["KIND_1", "KIND_2"]
[NAMESPACES] ist eine Liste von Namespace-IDs:
"namespace_ids":["NAMESPACE_1", "NAMESPACE_2"]
Entitäten im Emulator exportieren
Mit der Exportfunktion des Emulators können Sie Entitäten im Emulator in einer Reihe von Entitätsexportdateien speichern. Danach können Sie die Entitäten in den Entitätsexportdateien über einen Importvorgang in die Datenbank im Datastore-Modus oder in eine Emulatorinstanz laden.
Senden Sie eine POST-Exportanfrage an den Emulator, um Entitäten in einer Emulatorinstanz zu exportieren. Dazu können Sie curl oder ein ähnliches Tool verwenden. Mit der folgenden Anfrage werden z. B. alle Entitäten im Emulator exportiert:
Ändern Sie localhost:8081, wenn vom Emulator ein anderer Port verwendet wird.
Dabei gilt:
[PROJECT_ID] ist die ID des Projekts.
[EXPORT_DIRECTORY] gibt das Verzeichnis an, in dem die Entitätsexportdateien vom Emulator gespeichert werden. Dieses Verzeichnis darf noch keine Entitätsexportdateien enthalten. Beispiel:
Sobald die Entitätsexportdateien in einem Cloud Storage-Bucket verfügbar sind, können Sie die Daten in die Datenbank importieren, wie unter Entitäten exportieren und importieren beschrieben.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)."]]