Exporta una copia de todas las entidades o un subconjunto de ellas
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Exporta una copia de todas las entidades o de un subconjunto de ellas desde Datastore a otro sistema de almacenamiento, como Cloud Storage.
Muestra de código
Salvo que se indique lo contrario, el contenido de esta página está sujeto a la licencia Atribución 4.0 de Creative Commons, y los ejemplos de código están sujetos a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","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)."]]