-
备份:(指定备份数据库备份至哪个目录)
-
[root@iZ2ze66bhrbxkc31nljgjnZ backdump]# /usr/local/mongodb/bin/mongodump -d rundb -o /soft/backdump/
-
[root@iZ2ze66bhrbxkc31nljgjnZ backdump]# ll
-
drwxr-xr-x 2 root root 4096 Apr 26 18:10 rundb
-
-
恢复:(恢复至某个数据库,不存在会创建,—drop参数恢复前先删除)
-
[root@iZ2ze66bhrbxkc31nljgjnZ backdump]# /usr/local/mongodb/bin/mongorestore -d rundb2 /soft/backdump/rundb/
-
-
-
备份所有数据库:
-
[root@iZ2ze66bhrbxkc31nljgjnZ backdump]# /usr/local/mongodb/bin/mongodump -o /soft/backdump/
-
-
恢复所有数据库:
-
[root@iZ2ze66bhrbxkc31nljgjnZ backdump]# /usr/local/mongodb/bin/mongorestore --drop --dir /soft/backdump/
-
-
-
-
备份不指定目录:
-
[root@iZ2ze66bhrbxkc31nljgjnZ backdump]# /usr/local/mongodb/bin/mongodump (会在当前目录下生成一个dump目录)
-
恢复:(会用默认的dump目录)
-
[root@iZ2ze66bhrbxkc31nljgjnZ backdump]# /usr/local/mongodb/bin/mongorestore --drop
-
2018-04-27T11:48:26.102+0800 using default 'dump' directory
-
2018-04-27T11:48:26.105+0800 building a list of dbs and collections to restore from dump dir
备份单个集合
[root@iZ2ze66bhrbxkc31nljgjnZ soft]# /usr/local/mongodb/bin/mongodump -d rundb -c col -o ./
恢复某个集合
[root@iZ2ze66bhrbxkc31nljgjnZ rundb]# /usr/local/mongodb/bin/mongorestore -d rundb --drop --dir /soft/rundb/col.bson