search

Home  >  Q&A  >  body text

How to safely transfer the collection and index files of mongodb collection to make space

Use mongodb to cache the source code of web pages captured by crawlers in a stand-alone environment. There are no replica sets, shards, etc. Mongodb is used purely for convenience and to improve storage efficiency.
Now a collection occupies more than 50G of space. The data has been extracted. It will not be used in the short term. However, it is not easy to capture it. It may be used later, so I don’t want to delete it. The problem is The hard disk is out of space. I want to transfer the collection and index files to the mobile hard disk and copy them back when needed or use the mobile hard disk directory as the data directory. But when I tested a newly created test set, I found that once these files were moved, mongod could not be started and had to be moved back before it could be started.

My question is:
1. How to ensure that the startup of mongod and the use of other collections (there are other collections in the data directory) will not be affected after moving the space-occupying collection and its corresponding index file.
2. If you are not copying the entire data directory, just copy the llection and index files are copied to the new directory. If the new directory is used as the data directory later, it will not be able to start
3. Are there some files other than collection, index, log, and lock files in the data directory that are similar to The role of the registry, how to implement operations like binding and unbinding

I checked the operations related to db and collection, and I didn’t find any function to do the above work in the document, so I would like to ask for advice.

Attached is a screenshot of the data directory:

大家讲道理大家讲道理2839 days ago766

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-02 09:26:50

    You can consider the two data migration methods described in this article.
    Article

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-02 09:26:50

    A simple method for reference:

    1. Assume that data files and related logs are placed in the data folder;

    2. Close the MongoDB database normally;

    3. Copy the data folder to the portable disk;

    4. Modify relevant parameters in mongod.conf, such as

    systemLog:
        destination: file
        path: F:\mongodb\data\log\mongod.log
    storage:
        dbPath: F:\mongodb\data\db

    5. Start MongoDB normally

    In your description, it may be that the mongod.conf configuration file has not been modified, or the data/log path has not been reset.

    For reference.

    Love MongoDB! Have Fun!

    ------------------------Gorgeous separator--------------------- ----------

    MongoDB Chinese community has many offline activities, please click below:

    2017 Huashan Sword Discussion|MongoDB Chinese Community

    Hangzhou Station is coming in March! ! ! Interested friends please sign up quickly! ! !

    reply
    0
  • Cancelreply