如何通过结合使用Mongodump工具和示例来转储Mongodb

Mongodb provides a lot of flexibilities to the application developers and system administrators. As we know mongodb is an nosql database server. Standard Sql database servers provides different tools to dump and backup given database. Mongodb provides mongodump tool for dump and backup operations.

Mongodb为应用程序开发人员和系统管理员提供了很多灵活性。 我们知道mongodb是一个nosql数据库服务器。 标准Sql数据库服务器提供了不同的工具来转储和备份给定的数据库。 Mongodb提供了用于转储和备份操作的mongodump工具。

检查MongoDB服务状态 (Check MongoDB Service Status)

First we should check the status of the mongodb. We can use systemctl command which is provided by popular Linux distributions.

首先,我们应该检查mongodb的状态。 我们可以使用流行Linux发行版提供的systemctl命令。

$  systemctl status mongod
Check MongoDB Service Status
Check MongoDB Service Status
检查MongoDB服务状态

转储MongoDb数据库(Dump MongoDb Database)

We only need to specify the hostname of the mongodb database server. We will use  --host option in order to specify the hostname. In this example we will dump remote host named poftut1 . This will backup all databases to the file named dump .

我们只需要指定mongodb数据库服务器的主机名即可。 我们将使用--host选项来指定主机名。 在此示例中,我们将转储名为poftut1远程主机。 这会将所有数据库备份到名为dump的文件中。

$ mongodump --host poftut1

仅转储指定的数据库 (Only Dump Specified Database)

We do not need to dump all databases. We can specify the database we want to dump. We will use --db option in order to specify the database name. In this example we will only dump the database named school

我们不需要转储所有数据库。 我们可以指定我们要转储的数据库。 我们将使用--db选项来指定数据库名称。 在此示例中,我们仅转储名为school的数据库

$ mongodump --host poftut1 --db school

仅转储特定集合 (Only Dump Specific Collection)

We can also specify specific collection. We will use --collection option in order to specify the collection’s name. In this example we will dump the collection named students in database school .

我们还可以指定特定的集合。 我们将使用--collection选项来指定集合的​​名称。 在此示例中,我们将名为“ students的集合转储到数据库school

$ mongodump --host poftut1 --db school --collection students

转储和压缩 (Dump and Compress)

Dumping big databases or collections will create a lot data with big size. If we need to do dump multiple times in a day the disk will be full. We can compress the dumped data by using gzip or similar compression tools. We will redirect the output of dump to the gzip with --out - option. In this example we also set the compressed dump name with the current date.

转储大型数据库或集合将创建大量大数据。 如果我们需要在一天内多次转储,则磁盘将满。 我们可以使用gzip或类似的压缩工具来压缩转储的数据。 我们将使用--out -选项将转储的输出重定向到gzip。 在此示例中,我们还将压缩转储名称设置为当前日期。

$ mongodump --host poftut1  --out - | gzip > dump_`date "+%Y-%m-%d"`.gz

For more information about compression look following tutorials.

有关压缩的更多信息,请参见以下教程。

LEARN MORE  How To Compress Files and Folders In File System Level With Compact Command In Windows NTFS?
了解更多信息如何在Windows NTFS中使用压缩命令在文件系统级别压缩文件和文件夹?

http://www.poftut.com/7z-command-tutorial-examples-compress-extract-files-linux/

http://www.poftut.com/7z-command-tutorial-examples-compress-extract-files-linux/

http://www.poftut.com/gzip-command-tutorial-examples-linux/

http://www.poftut.com/gzip-command-tutorial-examples-linux/

翻译自: https://www.poftut.com/dump-mongodb-using-mongodump-tool-examples/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值