项目作者: kieras

项目描述 :
Utilities for Google Cloud Datastore.
高级语言: Python
项目地址: git://github.com/kieras/google-cloud-datastore-utils.git
创建时间: 2018-01-08T16:14:52Z
项目社区:https://github.com/kieras/google-cloud-datastore-utils

开源协议:MIT License

下载


Google Cloud Datastore Utils

Utilities for Google Cloud Datastore.

Supported commands:

  • export: Export entities from any project/namespace to a file.
  • import: Import entities from a file into any project/namespace.

Installation

Simply run:

  1. pipsi install gcdu

Usage

To use it:

  1. gcdu --help

Export command:

  1. gcdu export -p [project] -n [namespace] -k [comma separated list of datastore kinds]

Import command:

  1. gcdu import -p [project] -n [namespace] -k [comma separated list of datastore kinds]

Authentication

You can execute the program with your user authenticated in the using gcloud:

  1. gcloud auth application-default login
  2. gcloud config set project PROJECT_ID

If you want, you can use a Service Account to authenticate by exporting the following variable:

  1. export GOOGLE_APPLICATION_CREDENTIALS='service-account-key.json'

Example execution of an import

  1. gcdu import --project my-project-stage --namespace e2e-20190313-192340 --data-dir=resources/database --kinds=AuditLog,Budget,BudgetBigqueryIntegration,BudgetChannel,BudgetCostCenter,BudgetEntity,BudgetGLCode,BudgetLocation,BudgetProduct,CurrencyCode,CurrencyEntity,Entry,FeatureToggle,LoadVersionControl,Settings,Submission,SubmissionForEmailCron,SubmissionLinePreview,SubmissionSequence,Team,Template,Transaction,User,Checkpoint,CostCenter,Header,OptionEntry,Question,QuestionAlias,BudgetQuarterSnapshot

Command output:

  1. Executing import. Project=my-project-stage, Namespace=e2e-20190313-192340, Kinds=[u'AuditLog', u'Budget', u'BudgetBigqueryIntegration', u'BudgetChannel', u'BudgetCostCenter', u'BudgetEntity', u'BudgetGLCode', u'BudgetLocation', u'BudgetProduct', u'CurrencyCode', u'CurrencyEntity', u'Entry', u'FeatureToggle', u'LoadVersionControl', u'Settings', u'Submission', u'SubmissionForEmailCron', u'SubmissionLinePreview', u'SubmissionSequence', u'Team', u'Template', u'Transaction', u'User', u'Checkpoint', u'CostCenter', u'Header', u'OptionEntry', u'Question', u'QuestionAlias', u'BudgetQuarterSnapshot'].
  2. Starting tasks...
  3. Done. 30 tasks started.
  4. Executing...
  5. Done. Kind=Template
  6. Done. Kind=Header
  7. Done. Kind=LoadVersionControl
  8. Done. Kind=Question
  9. Done. Kind=BudgetEntity
  10. Done. Kind=Checkpoint
  11. Done. Kind=User
  12. Done. Kind=BudgetLocation
  13. Done. Kind=Settings
  14. Done. Kind=BudgetCostCenter
  15. Done. Kind=FeatureToggle
  16. Done. Kind=BudgetChannel
  17. Done. Kind=BudgetGLCode
  18. Done. Kind=Team
  19. Done. Kind=BudgetProduct
  20. Done. Kind=OptionEntry
  21. Done. Kind=CostCenter
  22. Done. Kind=Budget
  23. Done. Kind=QuestionAlias
  24. Done. Kind=Transaction
  25. Done. Kind=CurrencyEntity
  26. Done. Kind=CurrencyCode
  27. Done. Kind=SubmissionSequence
  28. Done. Kind=BudgetQuarterSnapshot
  29. Done. Kind=SubmissionForEmailCron
  30. Done. Kind=SubmissionLinePreview
  31. Done. Kind=Submission
  32. Done. Kind=AuditLog
  33. Done. Kind=Entry
  34. Done. Kind=BudgetBigqueryIntegration
  35. Finished!

Notice that we previously exported the database (not shown here), and now we are importing it into another project and namespace.

Another nice thing is that export/import executes in parallel, starting a task for each entity separately.