一、简介

  说起来数据库的“备份-还原”,在RDBMS系统中,都有很好的支持,也有很多选项可以设置,功能强大,也能自动完成大部分的备份功能,只要当初设置好了就可以了。对于MongoDB文档型的数据库来说,情况有一些不一样。在MongoDB中,要想对数据进行备份操作,需要使用脚本来执行命令完成,还原的的工作也是一样的,这是它本身支持的“备份-还原”的工作,相对RDBMS系统来说,要简单很多,不能自动完成。真的不能进行设置,来自动完成“备份和还原”的操作吗?当然可以,只是我们需要使用第三的软件才可以,而且功能越强大的,收费有的就越多,免费的也有,功能一般了,但是完成“备份-还原”的工作没问题。

接下来我们就开始说说MongoDB自己的、原生态的“备份-还原”是如何实现的,脚本很简单。mongodump命名主要完成数据的备份工作,mongorestore命令主要完成数据库的还原操作。就这两个命名,是不是很简单,那就开始我们今天的正文吧。

二、数据库的备份和还原

1、MongoDB数据库的备份

1.1、mongodump命令脚本语法如下:

>./mongodump -h dbhost -d dbname -o dbdirectory

-h:--host【--host <hostname><:port>, -h <hostname><:port>】

MongoDB所在服务器地址,默认地址:localhost(127.0.0.1),当然也可以指定端口号:localhost:27017

-d:--db【--db <database>, -d <database>】

需要备份的数据库实例,例如:school,这个数据库是我自己建立的,所以是该备份的

-o:--out <path>【 --out <path>, -o <path>】

备份的数据存放位置,例如:./databaseBack,当然该目录需要提前建立,在备份完成后,系统自动在dump目录下建立一个test目录,这个目录里面存放该数据库实例的备份数据。

-u:--username <username>【--username <username>, -u <username>】

指定用于向使用认证的MongoDB数据库认证的用户名,与--password和--authenticationDatabase结合使用

-p:--password <password>【--password <password>, -p <password>】

指定用于向使用认证的MongoDB数据库认证的密码。与--username和 --authenticationDatabase选项结合使用。

-c:--collection <collection>【--collection <collection>, -c <collection>】

指定要备份的集合。如果不指定,则会将指定数据库或实例中的所有集合备份。

--port <port>:

指定MongoDB实例监听客户连接的TCP端口号。端口的默认值:27017

--gzip:

MongoDB3.2或者以上的版本,可以进行压缩输出,如果mongodump指定导出到目录,则该选项会将每个文件都压缩,并添加.gz后缀;如果mongodump指定导出到文档或标准输出流,则该选项会压缩到文档或输出流中

--authenticationDatabase:【--authenticationDatabase <dbname>】

如果您未指定身份验证数据库,则mongodump会假定指定要导出的数据库保存用户的凭据。如果您未指定要导出的身份验证数据库或数据库,则mongodump假定admin数据库保存用户的凭据。

--authenticationMechanism:【 --authenticationMechanism <name>】

默认值: SCRAM-SHA-1

1.2、实例代码

  1】、登陆MongoDB的客户端,查看school数据库当前的详情

            //登陆MongoDB的客户端
