Skip to content

Instantly share code, notes, and snippets.

@xlfe
Created June 30, 2019 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlfe/af25f160256e4d52f499dee7e8fa212f to your computer and use it in GitHub Desktop.
Save xlfe/af25f160256e4d52f499dee7e8fa212f to your computer and use it in GitHub Desktop.
Export from Google App Engine Datastore Backup LevelDB format to JSON flat file
import sys, os, json
import datetime
sys.path.append(os.path.expanduser('~/google-cloud-sdk/platform/google_appengine/'))
from google.appengine.api.files import records
from google.appengine.datastore import entity_pb
from google.appengine.api import datastore
def myconverter(o):
if isinstance(o, datetime.datetime):
return o.isoformat()
for path, dirs, files in os.walk('./'):
for fn in files:
f = os.path.join(path, fn)
if not fn.startswith('output'):
continue
with open(f, 'r') as raw:
reader = records.RecordsReader(raw)
for record in reader:
entity_proto = entity_pb.EntityProto(contents=record)
entity = datastore.Entity.FromPb(entity_proto)
entity['table'] = path[2:]
j = json.dumps(entity, default=myconverter)
print (j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment