3

I created a backup of all entities of all namespaces using Google Cloud Datastore Admin.

I would like to ask if can I restore entities only on a namespace.

Example: I have 3 namespaces

  • Namespace_1
  • Namespace_2
  • Namespace_3

All namespaces contain the same entity kind let's say MyEntityKind

I would like to restore only Namespace_3.MyEntityKind from my full backup

How can I do that? In Datastore Admin, I can only select kind but not namespace when doing a restoration.

Thanks

joem
  • 31
  • 1
  • 4
  • I'm not sure, but a possible solution to your problem is that it may not matter. The way the backup functions is that it will overwrite any existing entities with the backed up data, and create them if they do not exist. If there are entities that are in the datastore which are not in the backup, they will be left unchanged. So if you have never edited your datastore data, and your only concern is losing the new entities that were created since the backup, then you can just go ahead and restore from backup and you will not lose any data that was added since you took the backup. – KevinG Jun 23 '17 at 00:30

1 Answers1

2

Overview

Datastore Admin backup is being phased out, so using the new managed exports functionality, although the same principles apply.

Create a new project, let's call it staging. Import the full backup into staging. Create a new export from staging for just the namespace or kind you want. Import this new export into your original project.

Commands

A full export in the new system is achieved as such:

gcloud datastore export gs://${BUCKET}

When exported like this, there isn't a direct method to import select parts, so you need to switch project, then import it a staging project. The importing command is straightforward:

gcloud datastore import gs://${BUCKET}/[PATH]/[FILE].overall_export_metadata

[PATH] can be found from the results from the export command, or browsing your Cloud Stage bucket in the console. [FILE] is the same as [PATH], but you can confirm in the UI.

Now, export the just the namespace you want from the staging project:

gcloud datastore export --namespaces="Namespace_3" gs://${BUCKET}

You now have an export with just the namespace you want, and can import it back into the original project.

Community
  • 1
  • 1
Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
  • Re: restore from backup (a.k.a. import), is there a way to just import certain entity kinds only? Just read the [docs](https://cloud.google.com/datastore/docs/export-import-entities#importing_entities), and looks like we can select certain kinds for exports, but not imports... – xiaolong Oct 29 '18 at 19:06
  • @xiaolong It appears the Datastore Admin API [`import`](https://cloud.google.com/datastore/docs/reference/admin/rest/v1/projects/import)method accepts an *entityFilter* parameter. I have not tested this functionality. – Lee Jan 08 '19 at 13:18