博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL innobackupex全备
阅读量:6342 次
发布时间:2019-06-22

本文共 2670 字,大约阅读时间需要 8 分钟。

MySQL innobackupex全备

MySQL innobackupex 全备

#!/usr/local/bin/python3# -*- coding: utf-8 -*-# Author:xtrdb.netimport osimport sysimport errnoimport timeimport loggingimport getoptimport shleximport MySQLdbfrom subprocess import PIPE, Popen, STDOUTdb_host = "116.196.xx.16"db_port = "9036"db_user = "zyl"db_passwd = 'g`QnpqD)P>}25B`^l1h)xxxx'db_name = "mysql"conf = "/data/mysql/mysql9036/my9036.cnf"target_dir = "/data/full_back/test_9036_full_{}".format(time.strftime("%Y%m%d"))pt_xtrabackup = "/usr/bin/innobackupex"# start logginglogging.basicConfig(    filename="/tmp/innobackupex.log",    format="%(asctime)s:%(levelname)s:%(message)s",    datefmt="%Y-%m-%d %T",    level=logging.INFO,)logging.info("Start backup...")class Backup(object):    def __init__(self,db_conf,user,host,passwd,port,bak_dir):        self.user = db_user        self.host = db_host        self.passwd = db_passwd        self.port = db_port        if conf == None:            self.defaults_file = "/etc/my.cnf"        else:            self.defaults_file = conf        self.target_dir = target_dir    def backup(self):        command = "{0} --defaults-file={1} --user={2} --password='{3}' --host={4} --port={5} --no-timestamp {6}".format(pt_xtrabackup, self.defaults_file, self.user, self.passwd, self.host, self.port, self.target_dir)        print(command)        status = runCommand(command)        if status == 1:            return 1    def applylog(self):        command = "%s --defaults-file=%s/backup-my.cnf --apply-log  --user=%s --password='%s' --host=%s --port=%s  %s" % (pt_xtrabackup, target_dir,self.user, self.passwd, self.host,self.port, target_dir)        print(command)        status = runCommand(command)        if status == 1:            return 1        return 0def runCommand(command):    cmd = shlex.split(command)    logging.debug('Running back command: "' + command + '"')    proc = Popen(cmd, stdout=PIPE, stderr=PIPE)    for line in proc.stderr:        logging.warning(str(line.strip()))    for line in proc.stdout:        logging.debug(str(line.strip()))    proc.wait()    if proc.returncode != 0:        logging.critical('Command failed with return code "' + str(proc.returncode) + '"')    else:        logging.debug('Command successfully finished with returncode "' + str(proc.returncode) + '"')        return 0if __name__ == '__main__':    t = Backup("defaults_file","db_user","db_passwd","db_host",9036,"target_dir")    t.backup()    backup_status = t.applylog()    if backup_status == 0:        db_size = os.popen("du -sh %s" %target_dir).read().split("\t")        logging.info("backup up dbszie: %s" %db_size[0])    logging.info("End backup")

转载于:https://blog.51cto.com/zhagyilig/2055019

你可能感兴趣的文章
赛门铁克收购以色列移动安全初创公司Skycure 旨在构建网络安全防御平台
查看>>
《Photoshop蒙版与合成(第2版)》目录—导读
查看>>
“最佳人气奖”出炉!4月27号,谁能拿到阿里聚安全算法挑战赛的桂冠?
查看>>
《网页美工设计Photoshop+Flash+Dreamweaver从入门到精通》——2.6 图层与图层样式...
查看>>
《iOS组件与框架——iOS SDK高级特性剖析》——第2章,第2.7节获取线路
查看>>
Spring中 @Autowired标签与 @Resource标签 的区别
查看>>
人工智能凭什么毁灭人类
查看>>
今天的学习
查看>>
面试必问之JVM原理
查看>>
mysql主主同步+Keepalived
查看>>
研究音频编解码要看什么书
查看>>
tomcat远程调试配置
查看>>
QuartZ Cron表达式
查看>>
性能测试工具VTune的功能和用法介绍
查看>>
音频视频组件Audio DJ Studio for .NET更新至v10.0.0.0丨附下载
查看>>
RMAN Complete Recovery
查看>>
[ CodeForces 1064 B ] Equations of Mathematical Magic
查看>>
NYOJ-15:括号匹配(二)
查看>>
首次记录在案的
查看>>
C#进阶系列——WebApi 跨域问题解决方案:CORS
查看>>