This commit is contained in:
aozhiwei 2020-08-31 20:28:24 +08:00
parent a241416c47
commit c32e8a93fa
2 changed files with 34 additions and 2 deletions

View File

@ -1,3 +1,6 @@
[
{
"table_name": "version",
"where": " accountid LIKE '$channel_'"
}
]

View File

@ -16,7 +16,7 @@ import functools
CONFIG_DIR = './'
context = {
'channel': 0,
'dbname_prefix': ''
'dbname_prefix': 'gamedb2004_'
}
def scanKeys(r, key_prefix, matched_keys):
@ -73,6 +73,34 @@ def exportRedis(context, redis_conf, redis_rule_conf):
saveKeys(r, matched_keys, curr_file)
#end for conf
def exportMysql(context, db_conf, db_rule_conf):
dbsh_file = open(context['out_dir'] + context['channel'] + '.sh', 'w')
for conf in db_conf:
for rule in db_rule_conf:
line = ''
if rule['where'] != '':
line = 'mysqldump -h %s -P %d -u%s -p%s %s %s > %s.sql' % (
conf['host'],
conf['port'],
conf['user'],
conf['passwd'],
context['dbname_prefix'] + str(conf['instance_id']),
rule['table_name'],
rule['table_name']
)
else:
line = 'mysqldump -h %s -P %d -u%s -p%s %s %s --where="%s"> %s.sql' % (
conf['host'],
conf['port'],
conf['user'],
conf['passwd'],
context['dbname_prefix'] + str(conf['instance_id']),
rule['table_name'],
rule['where'].replace('$channel', context['channel']),
rule['table_name']
)
dbsh_file.write(line + "\n")
def main():
global context
if not os.path.exists(CONFIG_DIR + 'out/'):
@ -85,6 +113,7 @@ def main():
db_rule_conf = json.loads(open(CONFIG_DIR + 'common/mysql_rule.json', 'r').read())
redis_rule_conf = json.loads(open(CONFIG_DIR + 'common/redis_rule.json', 'r').read())
exportRedis(context, redis_conf, redis_rule_conf)
exportMysql(context, db_conf, db_rule_conf)
if __name__ == "__main__":
context['channel'] = sys.argv[1]