【问题标题】:mongodump and mongorestore on PythonAnywherePythonAnywhere 上的 mongodump 和 mongorestore
【发布时间】:2020-05-30 02:12:33
【问题描述】:

我正在使用 PythonAnywhere 来托管我的 Web 应用程序。使用 Mongodb 作为我的数据库。现在我的任务是定期进行备份,并随时恢复特定版本的 mongodb。

要在本地(Windows 机器)上执行此操作,非常简单。安装 Mongodb 实用程序并执行命令

mongodump --mongodbConnectionString   //From location where this executable is stored
mongorestore --mongodbConnectionString

现在我的挑战是从 PythonAnywhere 完成。在这里我应该如何使用这些实用程序?


我有来自 mongodb site 的 mongodb 的 Linux 可执行文件,我从中提取了 bin 文件夹,如下所示

现在我将这个 bin 文件夹移动到 PythonAnywhere 并尝试执行 mongodump 命令

~/../applications/mongodb-linux-x86_64-ubuntu1404-3.4.0/bin$ ./mongodump mongodbConnectionString

失败并出现以下错误

bash: ./mongodump: 权限被拒绝

我的问题是如何从 PythonAnywhere 执行 mongodump 和 mongorestore?我的最终目标是定期备份 mongodb 数据库

【问题讨论】:

  • 试试:sudo chmod u+x mongodump
  • 嘿@Valijon,感谢您的回复,但在pythonanywhere环境中我们不能使用sudo命令pythonanywhere.com/forums/topic/13178
  • 我的意思是:Now I moved this bin folder to PythonAnywhere 你是用 shell 做的吗?如果是,您需要正确设置权限、所有者、组等...
  • 是的,我设置了适当的权限,现在我可以转储 mongodb 数据库了
  • @Valijon,感谢您的评论,它帮助我解决了我的问题,写一个答案我会接受的。我也在写我自己的问题的答案,这将给出有关 mongodb 备份和恢复的所有步骤

标签: linux mongodb web2py pythonanywhere mongodump


【解决方案1】:

由于在 PythonAnywhere 环境下关于 mongodb 备份和恢复的文档较少,所以在这里写下在 PythonAnywhere 上备份和恢复 mongodb 的所有步骤。


先决条件:您需要 Pythonanywhere 帐户和 Mongodb 连接字符串。


在 PythonAnywhere 上备份和恢复 mongodb 的步骤:

  1. 从 mongodb 站点下载适用于 Linux 机器的 mongodumpmongorestore 可执行文件 https://www.mongodb.org/dl/linux/x86_64-ubuntu1404

    我下载了mongodb-linux-x86_64-ubuntu1404-4.0.16,因为我用的是MongoDB 4.0

  2. 解压并将所需文件(如mongodumpmongorestore)上传到PythonAnywhere 的特定目录位置。

  3. 上传这些文件后,更新其权限。我是windows用户,所以使用WinSCP -> right click to file -> properties -> Select Groups/Owner permission.更新权限

  4. 从 PythonAnywhere 打开 Bash 控制台,转到您存储 mongodump 的目录并执行以下命令

    ~directory of your bin folder$ ./mongodump mongodb_connection_string.


我得到 bash: ./mongodump: Permission denied,因为我没有给这些文件适当的权限。

【讨论】:

  • 看起来你已经解决了!一件事可以帮助解决同样问题的其他人——您确实不需要需要使用sudo 来更改文件的权限。只要chmod +x filename 就足够了,只要您拥有该文件——如果您上传了它,您就拥有了。 (这实际上是 WinSCP 在幕后所做的事情。)
【解决方案2】:

您需要在 PythonAnywhere 中正确设置 MongoDB 二进制文件。

通常,由于权限错误,执行失败。

Make sure:
- You have execution permissions (chmod u+x file)
- Binnaries have proper owner    (chown user file)
- Binnaries have proper group    (chgrp group file)

注意:您需要sudoer 才能授予此类权限

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 1970-01-01
    相关资源
    最近更新 更多