File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 3232
3333from pykit import mysqlconnpool
3434from pykit import mysqlutil
35+ from pykit import timeutil
3536from pykit import logutil
3637from pykit import humannum
3738
@@ -461,6 +462,7 @@ def backup(self):
461462 'remove old backup {backup_tgz_des3} {backup_data_dir} {backup_binlog_dir}' )
462463
463464 try :
465+ self .clean_binlog ()
464466 self .backup_data ()
465467 self .backup_binlog ()
466468 self .calc_checksum ()
@@ -471,6 +473,18 @@ def backup(self):
471473 'remove backup {backup_tgz_des3} {backup_data_dir} {backup_binlog_dir}' )
472474
473475
476+ def clean_binlog (self , before_days = 1 ):
477+
478+ ts = timeutil .ts ()
479+ ts = ts - 86400 * before_days
480+ dt = timeutil .format_ts (ts , 'daily' )
481+
482+ pool = mysqlconnpool .make (self .mysql_addr )
483+
484+ self .mysql_pool_query (pool ,
485+ 'PURGE BINARY LOGS BEFORE "{dt} 00:00:00"' .format (
486+ dt = dt ))
487+
474488 def backup_data (self ):
475489
476490 self .shell_run ('create backup dir {backup_data_dir}' ,
You can’t perform that action at this time.
0 commit comments