From 3d5d2b8c89b53e8c264f6ad26fac2bc1f423bb8c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 1 Sep 2020 10:41:40 +0800 Subject: [PATCH] 1 --- tools/migratedb/migratedb.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/migratedb/migratedb.py b/tools/migratedb/migratedb.py index 2722b3f..402b176 100644 --- a/tools/migratedb/migratedb.py +++ b/tools/migratedb/migratedb.py @@ -60,7 +60,10 @@ def saveKeys(r, keys, curr_file): print('[ERROR] ' + key + ' ttl > 3600 * 24') def exportRedis(context, redis_conf, redis_rule_conf): - curr_file = open(context['out_dir'] + context['channel'] + '.redis', 'w') + redis_dir = CONFIG_DIR + 'out/' + context['channel'] + '/redis/' + if not os.path.exists(redis_dir): + os.mkdir(redis_dir) + curr_file = open(redis_dir + context['channel'] + '.redis', 'w') for conf in redis_conf: r = redis.Redis(host = conf['host'], port = conf['port'], @@ -74,22 +77,26 @@ def exportRedis(context, redis_conf, redis_rule_conf): #end for conf def exportMysql(context, db_conf, db_rule_conf): - dbsh_file = open(context['out_dir'] + context['channel'] + '.sh', 'w') + dbsh_file = open(context['out_dir'] + 'exportdb.sh', 'w') for conf in db_conf: + db_dir = CONFIG_DIR + 'out/' + context['channel'] + '/' + str(conf['instance_id']) + if not os.path.exists(db_dir): + os.mkdir(db_dir) for rule in db_rule_conf: line = '' if rule['where'] == '': - line = 'mysqldump -h %s -P %d -u%s -p%s %s %s > %s.sql' % ( + line = 'mysqldump -h %s -P %d -u%s -p%s %s %s > %d/%s.sql' % ( conf['host'], conf['port'], conf['user'], conf['passwd'], context['dbname_prefix'] + str(conf['instance_id']), rule['table_name'], + conf['instance_id'], rule['table_name'] ) else: - line = 'mysqldump -h %s -P %d -u%s -p%s %s %s --where="%s"> %s.sql' % ( + line = 'mysqldump -h %s -P %d -u%s -p%s %s %s --where="%s"> %d/%s.sql' % ( conf['host'], conf['port'], conf['user'], @@ -97,6 +104,7 @@ def exportMysql(context, db_conf, db_rule_conf): context['dbname_prefix'] + str(conf['instance_id']), rule['table_name'], rule['where'].replace('$channel', context['channel']), + conf['instance_id'], rule['table_name'] ) dbsh_file.write(line + "\n")