1
This commit is contained in:
parent
6db522bf78
commit
783638db51
64
tools/migratedb/migratedb.py
Normal file
64
tools/migratedb/migratedb.py
Normal file
@ -0,0 +1,64 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#!/usr/bin/python
|
||||
|
||||
import pymysql
|
||||
import hashlib
|
||||
import json
|
||||
import urllib.request
|
||||
import base64
|
||||
import time
|
||||
import datetime
|
||||
import redis
|
||||
import os
|
||||
import functools
|
||||
|
||||
CONFIG_DIR = '.'
|
||||
context = {
|
||||
'channel': 0,
|
||||
'dbname_prefix': ''
|
||||
}
|
||||
|
||||
def md5Str(data):
|
||||
m = hashlib.md5()
|
||||
m.update(data)
|
||||
return m.hexdigest()
|
||||
|
||||
def fetchAllAccount(context, db_conf, all_account_hash):
|
||||
for conf in db_conf:
|
||||
conn = pymysql.connect(host = conf['host'],
|
||||
port = conf['port'],
|
||||
user = conf['user'],
|
||||
passwd = conf['passwd'],
|
||||
db = context['dbname_prefix'] + str(conf['instance_id']),
|
||||
charset = 'utf8'
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
last_idx = 0
|
||||
while True:
|
||||
cursor.execute('SELECT idx, accountid FROM user '
|
||||
'WHERE idx > %s AND accountid LIKE "%s_\%" LIMIT 0, 10000;' %
|
||||
(last_idx,
|
||||
context['dbname_prefix']
|
||||
))
|
||||
has_data = False
|
||||
for row in cursor:
|
||||
has_data = True
|
||||
all_account_hash[row[1]] = {
|
||||
'md5' : md5Str(row[1])
|
||||
}
|
||||
if row[0] > last_idx:
|
||||
last_idx = row[0]
|
||||
if not has_data:
|
||||
break
|
||||
|
||||
def main():
|
||||
global context
|
||||
db_conf = json.loads(open(CONFIG_DIR + '/mysql_list.json', 'r').read())
|
||||
redis_conf = json.loads(open(CONFIG_DIR + '/redis_list.json', 'r').read())
|
||||
db_rule_conf = json.loads(open(CONFIG_DIR + '/mysql_rule.json', 'r').read())
|
||||
redis_rule_conf = json.loads(open(CONFIG_DIR + '/redis_rule.json', 'r').read())
|
||||
all_account_hash = {}
|
||||
fetchAllAccount(context, db_conf, all_account_hash)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
6
tools/migratedb/redis_rule.json
Normal file
6
tools/migratedb/redis_rule.json
Normal file
@ -0,0 +1,6 @@
|
||||
[
|
||||
{
|
||||
"key_prefix": "",
|
||||
"pattern": "md5"
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user