Copy the database copyDatabase () from mongodb (). Release disk space.

Source: Internet
Author: User
Tags mongodb

Db. copyDatabase ("from", "to", "127.0.0.1: 16161 ");

Replace the from library on 127.0.0.1. Copy to the to library.

This has an additional benefit. That is, the from database may have deleted the data. We know that the disk space will not be released when data is deleted. Refer to another article in the blog: the disk space is not released after mongodb deletes the set.

It can occupy a lot of disk space. Although you can use db. repairDatabase () to repair data. But this method has two bad points. 1. Accidental stopping of operations in production may cause the risk that data cannot be restored. 2. If the disk space is insufficient, it is smaller than the current space occupied by the db time. In this case, db. repairDatabase () cannot be used.

This section describes how to use db. copyDatabase to back up and copy data.

1. db. copyDatabase ("from", "to", "127.0.0.1: 16161"); copy a new to database. This is the minimum data used. Related data files to will be generated in the data directory.

2. Change the configuration of all programs from the from library to the to library. The test is correct.

3. You can delete the from database. Method. Use from and then db. dropDatabase (). The advantage of this method is that the data on the disk can be deleted in time. Save a lot of space.

If the disk is insufficient, refer to the above method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.