在Ubuntu下備份MongoDB數據庫,可以使用mongodump
工具。以下是備份的步驟:
打開終端(Terminal)。
確保已經安裝了MongoDB。如果沒有,請參考官方文檔進行安裝:https://docs.mongodb.com/manual/installation/ubuntu/
使用mongodump
命令進行備份。以下是一個基本的備份命令示例:
mongodump --host <hostname> --port <port> --username <username> --password <password> --authenticationDatabase admin --db <database_name> --out <output_directory>
請將<hostname>
、<port>
、<username>
、<password>
、<database_name>
和<output_directory>
替換為實際值。例如:
mongodump --host localhost --port 27017 --username myUser --password myPassword --authenticationDatabase admin --db myDatabase --out /backups/mongodb
這個命令將會備份名為myDatabase
的數據庫,并將備份文件存儲在/backups/mongodb
目錄中。
<output_directory>
目錄下找到備份文件。這些文件通常以.bson
格式存儲。注意:如果你使用的是MongoDB Atlas云數據庫,你需要創建一個IAM用戶并為其分配適當的權限,然后使用該用戶的憑據進行備份。
更多關于mongodump
的詳細信息和選項,請參考官方文檔:https://docs.mongodb.com/database-tools/mongodump/