[root@linux bin]# ./mongo --host=192.168.127.130 --port=27017
MongoDB shell version v3.6.3
connecting to: mongodb://192.168.127.130:27017/
MongoDB server version: 3.6.3
Server has startup warnings:
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] //显示当前数据库列表
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
school 0.000GB //---这个数据库就是我们要备份的 //切换到school数据库
> use school
switched to db school //显示当前school数据库下有多个集合
> show tables
geoInstance
users //当前两个集合都有数据
> db.users.find()
{ "_id" : ObjectId("5b1e044733091e826f7c2c74"), "title" : "MongoDb Overview", "description" : "Mongodb is not sql database", "author" : "huangFeiHong", "url" : "http://www.huangfeihong.com", "tags" : [ "mongodb", "database", "NoSql" ], "likes" : 100, "quantity" : 4 }
{ "_id" : ObjectId("5b1e044733091e826f7c2c75"), "title" : "NoSql Overview", "description" : "No sql database is very fast", "author" : "huangFeiHong", "url" : "http://www.huangfeihong.com", "tags" : [ "mongodb", "database", "NoSql" ], "likes" : 10, "quantity" : 12 }
{ "_id" : ObjectId("5b1e044733091e826f7c2c76"), "title" : "Log4Net Overview", "description" : "log4net is not sql database", "author" : "linChong", "url" : "http://www.linchong.com", "tags" : [ "log", "net", "NoSQL" ], "likes" : 750, "quantity" : 6 }
{ "_id" : ObjectId("5b1e1bfb33091e826f7c2c77"), "title" : "MongoDb Higher", "description" : "Mongodb is not sql database", "author" : "huangFeiHong", "url" : "http://www.huangfeihong.com", "tags" : [ "mongodb", "database", "NoSql" ], "likes" : 120, "quantity" : 4 }
{ "_id" : ObjectId("5b1e1bfb33091e826f7c2c78"), "title" : "NoSql Redis Overview", "description" : "No sql database is very fast", "author" : "linChong", "url" : "http://www.linchong.com", "tags" : [ "redis", "database", "NoSql" ], "likes" : 30, "quantity" : 33 }
{ "_id" : ObjectId("5b1e1bfb33091e826f7c2c79"), "title" : "Memcached Overrivew", "description" : "Memcached is sql database", "author" : "wuSong", "url" : "http://www.wusong.com", "tags" : [ "memcached", "cache", "NoSQL" ], "likes" : 50, "quantity" : 10 }
>
>
> db.geoInstance.find()
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e03"), "loc" : [ 1, 3 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e04"), "loc" : [ 3, 4 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e05"), "loc" : [ 0, -3 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e06"), "loc" : [ -6, 2 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e07"), "loc" : { "x" : 9, "y" : 5 } }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e08"), "loc" : { "lng" : -9.2, "lat" : 21.3 } }

  2】、退出MongoDB的客户端,我们要创建保存备份文件的目录

            //退出MongoDB的客户端
> exit
bye
[root@linux bin]# //当前目录结构
[root@linux bin]# pwd
/root/application/program/mongodb/mongodb-linux-x86_64-3.6.3/bin
[root@linux bin]# databaseBack //创建保存备份文件的目录名称 //已经创建好的目录结构,databaseBack是备份目录
[root@linux bin]# ls
bsondump datas logs mongod mongodump mongofiles mongoperf mongorestore mongostat
databaseBack install_compass mongo mongodb.conf mongoexport mongoimport mongoreplay mongos mongotop

  3】、开始备份数据库,因为我们使用的是客户端,要写完整的地址,在MongoDB服务器端就可以省略

            //代码很简单
[root@linux bin]# ./mongodump -h 192.168.127.130:27017 -d school -o ./databaseBack
2018-06-13T11:50:00.816+0800 writing school.geoInstance to
2018-06-13T11:50:00.817+0800 writing school.users to
2018-06-13T11:50:00.821+0800 done dumping school.geoInstance (6 documents)
2018-06-13T11:50:00.821+0800 done dumping school.users (6 documents) //查看备份文件
[root@linux bin]# ls ./databaseBack
school
[root@linux bin]# ls ./databaseBack/school
geoInstance.bson geoInstance.metadata.json users.bson users.metadata.json

  4】、以下操作将创建一个只包含名为school的数据库中名为users的集合的转储文件。 在这种情况下,数据库在端口27017上的192.168.127.130运行:

            [root@linux bin]# ./mongodump -h 192.168.127.130:27017 --db school --collection users -o ./backCollection
2018-06-13T13:40:46.702+0800 writing school.users to
2018-06-13T13:40:46.706+0800 done dumping school.users (6 documents)
[root@linux bin]# ls ./backCollection
school
[root@linux bin]# ls ./backCollection/school
users.bson users.metadata.json
[root@linux bin]#

  5】、要将转储输出到存档文件,请使用--archive选项和存档文件名运行mongodump。 例如,以下操作将创建一个包含school数据库转储的文件school.20180613.archive。

            [root@linux bin]# ./mongodump -h 192.168.127.130:27017 --archive=./backArchiveFile/school.2018613.archive --db school
