Created
June 30, 2019 05:56
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Thanks for this ! It helped me export some data from an old App Engine app that I'd been putting off doing for years. I've forked it with some extra instructions and tweaks to better export entity kinds and key paths (ie entity identifiers) for my purposes.