if type(binlogevent) not in (RotateEvent, FormatDescriptionEvent): lastPos = binlogevent.packet.log_pos if flagLastEvent: break ftmp.close() if self.flashback: # doesn't work if you can't fit the whole file in memory. # need to be optimized for line in reversed(open(tmpFile).readlines()): print line.rstrip() finally: os.remove(tmpFile) cur.close() stream.close() return True def __del__(self): pass if __name__ == '__main__': args = command_line_args() connectionSettings = {'host':args.host, 'port':args.port, 'user':args.user, 'passwd':args.password} binlog2sql = Binlog2sql(connectionSettings=connectionSettings, startFile=args.startFile, startPos=args.startPos, endFile=args.endFile, endPos=args.endPos, startTime=args.startTime, stopTime=args.stopTime, only_schemas=args.databases, only_tables=args.tables, nopk=args.nopk, flashback=args.flashback, stopnever=args.stopnever) binlog2sql.process_binlog()
return True def print_rollback_sql(self, filename): """print rollback sql from tmp_file""" with open(filename, "rb") as f_tmp: batch_size = 1000 i = 0 for line in reversed_lines(f_tmp): print(line.rstrip()) if i >= batch_size: i = 0 if self.back_interval: print('SELECT SLEEP(%s);' % self.back_interval) else: i += 1 def __del__(self): pass if __name__ == '__main__': args = command_line_args(sys.argv[1:]) conn_setting = {'host': args.host, 'port': args.port, 'user': args.user, 'passwd': args.password, 'charset': 'utf8'} binlog2sql = Binlog2sql(connection_settings=conn_setting, start_file=args.start_file, start_pos=args.start_pos, end_file=args.end_file, end_pos=args.end_pos, start_time=args.start_time, stop_time=args.stop_time, only_schemas=args.databases, only_tables=args.tables, no_pk=args.no_pk, flashback=args.flashback, stop_never=args.stop_never, back_interval=args.back_interval, only_dml=args.only_dml, sql_type=args.sql_type, flashback_base_key=args.flashback_base_key) binlog2sql.process_binlog()
def print_rollback_sql(self, fin): '''print rollback sql from tmpfile''' with open(fin) as ftmp: sleepInterval = 1000 i = 0 for line in reversed_lines(ftmp): print (line.rstrip()) if i >= sleepInterval: print ('SELECT SLEEP(1);') i = 0 else: i += 1 def __del__(self): pass if __name__ == '__main__': args_t = ['-h192.168.134.130','-uroot','-p123456','-P3307','--start-file=mysql-bin.000128','--stop-file=mysql-bin.000130','-dbinlog2sql','-B'] args = command_line_args(args_t) # args = command_line_args(sys.argv[1:]) connectionSettings = {'host':args.host, 'port':args.port, 'user':args.user, 'passwd':args.password,'charset':'utf8'} binlog2sql = Binlog2sql(connectionSettings=connectionSettings, startFile=args.startFile, startPos=args.startPos, endFile=args.endFile, endPos=args.endPos, startTime=args.startTime, stopTime=args.stopTime, only_schemas=args.databases, only_tables=args.tables, nopk=args.nopk, flashback=args.flashback, stopnever=args.stopnever) binlog2sql.process_binlog()