三国合区保留区服.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 合区方法:
  2. 1,redis中使用命令(举例:将10003的玩家合到10001)
  3. redis-cli -a "tmKjD1ENs3HfZ7adzLJO!" EVAL "local keys = redis.call('HKEYS', 'CUser_ServerId:'); local count = 0; for i,key in ipairs(keys) do if redis.call('HGET', 'CUser_ServerId:', key) == '10031' then redis.call('HSET', 'CUser_ServerId:', key, '10026'); count = count + 1; end; end; return count" 0
  4. redis-cli -n 1 -a "tmKjD1ENs3HfZ7adzLJO!" EVAL "local keys = redis.call('HKEYS', 'CUser_ServerId:'); local count = 0; for i,key in ipairs(keys) do if redis.call('HGET', 'CUser_ServerId:', key) == '10031' then redis.call('HSET', 'CUser_ServerId:', key, '10026'); count = count + 1; end; end; return count" 0
  5. 2,更新mongo中的x5_tk_login中的user_info中合服区的等级。
  6. // 更新服务器s1的玩家等级
  7. var server1Db = db.getSiblingDB("m5_x1_game_10001");
  8. var loginDb = db.getSiblingDB("x5_tk_login");
  9. var count1 = 0;
  10. server1Db.user.find().forEach(function(doc) {
  11. var result = loginDb.user_info.updateOne(
  12. {
  13. _id: doc._id
  14. },
  15. {
  16. $set: {
  17. level: doc.playerManager.level,
  18. update_time: new Date()
  19. }
  20. }
  21. );
  22. if (result.modifiedCount > 0) {
  23. count1++;
  24. }
  25. });
  26. print("服务器s1更新完成,更新了 " + count1 + " 条记录");
  27. 将mongo中的x5_tk_login中的user_info中10003的玩家serverId改成10001,
  28. db.user_info.updateMany(
  29. {
  30. "serverId": "10003" // 只匹配serverId为10003的文档
  31. },
  32. {
  33. $set: {
  34. "serverId": "10001"
  35. }
  36. }
  37. );
  38. 将mongo中10003区的集合user和guildinfo插入到10001区的数据库。
  39. db.getSiblingDB('m5_x1_game_10001').user.insertMany(
  40. db.getSiblingDB('m5_x1_game_10003').user.find().toArray(),
  41. { ordered: false }
  42. );
  43. 另一中方式:
  44. 先拷贝出来
  45. mongodump --uri='mongodb://root:StrongMongoPass123@localhost:27017/m5_x1_game_10007?authSource=admin' --collection user --out /data/mongodb/
  46. 再插入到目标数据库
  47. mongorestore --uri='mongodb://root:StrongMongoPass123@localhost:27017/?authSource=admin' --db m5_x1_game_10001 --collection user /data/mongodb/m5_x1_game_10002/user.bson
  48. db.getSiblingDB('m5_x1_game_10001').guildInfo.insertMany(
  49. db.getSiblingDB('m5_x1_game_10003').guildInfo.find().toArray(),
  50. { ordered: false }
  51. );
  52. db.server_info.updateMany(
  53. {
  54. "server_id": "10060" // 只匹配serverId为10003的文档
  55. },
  56. {
  57. $set: {
  58. "server_id": "10060",
  59. "port": "16160" ,
  60. "gm_port": "8160"
  61. }
  62. }
  63. );
  64. 1-19区合区保留1区
  65. 20-21保留20
  66. 22-25保留22
  67. 26-33保留30