在 mongodb 中归档副本集

问题描述 投票:0回答:2

朋友们, 我是 MongoDB DBA,对 Mongo 和 DBA 角色都是全新的。

我想在 3 节点副本集中归档一个月前的数据。 mongodump 是我可以实现这一目标的一种选择,但我的客户问我是否有任何选择。那么,请您建议在副本集中归档数据的可用选项。

非常感谢!!!

mongodb mongodb-query
2个回答
1
投票

是的,我们有多种选择。

我们可以从工具中获取,

  1. 运营经理
  2. 阿特拉斯
  3. 通过
  4. 编写脚本

除此之外,如果您尝试手动使用MongoDUMP

mongodump --archive=test.20150715.gz --gzip --db test

mongodump --gzip --db test

额外 如果您想恢复相同的存档文件,

mongorestore --archive --port 27017 --host abc.mongo.com

参考: https://docs.mongodb.com/manual/reference/program/mongodump/ https://docs.mongodb.com/manual/reference/program/mongorestore/


0
投票
By implementing a zone-based sharding strategy using MongoDB, we can effectively allow you to manage the data distribution across shards, separating live/online data from archival data.

Creating Zone Tags: Associate zone tags (online and archiveZone) with specific shards.

Two shards for live data: These shards (shard0 and shard1) will store all the active data.

    sh.addShardToZone("shard0", "online")  -- Shard for live data
    sh.addShardToZone("shard1", "online")  -- Another shard for live data

One shard for archival data: A separate shard (shard2) will store older, archived data.

    sh.addShardToZone("shard2", "archiveZone")  -- Shard for archived data

Shard collection: Enable sharding for the target database and shard a collection based on createdAt for time-based partitioning and Id for hashed partitioning.

    sh.enableSharding("db_name")  
    sh.shardCollection("db_name.collection_name", { createdAt: 1, Id: "hashed" })  


Create a zone range: Archive data older than a specific date (one month) into the archiveZone.

    sh.updateZoneKeyRange(
        "db_name.collection_name", 
        { createdAt: MINKEY },  // Minimum possible value (oldest data)
        { createdAt: ISODate("2024-04-01T00:00:00Z") },  // Archive data older than April 1, 2024
        "archiveZone"
    )

MINKEY: This indicates the minimum possible value for the createdAt field, meaning this range includes all older data up to April 1, 2024.
Automated script: Create a script to automate the zone range update process whenever you want to archive more data.

    sh.shardCollection("db_name.collection_name", { createdAt: 1, Id: "hashed" })

  
we can split online and archive data using range based sharding (createdAt: 1), and inside online shrard we can distribute the data using Id: "hashed" as a even distribution.
© www.soinside.com 2019 - 2024. All rights reserved.