-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflush_slow_logs.py
More file actions
27 lines (20 loc) · 859 Bytes
/
Copy pathflush_slow_logs.py
File metadata and controls
27 lines (20 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import datetime
from mtk.utils.cmd import exec_cmd
from mtk.scripts.mysql_backup_binlog import dir_bin_all_binlog
# 如需其他实例切割slow.log,在ports增加端口即可
ports = [5004]
today = datetime.date.today()
def week_slow_log():
for port in ports:
# dir即获得datadir
dir = dir_bin_all_binlog(port)[0]
cmd = "mv {}/slow.log {}/slow-{}.log".format(dir, dir, today)
rc, stdout, stderr = exec_cmd(cmd)
if rc != 0:
print("flush_slow_log.py.mv is failed.stderr:{}".format(stderr))
cmd = "/usr/local/mysql/bin/mysqladmin -uroot -S /tmp/mysql_{}.sock flush-logs slow".format(port)
rc, stdout, stderr = exec_cmd(cmd)
if rc != 0:
print("flush_slow_log.py.flush-logs slow failed.stderr:{}".format(stderr))
if __name__ == '__main__':
week_slow_log()