This commit is contained in:
aozhiwei 2020-09-01 10:41:40 +08:00
parent dba6777766
commit 3d5d2b8c89

View File

@ -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")