Giter VIP home page Giter VIP logo

datastore-backup's Introduction

datastore-backup

Load a backup of Google Datastore into your local dev_appserver.py

Steps

  1. Create the backup
  2. Download the backup
  3. Re-hydrate the backup data into ndb.Model entities

Detailed Steps

  1. Create a backup of datastore in a Google Cloud Storage bucket using one of the following methods. (~5 minutes + backup time)

    1. Instructions for creating backup
    2. Instructions for creating periodic backup (Alpha)
  2. Download the backup from the Google Cloud Storage bucket created in the above step.

    1. Install and setup the Google Cloud Tools. The easiest way to do so is to download the bucket using gsutil (available here as the latest Google Cloud SDK).
    2. Switch to the project that contains the backups.
      # List out all the projects you have
      > gcloud projects list
      
      # switch active configuration to example-project-name
      > gcloud config set project example-project
    3. Download the actual bucket using the name of the bucket that you specified in step 1.
      # This will download the specified bucket to `.ds_backup`
      > ./dsbackup.py <bucket_name>
  3. Use the same APPLICATION_ID on your dev_appserver or webtest that you use on your production server. This can be done by setting the APPLICATION_ID on your testbed test or setting the APPLICATION_ID as an environment variable in your dev_appserver. Note that your APPLICATION_ID in production seems to be "s~" + <project_id>. So this project's APPLICATION_ID would be s~example-project.

  4. Hydrate the backup into Datastore entities in test or within dev_appserver using the following guiding example.

    from google.appengine.api.files import records
    from google.appengine.datastore import entity_pb
    from google.appengine.ext import ndb
    import dsbackup
    
    # Be sure to import all the ndb.Models that your project needs to hydrate!
    # This project only has `User` `ndb.Model`'s so the following is needed:
    from user import User # user.py not included (only example)
    
    def hydrate():
        for f in dsbackup.get_files():
            raw = open(f, 'r')
            reader = records.RecordsReader(raw)
            for record in reader:
                entity_proto = entity_pb.EntityProto(contents=record)
                entity = ndb.Model._from_pb(entity_proto)
                entity.put()

datastore-backup's People

Contributors

samedhi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.