Home  >  Article  >  System Tutorial  >  How to import, export, backup and restore mongodb

How to import, export, backup and restore mongodb

WBOY
WBOYOriginal
2024-06-02 09:02:36792browse

mongodb 如何导入导出备份恢复

1. Back up Mongodb
mongodump -h RuiyIp -d dataname -o /home/aa/dev/mongodb/data

mongodump mongo Export database command mongodump --help You can view all the help under this command

    -h export source
    -d Database name to be exported
    -o The location where the database is to be exported

After the terminal scrolls through N lines, the database export is completed. You can go to the /home/aa/dev/mongodb/data directory to view the exported file, which is in bson format (I did not export it immediately after exporting. I saw the file, but it took a while for it to appear, for unknown reasons).

2. Restore using: mongorestore command
mongorestore -d cmsdev  /home/xx/dev/mongodb/data/cmsdev
    -d Database name used

Add the directory you just exported directly after it, so that all tables can be restored directly. If -c is to restore one table

3. Import
mongoimport -d my_mongodb -c user user.dat

Parameter Description:

    -d specifies the library to use, in this case "my_mongodb"
    -c specifies the table to be exported, in this case "user"

You can see that the table structure will be created implicitly when importing data

4. Export
mongoexport -d my_mongodb -c user -o user.dat

Parameter Description:

    -d specifies the library to use, in this case "my_mongodb"
    -c specifies the table to be exported, in this case "user"
    -o specifies the file name to be exported, in this case "user.dat"
    As you can see from the above, the export method uses the JSON style

The above is the detailed content of How to import, export, backup and restore mongodb. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn