Esportare una copia di tutte le entità o di un sottoinsieme di entità
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Esporta una copia di tutte le entità o di un sottoinsieme di entità da Datastore a un altro sistema di archiviazione, ad esempio Cloud Storage.
Esempio di codice
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
[[["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"]],[],[[["\u003cp\u003eThis page details how to export entities from Datastore to another storage system, such as Cloud Storage.\u003c/p\u003e\n"],["\u003cp\u003eCode samples are provided for C#, Go, Node.js, Python, and Ruby, demonstrating the process of exporting entities.\u003c/p\u003e\n"],["\u003cp\u003eThe export process can be configured to include all entities or a specific subset based on kind and namespace.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Datastore mode requires setting up Application Default Credentials, as detailed in the documentation.\u003c/p\u003e\n"],["\u003cp\u003eClient library information and API reference documentation are provided for each language, with links for further detail.\u003c/p\u003e\n"]]],[],null,["# Export a copy of all or a subset of entities\n\nExports a copy of all or a subset of entities from Datastore to another storage system, such as Cloud Storage.\n\nCode sample\n-----------\n\n### C#\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode C# API\nreference documentation](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.V1/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n using https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.html;\n using System;\n using System.Collections.Generic;\n\n public class ExportEntitiesSample\n {\n public string ExportEntities(\n string projectId = \"your-project-id\",\n string outputUrlPrefix = \"gs://your-bucket-name\",\n string kind = \"Task\",\n string namespaceId = \"default\")\n {\n // Create client\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html datastoreAdminClient = https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html#Google_Cloud_Datastore_Admin_V1_DatastoreAdminClient_Create();\n\n IDictionary\u003cstring, string\u003e labels = new Dictionary\u003cstring, string\u003e { { \"cloud_datastore_samples\", \"true\" }, };\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.EntityFilter.html entityFilter = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.EntityFilter.html\n {\n Kinds = { kind },\n NamespaceIds = { namespaceId }\n };\n\n var response = datastoreAdminClient.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.DatastoreAdminClient.html#Google_Cloud_Datastore_Admin_V1_DatastoreAdminClient_ExportEntities_Google_Cloud_Datastore_Admin_V1_ExportEntitiesRequest_Google_Api_Gax_Grpc_CallSettings_(projectId, labels, entityFilter, outputUrlPrefix);\n\n // Poll until the returned long-running operation is complete\n var completedResponse = response.PollUntilCompleted();\n\n if (completedResponse.IsFaulted)\n {\n Console.WriteLine($\"Error while Exporting Entities: {completedResponse.Exception}\");\n throw completedResponse.Exception;\n }\n\n Console.WriteLine($\"Entities exported successfully.\");\n\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.ExportEntitiesResponse.html result = completedResponse.Result;\n\n return result.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Datastore.Admin.V1/latest/Google.Cloud.Datastore.Admin.V1.ExportEntitiesResponse.html#Google_Cloud_Datastore_Admin_V1_ExportEntitiesResponse_OutputUrl;\n }\n }\n\n### Go\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Go API\nreference documentation](https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tadmin \"cloud.google.com/go/datastore/admin/apiv1\"\n \t\"cloud.google.com/go/datastore/admin/apiv1/adminpb\"\n )\n\n // entitiesExport exports a copy of all or a subset of entities from\n // Datastore to another storage system, such as Cloud Storage.\n func entitiesExport(w io.Writer, projectID, outputURLPrefix string) (*adminpb.ExportEntitiesResponse, error) {\n \t// projectID := \"project-id\"\n \t// outputURLPrefix := \"gs://bucket-name\"\n \tctx := context.Background()\n \tclient, err := admin.NewDatastoreAdminClient(ctx)\n \tif err != nil {\n \t\treturn nil, fmt.Errorf(\"admin.NewDatastoreAdminClient: %w\", err)\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest/admin/apiv1.html#cloud_google_com_go_datastore_admin_apiv1_DatastoreAdminClient_Close()\n\n \treq := &adminpb.ExportEntitiesRequest{\n \t\tProjectId: projectID,\n \t\tOutputUrlPrefix: outputURLPrefix,\n \t}\n \top, err := client.ExportEntities(ctx, req)\n \tif err != nil {\n \t\treturn nil, fmt.Errorf(\"ExportEntities: %w\", err)\n \t}\n \tresp, err := op.Wait(ctx)\n \tif err != nil {\n \t\treturn nil, fmt.Errorf(\"Wait: %w\", err)\n \t}\n \tfmt.Fprintln(w, \"Entities were exported\")\n \treturn resp, nil\n }\n\n### Node.js\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Node.js API\nreference documentation](https://cloud.google.com/nodejs/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const {Datastore} = require('https://cloud.google.com/nodejs/docs/reference/datastore/latest/overview.html');\n const datastore = new https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html();\n\n async function exportEntities() {\n /**\n * TODO(developer): Uncomment these variables before running the sample.\n */\n // const bucket = 'YOUR_BUCKET_NAME';\n\n const [exportOperation] = await datastore.https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html({bucket});\n await exportOperation.promise();\n\n // The export operation has created a new file in your bucket, e.g.\n // gs://{YOUR_BUCKET_NAME}/{timestamp}/{timestamp}.overall_export.metadata\n console.log(`Export file created: ${exportOperation.result.outputUrl}`);\n\n // You may also choose to include only specific kinds and namespaces.\n const [specificExportOperation] = await datastore.https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore.html({\n bucket,\n kinds: ['Employee', 'Task'],\n namespaces: ['Company'],\n });\n await specificExportOperation.promise();\n console.log(specificExportOperation.result.outputUrl);\n }\n\n exportEntities();\n\n### Python\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Python API\nreference documentation](https://cloud.google.com/python/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def export_entities(project_id, output_url_prefix):\n \"\"\"\n Exports a copy of all or a subset of entities from\n Datastore to another storage system, such as Cloud Storage.\n \"\"\"\n # project_id = \"project-id\"\n # output_url_prefix = \"gs://bucket-name\"\n client = DatastoreAdminClient()\n\n op = client.export_entities(\n {\"project_id\": project_id, \"output_url_prefix\": output_url_prefix}\n )\n response = op.result(timeout=300)\n\n print(\"Entities were exported\\n\")\n return response\n\n### Ruby\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Ruby API\nreference documentation](/ruby/docs/reference/google-cloud-datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n # project_id = \"project-id\"\n # output_url_prefix = \"gs://bucket-name\"\n op = client.export_entities project_id: project_id, output_url_prefix: output_url_prefix\n\n op.wait_until_done!\n raise op.error.message if op.error?\n\n response = op.response\n # Process the response.\n\n metadata = op.metadata\n # Process the metadata.\n\n puts \"Entities were exported\"\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=datastore)."]]