コード例 #1
0
ファイル: redis_history_clear.py プロジェクト: heafod/RedisMM
def clear_history_data():
    history_save_days =int(func.get_option('history_save_days'))
    if history_save_days >= 1:
        old_date=str(func_time.get_day_of_day(history_save_days*-1))
        sql="delete from redis_coldback_info where date <'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        sql="delete from alarm_history where left(create_time,10)<'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        sql="delete from redis_keyspace_history where left(create_time,10)<'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        sql="delete from redis_persistence_status_history where left(create_time,10)<'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        sql="delete from redis_replication_history where left(create_time,10)<'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        sql="delete from redis_resource_status_history where left(create_time,10)<'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        sql="delete from redis_run_status_history where left(create_time,10)<'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        sql="delete from redis_server_status_history where left(create_time,10)<'"+old_date+"'"
        log.debug("sql:%s"%(sql))
        func.mysql_exec(sql,'')
        tCmd="rm -f ./log/*"+old_date
        log.debug("tCmd:%s"%(tCmd))
        os.system(tCmd)
    else:
        log.error("get history_save_days from options error!")
コード例 #2
0
ファイル: redis_data_back.py プロジェクト: heafod/RedisMM
def backup_data(log):
    current_minute=time.strftime('%H:%M', time.localtime())
    current_date=time.strftime('%Y-%m-%d', time.localtime())
    #test
    #sql="delete from redis_coldback_info where server_id='3';"
    #func.mysql_exec(sql,'')
    sql="select server_id,IP,ssh_port,ssh_user,ssh_passwd,back_IP,back_ssh_port,back_ssh_user,back_ssh_passwd,back_path,db_name,back_cycle,save_number,alarm_flag,charge_person from redis_coldback_config where back_flag='y' and back_time<='"+current_minute+"' and server_id not in (select distinct server_id from redis_coldback_info where suc_flag='y' and date='"+current_date+"');"
    servers=func.mysql_query(sql)
    #print sql
    #frequency_monitor = func.get_option('frequency_monitor')
    if servers:
	 log.info("need backup servers: %s" %(servers,));
         #print("%s: check_mysql_status controller started..." % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),));
         plist = []
         for row in servers:
             server_id=str(row[0])
             IP=row[1]
             ssh_port=row[2]
             ssh_user=row[3]
             ssh_passwd=row[4]
             back_IP=row[5]
             back_ssh_port=row[6]
             back_ssh_user=row[7]
             back_ssh_passwd=row[8]
             back_path=row[9]
             db_name=row[10]
             back_cycle=int(row[11])
             save_number=row[12]
             alarm_flag=row[13]
             charge_person=row[14]
             #check if need to back
             if back_cycle > 1:
                 back_date=str(func_time.get_day_of_day(back_cycle*-1))
                 sql="select count(1) as num from redis_coldback_info where server_id='"+server_id+"' and  suc_flag='y' and date>='"+back_date+"'"
                 result=func.mysql_query(sql)
                 if result:
                     num=result[0]
                     if num >=1:
                         continue
             #get host:port of server
             mail_content="RedisBackup:"
             sql="select a.display_name,b.host,b.port,b.application_id from application a,servers b where a.id=b.application_id and b.id='"+server_id+"';"
             #sql="set names utf8;select a.display_name,b.host,b.port,b.application_id from application a,servers b where a.id=b.application_id and b.id='"+server_id+"';"
             result=func.mysql_query(sql)
             if result:
                 display_name=result[0][0]
                 ##host equal with IP
                 host=result[0][1]
                 port=result[0][2]
                 application_id=result[0][3]
             else:
                 mail_content=mail_content+"not found server_id:"+server_id
                 #send warn to system charge person
                 application_id=0
                 send_backup_alarm(alarm_flag,charge_person,mail_content,application_id,server_id,db_name,current_date,log)
                 continue

             mail_content="RedisBackup_"+IP+"_"+port+"("+display_name+"):"
             #get redis dir
             sql="select dir from redis_server_status_history where server_id='"+server_id+"' order by id desc limit 1;"
             result=func.mysql_query(sql)
             if result and result[0][0]!="---":
                 dir=result[0][0]
                 #print("dir:%s"%(dir))
             else:
                 mail_content=mail_content+"redis dir not found"
                 #send warn
                 send_backup_alarm(alarm_flag,charge_person,mail_content,application_id,server_id,db_name,current_date,log)
                 continue

             #get config of rdb/aof
             sql="select rdb_enabled,rdb_dbfilename,rdb_last_bgsave_status,aof_enabled,aof_last_bgrewrite_status,aof_last_write_status,aof_current_size from redis_persistence_status_history where server_id='"+server_id+"' order by YmdHi desc limit 1;"
             result=func.mysql_query(sql)
             if result:
                 rdb_enabled=result[0][0]
                 rdb_dbfilename=result[0][1]
                 rdb_last_bgsave_status=result[0][2]
                 aof_enabled=result[0][3]
                 aof_last_bgrewrite_status=result[0][4]
                 aof_last_write_status=result[0][5]
                 aof_current_size=result[0][6]
             else:
                 mail_content=mail_content+"redis persistence info not found"
                 #send warn
                 send_backup_alarm(alarm_flag,charge_person,mail_content,application_id,server_id,db_name,current_date)
                 continue

             #check passwd
             if ssh_passwd == "":
                 log.error("passwd not found,IP:%s:"%(IP))
                 continue    
             if back_ssh_passwd == "": 
                 log.error("passwd not found,IP:%s"%(back_IP))
                 continue

             #back data
             if db_name.find("rdb") >=0:
                  back_rdb_file(server_id,display_name,port,IP,ssh_port,ssh_user,ssh_passwd,back_IP,back_ssh_port,back_ssh_user,back_ssh_passwd,rdb_enabled,rdb_last_bgsave_status,dir,rdb_dbfilename,back_path,current_date,alarm_flag,charge_person,application_id,log)

             if db_name.find("aof") >=0:
                  back_aof_file(server_id,display_name,port,IP,ssh_port,ssh_user,ssh_passwd,back_IP,back_ssh_port,back_ssh_user,back_ssh_passwd,aof_enabled,aof_last_bgrewrite_status,aof_last_write_status,aof_current_size,dir,back_path,current_date,alarm_flag,charge_person,application_id,log)