簡體   English   中英

PythonAnywhere 上的 mongodump 和 mongorestore

[英]mongodump and mongorestore on PythonAnywhere

我正在使用 PythonAnywhere 來托管我的 Web 應用程序。 使用 Mongodb 作為我的數據庫。 現在我的任務是定期進行備份並隨時恢復特定版本的 mongodb。

要在本地(Windows 機器)上執行此操作,很容易。 安裝 Mongodb 實用程序並執行命令

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

現在我的挑戰是從 PythonAnywhere 中完成。 這里我應該如何使用這些實用程序?


我有來自mongodb 站點的mongodb 的 Linux 可執行文件,我從中提取了 bin 文件夾,如下所示

在此處輸入圖片說明

現在我將此 bin 文件夾移動到 PythonAnywhere 並嘗試執行mongodump命令

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

它因以下錯誤而失敗

bash: ./mongodump: 權限被拒絕

我的問題是如何從 PythonAnywhere 執行 mongodump 和 mongorestore? 我的最終目標是定期備份mongodb數據庫

由於PythonAnywhere環境下mongodb備份和恢復的文檔比較少,所以把在PythonAnywhere上做mongodb備份和恢復的所有步驟寫在這里。


前提條件:需要 Pythonanywhere 賬號和 Mongodb 連接字符串。


在 PythonAnywhere 上備份和恢復 mongodb 的步驟:

  1. 從 mongodb 站點下載mongodump於 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.更新權限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 ,因為我沒有給這些文件適當的權限。

您需要在 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才能授予此類權限

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM