同事整理的命令,经常用到拿过来记录一下。
备份
mongodump --host dds-m5b42.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u root -p [password] -d [db] -o /www/db
恢复
mongorestore --host dds-mb42.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u root -p [password] -d [db] /www/db/game_center
备份Collection
mongodump --host dds-m842.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u root -p [password] -d [db] -c [collection] -o /www/db
恢复Collection
mongorestore --host dds-m511b.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u root -p [password] -d [db] -c [collection] /www/db/game_center/[collection.bson]
参数
-h or --host: mongodb // mongo连接地址
-u: username // 用户名
-p: password // 密码
-d: database // 要备份的数据库 或 要恢复的数据库名称
-c: collection // 要备份的collection 或 要恢复的collection
-o: savepath // 备份数据保存位置