Export from Google App Engine Datastore Backup LevelDB format to JSON flat file

Felix Barbalet
2019-06-30T05:56:26Z

export.py

| 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)