2018-06-13T13:57:51.953+0800 writing school.geoInstance to archive './backArchiveFile/school.2018613.archive'
2018-06-13T13:57:51.955+0800 writing school.users to archive './backArchiveFile/school.2018613.archive'
2018-06-13T13:57:51.994+0800 done dumping school.geoInstance (6 documents)
2018-06-13T13:57:51.997+0800 done dumping school.users (6 documents)
[root@linux bin]# ls ./backArchiveFile/
school.2018613.archive

          6】、要压缩输出转储目录中的文件,请使用新的--gzip选项运行mongodump。 例如,以下操作将压缩文件输出到默认转储目录。

            [root@linux bin]# ./mongodump -h 192.168.127.130:27017 --db school --gzip -o ./backZip
2018-06-13T14:04:39.674+0800 writing school.geoInstance to
2018-06-13T14:04:39.675+0800 writing school.users to
2018-06-13T14:04:39.682+0800 done dumping school.geoInstance (6 documents)
2018-06-13T14:04:39.684+0800 done dumping school.users (6 documents) //显示压缩文件
[root@linux bin]# ls ./backZip/school
geoInstance.bson.gz geoInstance.metadata.json.gz users.bson.gz users.metadata.json.gz

          7】、想要通过mongodump命令将压缩的文件输出到指定目录,请将--gzip选项与--archive选项一起使用,并指定压缩文件的名称。

            [root@linux bin]# ./mongodump -h 192.168.127.130:27017 --archive=./backZip/school.2018613.gz --db school --gzip
2018-06-13T14:08:57.311+0800 writing school.geoInstance to archive './backZip/school.2018613.gz'
2018-06-13T14:08:57.312+0800 writing school.users to archive './backZip/school.2018613.gz'
2018-06-13T14:08:57.346+0800 done dumping school.geoInstance (6 documents)
2018-06-13T14:08:57.349+0800 done dumping school.users (6 documents) [root@linux bin]# ls ./backZip/
school.2018613.gz

    2、MongoDB数据库的还原

  2.1、mongorestore命令脚本语法如下:

     >mongorestore -h <hostname><:port> -d dbname <path>

--host <:port>, -h <:port>:

MongoDB所在服务器地址,默认为: localhost:27017

--db , -d :

需要恢复的数据库实例,例如:school,当然这个名称也可以和备份时候的不一样,比如school3

--drop:

还原的时候,先删除当前的数据,然后还原备份的数据。也就是说,还原后,成功备份之后再添加或者修改的数据都会被删除,慎用哦!

<path>:

mongorestore 最后的一个参数,设置备份数据所在位置,如:./databaseBack

你不能同时指定 <path> 和 --dir 选项,--dir也可以设置备份目录。

--dir:

指定备份数据的目录地址

你不能同时指定 <path> 和 --dir 选项。

 2.2、示例代码

          1】、上文已经成功备份了数据库,现在我们要登陆MongoDB客户端把我们的school数据库删除。

            //登陆MongoDB客户端,显示当前数据库列表
[root@linux bin]# ./mongo --host=192.168.127.130 --port=27017
MongoDB shell version v3.6.3
connecting to: mongodb://192.168.127.130:27017/
MongoDB server version: 3.6.3
Server has startup warnings:
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten]
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
school 0.000GB
> //删除school数据库
> use school
switched to db school
> db.dropDatabase()
{ "dropped" : "school", "ok" : 1 }
>
>
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> //退出MongoDB客户端
> exit
bye
[root@linux bin]#

          2】、我们开始还原我们的school数据库吧,我们从集合来恢复数据库。

            //还原users集合
