def backup(): ssh=None Common.create_xlsx(xlsx_path,mysql_tables_list) for mysql_table_name in mysql_tables_list: redisdb=0 if mysql_table_name=='local_user_status':redisdb=1 r=redis.StrictRedis(host=ip,port=redis_port,db=redisdb,password='******',encoding='utf-8') comm=Common(ssh,r,cur,mysql_table_name,'backup') comm.set_backup_name() comm.get_id_list() comm.write_xlsx(xlsx_path) print '********************************test end**************************************\n\n'
def restore(): #connect SSH ssh_port=config.getint(server_name,'ssh_port','server') ssh_user=config.getstr(server_name,'ssh_user','server') ssh_password=config.getstr(server_name,'ssh_password','server') ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip,ssh_port,ssh_user,ssh_password,timeout=2000) excel_name=['flush_restore_one','flush_restore_all','restore_one','restore_all'] for i in range(4): xlsx_path=sys.path[0]+'\\result\\'+date+'_'+excel_name[i]+'.xlsx' Common.create_xlsx(xlsx_path,mysql_tables_list) flag=0 for mysql_table_name in mysql_tables_list: #define array to store values redisdb=0 if mysql_table_name=='local_user_status':redisdb=1 r=redis.StrictRedis(host=ip,port=redis_port,db=redisdb,password='******',encoding='utf-8') comm=Common(ssh,r,cur,mysql_table_name,'restore') comm.set_restore_name() if i==0 or i==2: if i==0:r.flushdb() print'********************'+excel_name[i]+':'+mysql_table_name+'************************\n' comm.restore_table() if (i==1 or i==3) and flag==0: if i==1:r.flushdb() print'******************************'+excel_name[i]+'*********************************\n' comm.restore_table('all') flag=1 comm.get_id_list() comm.write_xlsx(xlsx_path) print '********************************test end '+str(i+1)+'********************************\n\n'