dbdao吧 关注:1,186贴子:4,073
  • 2回复贴,共1

分片集合如何备份,重命名

只看楼主收藏回复

在mongos里执行db.click.renameCollection('click_bak_150818'),报错说不能重命名分片集合,后来看官方文档才发现也是这么写的,jira也说是在规划中还没有排期开发。请问,对于集群分片集合如何才能备份或者重命名?谢谢


1楼2015-08-19 12:10回复
    There is no way to rename a sharded collection.
    You can copy all the docs to a new collection.
    Or create multiple collections based on a weekly/period date, and use as the current one. Then have your application always use the current one by name and change the name at each period break.
    可以CTAS 为另一个collection 例如
    db.orders.find({ 条件: 1 }).
    forEach( function(i) {
    i.ts_imported = new Date();
    db.orders1.insert(i);
    });
    db.orders.find().forEach( function(i) {
    i.ts_imported = new Date();
    db.orders1.insert(i);
    });


    IP属地:日本2楼2015-08-19 20:07
    回复
      谢谢吧主回复,我的做法是绕过mongos,写shell脚本连各台机器的mongod进程,然后renameCollection。这样做是可以备份,但缺点是用mongos查不到了备份的集合,只能连各个mongod查各自存储的集合数据了。


      3楼2015-08-20 18:57
      回复