[root@linux bin]# ./mongorestore -h 192.168.127.130:27017 --collection users --db school ./databaseBack/school/users.bson
2018-06-13T13:16:52.118+0800 checking for collection data in databaseBack/school/users.bson
2018-06-13T13:16:52.120+0800 reading metadata for school.users from databaseBack/school/users.metadata.json
2018-06-13T13:16:52.148+0800 restoring school.users from databaseBack/school/users.bson
2018-06-13T13:16:52.218+0800 no indexes to restore
2018-06-13T13:16:52.218+0800 finished restoring school.users (6 documents)
2018-06-13T13:16:52.219+0800 done //还原geoInstance集合
[root@linux bin]# ./mongorestore -h 192.168.127.130:27017 --collection geoInstance --db school ./databaseBack/school/geoInstance.bson
2018-06-13T13:18:26.353+0800 checking for collection data in databaseBack/school/geoInstance.bson
2018-06-13T13:18:26.358+0800 reading metadata for school.geoInstance from databaseBack/school/geoInstance.metadata.json
2018-06-13T13:18:26.386+0800 restoring school.geoInstance from databaseBack/school/geoInstance.bson
2018-06-13T13:18:26.456+0800 restoring indexes for collection school.geoInstance from metadata
2018-06-13T13:18:26.475+0800 finished restoring school.geoInstance (6 documents)
2018-06-13T13:18:26.475+0800 done

          3】、查看一下我们还原的数据。       

            [root@linux bin]# ./mongo --host=192.168.127.130 --port=27017
MongoDB shell version v3.6.3
connecting to: mongodb://192.168.127.130:27017/
MongoDB server version: 3.6.3
Server has startup warnings:
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten]
>
>
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
school 0.000GB
>
>
> use school
switched to db school
>
> show tables
geoInstance
users
>
>
> db.users.find()
{ "_id" : ObjectId("5b1e044733091e826f7c2c74"), "title" : "MongoDb Overview", "description" : "Mongodb is not sql database", "author" : "huangFeiHong", "url" : "http://www.huangfeihong.com", "tags" : [ "mongodb", "database", "NoSql" ], "likes" : 100, "quantity" : 4 }
{ "_id" : ObjectId("5b1e044733091e826f7c2c75"), "title" : "NoSql Overview", "description" : "No sql database is very fast", "author" : "huangFeiHong", "url" : "http://www.huangfeihong.com", "tags" : [ "mongodb", "database", "NoSql" ], "likes" : 10, "quantity" : 12 }
{ "_id" : ObjectId("5b1e044733091e826f7c2c76"), "title" : "Log4Net Overview", "description" : "log4net is not sql database", "author" : "linChong", "url" : "http://www.linchong.com", "tags" : [ "log", "net", "NoSQL" ], "likes" : 750, "quantity" : 6 }
{ "_id" : ObjectId("5b1e1bfb33091e826f7c2c77"), "title" : "MongoDb Higher", "description" : "Mongodb is not sql database", "author" : "huangFeiHong", "url" : "http://www.huangfeihong.com", "tags" : [ "mongodb", "database", "NoSql" ], "likes" : 120, "quantity" : 4 }
{ "_id" : ObjectId("5b1e1bfb33091e826f7c2c78"), "title" : "NoSql Redis Overview", "description" : "No sql database is very fast", "author" : "linChong", "url" : "http://www.linchong.com", "tags" : [ "redis", "database", "NoSql" ], "likes" : 30, "quantity" : 33 }
{ "_id" : ObjectId("5b1e1bfb33091e826f7c2c79"), "title" : "Memcached Overrivew", "description" : "Memcached is sql database", "author" : "wuSong", "url" : "http://www.wusong.com", "tags" : [ "memcached", "cache", "NoSQL" ], "likes" : 50, "quantity" : 10 }
>
>
> db.geoInstance.find()
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e03"), "loc" : [ 1, 3 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e04"), "loc" : [ 3, 4 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e05"), "loc" : [ 0, -3 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e06"), "loc" : [ -6, 2 ] }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e07"), "loc" : { "x" : 9, "y" : 5 } }
{ "_id" : ObjectId("5b1f4d21cf30d7cba03d5e08"), "loc" : { "lng" : -9.2, "lat" : 21.3 } }

          4】、我们可以使用nsInclude参数来恢复指定集合的数据。

            [root@linux bin]# ./mongorestore -h 192.168.127.130:27017 --nsInclude school.users ./databaseBack/
