我应该使用什么命令来创建我的数据库的MongoDB转储?


当前回答

使用mongodump:

$ ./mongodump --host prod.example.com
connected to: prod.example.com
all dbs
DATABASE: log    to   dump/log
        log.errors to dump/log/errors.bson
                713 objects
        log.analytics to dump/log/analytics.bson
                234810 objects
DATABASE: blog    to    dump/blog
        blog.posts to dump/log/blog.posts.bson
                59 objects
DATABASE: admin    to    dump/admin

来源:http://www.mongodb.org/display/DOCS/Import +出口+工具

其他回答

mongodb -h hostname -u dbusername -p dbpassword——db dbname——port portnumber——out /路径/文件夹

mongodb -h hostname -u dbusername -p dbpassword——db dbname——port portnumber——out /path/folder.gz

使用mongodump:

$ ./mongodump --host prod.example.com
connected to: prod.example.com
all dbs
DATABASE: log    to   dump/log
        log.errors to dump/log/errors.bson
                713 objects
        log.analytics to dump/log/analytics.bson
                234810 objects
DATABASE: blog    to    dump/blog
        blog.posts to dump/log/blog.posts.bson
                59 objects
DATABASE: admin    to    dump/admin

来源:http://www.mongodb.org/display/DOCS/Import +出口+工具

 Use -v to see progress of backup data
    mongodump -v --db dbname --out /pathforbackup/NewFolderforBackupData

 you can use it for restore also
    mongorestore -v --db dbname --drop /pathforbackup/NewFolderforBackupData/dbname

with multile v like -vvvv you will get more information

你也可以使用gzip备份一个集合,并在运行中压缩备份:

mongodump --db somedb --collection somecollection --out - | gzip > collectiondump.gz

或者在文件名中加上日期:

mongodump --db somedb --collection somecollection --out - | gzip > dump_`date "+%Y-%m-%d"`.gz

更新: 在date文件夹中备份数据库的所有集合。文件被gzip压缩:

mongodump --db somedb --gzip --out /backups/`date +"%Y-%m-%d"`

或者对于单个存档:

mongodump --db somedb --gzip --archive > dump_`date "+%Y-%m-%d"`.gz

或者mongodb在docker内部运行时:

docker exec <CONTAINER> sh -c 'exec mongodump --db somedb --gzip --archive' > dump_`date "+%Y-%m-%d"`.gz

在Windows中使用“path”,否则会给出错误:位置参数不允许