尝试在 Google App Engine 项目中创建备份时出现 404

404 when trying to create backup in a Google App Engine project

设置

我按照 未接受 问题的答案 AppEngine datastore - backup programatically

后遇到了 404 问题

我已按照一位回答提供者的建议启用了数据存储管理。我可以在 Google App Engine 控制台中手动触发数据存储备份,并且备份运行没有任何失败。

这个问题中的代码位于一个名为 'app' 的模块中。不是 'default'.

404问题

这是 cron.yaml 中的 cron 作业。

cron:
- description: Regular backup
  url: /_backup/fullbackup
  schedule: every 24 hours

url 的处理程序会将备份任务放入队列中,然后调用

_ah/datastore_admin/backup.create?
gs_bucket_name=%2Fgs%2Ftest.appspot.com%2F21-06-2015&kind=Test&kind=TestContent
&kind=TestDocument&filesystem=gs

(我在这里用 'test' 替换了我的应用程序 ID)

这在日志中显示 404 错误。

如果我在浏览器中使用上面的 url 和我的应用程序主机名(即 https://test.appspot.com/_ah/datastore_admin/backup.create? gs_bucket_name=%2Fgs%2Ftest.appspot.com%2F21-06-2015&kind=Test&kind=TestContent &kind=TestDocument&filesystem=gs),我也会收到 404。

这里是路由处理程序中的相关代码/_backup/fullbackup

    task = taskqueue.add(
        url='/_ah/datastore_admin/backup.create',
        method='GET',
        target='ah-builtin-python-bundle',
        params={
            'filesystem': 'gs',
            'gs_bucket_name': self.get_bucket_name(),
            'kind': (
                'Test',
                'TestContent',
                'TestDocument'
            )
        }
    )

问题:

编辑

内置数据存储管理已启用,如屏幕截图所示。

而且没有dispatch.yaml

你有enabled the Datastore Admin吗?您需要完成此操作才能允许模块 ah-builtin-python-bundle 存在,当您激活 Datastore 管理员时,这是您应用程序的一个特殊模块 "deployed",它实际上负责响应对 /_ah/datastore_admin 并生成 MapReduce 作业,这些作业从 Datastore 读取并在 Cloud Storage(或您将它们发送到的任何其他地方)中生成备份文件。

此外,另一种可能性是您使用了 test.appspot.com 硬编码到您的应用程序中。您是否拥有该应用程序 ID,"test"?从您在浏览器中看到的错误屏幕截图来看,您似乎正在尝试备份到存储桶“test.appspot.com”,这将是应用程序 ID [=25] 的应用程序的默认存储桶=].但是,在您显示的日志屏幕截图中,它还尝试备份到“example.appspot.com”存储桶。确保您的应用拥有这些存储桶。

另一种可能性是处理请求的模块不是 ah-builtin-python-bundle,而是另一个模块。如果您有 dispatch rule 正在重新路由请求,即使您在任务添加方法中指定了不同的目标,也可能会发生这种情况。

与队列配置问题有关。

'default' 队列定义存在于 app.yaml 之前执行定期备份。结果,备份任务没有达到目标 'ah-builtin-python-bundle'

如果我定义一个新队列

- name: data-backup
  rate: 1/s
  target: ah-builtin-python-bundle

然后使用这段代码插入任务,

    task = taskqueue.add(
        url='/_ah/datastore_admin/backup.create',
        method='GET',
        queue_name="data-backup",
        params={
            'filesystem': 'gs',
            'gs_bucket_name': self.get_bucket_name(),
            'kind': kinds_list  # A list of ndb model classes I want to backup
        }
    )

然后 Google 应用引擎可以创建备份集