2018-06-13T14:19:59.942+0800 preparing collections to restore from
2018-06-13T14:19:59.946+0800 reading metadata for school.users from databaseBack/school/users.metadata.json
2018-06-13T14:19:59.970+0800 restoring school.users from databaseBack/school/users.bson
2018-06-13T14:19:59.977+0800 no indexes to restore
2018-06-13T14:19:59.977+0800 finished restoring school.users (6 documents)
2018-06-13T14:19:59.977+0800 done //这是在有数据的情况下执行恢复
[root@linux bin]# ./mongorestore -h 192.168.127.130:27017 --nsInclude school.users ./databaseBack/
2018-06-13T14:21:10.743+0800 preparing collections to restore from
2018-06-13T14:21:10.747+0800 reading metadata for school.users from databaseBack/school/users.metadata.json
2018-06-13T14:21:10.748+0800 restoring school.users from databaseBack/school/users.bson
2018-06-13T14:21:10.755+0800 error: multiple errors in bulk operation:
- E11000 duplicate key error collection: school.users index: _id_ dup key: { : ObjectId('5b1e044733091e826f7c2c74') }
- E11000 duplicate key error collection: school.users index: _id_ dup key: { : ObjectId('5b1e044733091e826f7c2c75') }
- E11000 duplicate key error collection: school.users index: _id_ dup key: { : ObjectId('5b1e044733091e826f7c2c76') }
- E11000 duplicate key error collection: school.users index: _id_ dup key: { : ObjectId('5b1e1bfb33091e826f7c2c77') }
- E11000 duplicate key error collection: school.users index: _id_ dup key: { : ObjectId('5b1e1bfb33091e826f7c2c78') }
- E11000 duplicate key error collection: school.users index: _id_ dup key: { : ObjectId('5b1e1bfb33091e826f7c2c79') } 2018-06-13T14:21:10.755+0800 no indexes to restore
2018-06-13T14:21:10.755+0800 finished restoring school.users (6 documents)
2018-06-13T14:21:10.755+0800 done

          5】、我们可以使用zip压缩文件,通过archive参数来恢复指定数据库的数据。

            [root@linux bin]# ./mongorestore -h 192.168.127.130:27017 --gzip --db school  --archive=./backZip/school.2018613.gz
2018-06-13T14:26:48.939+0800 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2018-06-13T14:26:49.591+0800 preparing collections to restore from
2018-06-13T14:26:50.041+0800 reading metadata for school.geoInstance from archive './backZip/school.2018613.gz'
2018-06-13T14:26:50.071+0800 restoring school.geoInstance from archive './backZip/school.2018613.gz'
2018-06-13T14:26:51.132+0800 restoring indexes for collection school.geoInstance from metadata
2018-06-13T14:26:51.150+0800 finished restoring school.geoInstance (6 documents)
2018-06-13T14:26:51.152+0800 reading metadata for school.users from archive './backZip/school.2018613.gz'
2018-06-13T14:26:51.181+0800 restoring school.users from archive './backZip/school.2018613.gz'
2018-06-13T14:26:51.837+0800 no indexes to restore
2018-06-13T14:26:51.838+0800 finished restoring school.users (6 documents)
2018-06-13T14:26:51.838+0800 done //以前已经删除了school数据库
[root@linux bin]# ./mongo --host 192.168.127.130 --port=27017
MongoDB shell version v3.6.3
connecting to: mongodb://192.168.127.130:27017/
MongoDB server version: 3.6.3
Server has startup warnings:
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-06-13T11:27:09.721+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten]
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-06-13T11:27:09.723+0800 I CONTROL [initandlisten]
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
school 0.000GB //数据库已经存在了,说明恢复成功

三、结束

  好了,就是这些了。MongoDB的备份和还原还是有很多内容的,mongodump和mongorestore命令有很多参数可以去配置,今天只是一个初步认知,如果大家想查看更详细的内容,可以查看英文的网站。地址如下:https://docs.mongodb.com/manual/reference/program/mongodump/。不忘初心,继续努力吧。

