App Engine:将实时数据存储复制到本地开发数据存储区(仍可正常工作)

时间:2016-05-06 03:51:23

标签: google-app-engine google-cloud-storage google-cloud-datastore

以前可以通过使用bulkloader下载并上传到本地开发服务器来实现。但是,由于不支持oauth2,批量加载程序下载现在几个月都没有功能。

有些地方建议从云存储备份下载,并通过bulkloader或直接解析备份上传到本地数据存储。但是,这些都不再具有功能。 bulkloader方法抛出:

OperationalError: unable to open database file

用于读取备份文件的RecordsReader类在尝试读取第一条记录时到达文件末尾,导致没有记录被读取。

是否存在将实时数据存储区复制到本地开发数据存储区的当前功能方法?

2 个答案:

答案 0 :(得分:1)

RecordsReader在unix上完美运行。我前一天试过这个https://gist.github.com/jehna/3b258f5287fcc181aacf并且效果很好。

您应该在导入中添加您的Kinds实现并在数据存储交互式shell中运行它。 例如: 来自myproject.kinds_implementations导入MyKind 我删除了

for pp in dir(a): try: ppp = getattr(a, "_" + pp) if isinstance(ppp, db.Key): ppp._Key__reference.set_app(appname) ppp except AttributeError: """ It's okay """

它运作良好。在我的情况下,备份下载到多个目录中,所以我修改了对目录的访问。对于某些事情:

for directory in mypath: full_directory_path = join(mypath, directory) for sub_dir in listdir(directory_full_path): full_sub_dir_path = join(full_directory_path, sub_dir) onlyfiles = [ f for f in listdir(full_sub_dir_path) if isfile(join(mypath,f)) ] for file in onlyfiles:

如果您正在使用Windows,欢迎您在Windows上关注我关于RecordsReader的问题,希望有人会在那里回答Google datastore backup to local dev_appserver

编辑: 如果您将文件打开权限从“r”更改为“rb”

,则在Windows上运行良好

答案 1 :(得分:1)

虽然有一些注意事项,但是使用OAuth2的Python上仍然可以使用bulkloader。从实时应用程序下载时,刷新OAuth2令牌存在问题,因此如果您手动使用带有--oauth2_refresh_token的刷新令牌,则总下载时间限制为3600秒或3600 + 3600。

上传到开发服务器应用时,OAuth2将失败并显示401,因此需要编辑google.appengine.ext.remote_api.handler并删除' CheckIsAdmin'始终返回True作为解决方法:

def CheckIsAdmin(self):
  return True
  user_is_authorized = False
  ...

我赞成上述答案,因为此时它似乎是一个更强大的解决方案。