1
This commit is contained in:
parent
a241416c47
commit
c32e8a93fa
@ -1,3 +1,6 @@
|
||||
[
|
||||
|
||||
{
|
||||
"table_name": "version",
|
||||
"where": " accountid LIKE '$channel_'"
|
||||
}
|
||||
]
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user