mongodb 备份还原的更多相关文章

  1. mongodb 备份 还原 导出 导入

    张映 发表于 2013-12-03 分类目录: nosql 标签:mongodb, 备份, 导入, 导出, 还原 mongodb数据备份和还原主要分为二种,一种是针对于库的mongodump和mong ...

  2. 一次生产环境下MongoDB备份还原数据

    最近开发一个版本的功能当中用到了MongoDB分页,懒于造数据,于是就研究了下从生产环境上导出数据到本地来进行测试. 研究了一下,发现MongoDB的备份还原和MySQL语法还挺类似,下面请看详细介绍 ...

  3. mongodb备份还原

    备份:mongodump mongodump常用参数 --db:指定导出的数据库 --collection:指定导出的集合 --excludeCollection:指定不导出的集合 --host :远 ...

  4. Mongodb 备份 还原 导出 导入 等批量操作

    mongodb数据备份和还原主要分为二种,一种是针对于库的mongodump和mongorestore,一种是针对库中表的mongoexport和mongoimport. 一,mongodump备份数 ...

  5. mongodb备份还原脚本

    同步 echo off ,%-%date:~,%-%date:~,% set bak_dir=mongo_na_world_svn2win_%time_dir% set fromdb=db_erago ...

  6. MongoDB之整库备份还原单表collection备份还原

    MongoDB之整库备份还原单表collection备份还原 cd D:\MongoDB\bin 1整库备份: mongodump -h dbhost -d dbname -o dbdirectory ...

  7. 挖一挖MongoDB的备份与还原(实现指定时间点还原和增量备份还原)

    一  研究背景需求 目前作者所在公司的MongoDB数据库是每天凌晨做一次全库完整备份,但数据库出现故障时,只能保证恢复到全备时间点,比如,00:30 做的完整备份,而出现故障是下午18:00,那么现 ...

  8. MongoDB 备份与还原 mongodump、mongorestore

    目录 MongoDB 备份与还原 一. MongoDB 备份 1.mongodump 2 .cp 或者rsync 3.单节点意外关闭后,如何恢复数据 4.查看备份数据 二.MongoDB 还原 1.m ...

  9. mongodb 数据库操作--备份 还原 导出 导入(转)

    mongodb 数据库操作--备份 还原 导出 导入   -------------------MongoDB数据导入与导出------------------- 1.导出工具:mongoexport ...

随机推荐

  1. 一次使用 Redis 优化查询性能的实践

    因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,一次使用 Redis 优化查询性能的实践 应用背景 有一个应用需要上传一组ID到 ...

  2. email 解析 ,发送 邮件

    email 来源:https://blog.csdn.net/xyang81/article/details/7675160     详见此人其它mail 篇 参考2:http://lib.csdn. ...

  3. Sqlserver2012的数据导入到sqlserver2008或sqlserver2008R2

    我采取的是sql语句的方式 将Sqlserver2012的表结构导出成sql语句,数据也导出成sql语句 一.点击数据库名称右键=========>属性 二.导出表结构与数据为sql语句 htt ...

  4. Maven(四-2) Maven pom.xml 配置详解

    转载于:http://niuzhenxin.iteye.com/blog/2042102 什么是pom?    pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述 ...

  5. 在Spring使用junit注解进行单元测试

    在Spring中可以使用junit配合注解进行单元测试 一.常用注解 1.@RunWith(SpringJUnit4ClassRunner.class),让测试运行于spring测试环境2.@Cont ...

  6. 解决clion2016.3不能支持搜狗输入法的问题

    参考链接http://www.cnblogs.com/chentq/p/4975794.html 打开clion.sh在文件头部添加 export GTK_IM_MODULE=fcitx export ...

  7. git best practice

    1. https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud (atlassian家的git) 2. https: ...

  8. iconv()错误

    //转换字符编码过程中报错,数据会丢失,解决办法:设置第二个参数为gbk//IGNORE $strexport=iconv('UTF-8',"GBK",$strexport); $ ...

  9. [Selenium]怎样等待元素出现之后再消失,譬如Loading icon

    界面上有些元素是要先等它出现,再等它消失,譬如loading icon 这个是等多个loading icon出现后消失 /** * Wait for loading icon disappear in ...

  10. [Tools]SurveyMonkey

    做问卷调查,推荐一个好工具,免费的 SurveyMonkey : it's free, quick & easy! https://www.surveymonkey.com/