Skip to content

Commit b8c6b1a

Browse files
committed
cleanup binlog before backup
1 parent 6dfad4e commit b8c6b1a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

mysqlbackup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from pykit import mysqlconnpool
3434
from pykit import mysqlutil
35+
from pykit import timeutil
3536
from pykit import logutil
3637
from 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}',

0 commit comments

Comments
 (0)