UseCentOS can help IT managers to get rid of the boring learning methods, quick grasp Linux technology knowledge, so as to improve the level of technology, to lay a good foundation for their growth. Our tenet: all for one, one for all
For database backup and recovery is the main responsibility of DBA, and how to effectively backup database, and when the database is the collapse of the timely recovery will become very important, if the Linux of pure manual backup of the database, will bring a lot of trouble, I have to write a script, the script added to regularly perform the tasks list, regular data backup, it becomes easier to manage the database, here is a simple small script, of course in the actual reference but also changes, such as adding the user and password, you can modify the doing according to their own needs.
The following simple introduce the script, the script has four parameters:
/PATH/mysqlbak.sh -f / / full backup, the database can according to their own changes set how long the implementation time, add a month to perform a!
/PATH/mysqlbak.sh -d / / this is from the last full backup to a difference between the current time of the backup, thus reducing the database backup time.
/PATH/mysqlbak.sh -i / / this parameter can achieve incremental backup, which changes between a database backup and the backup, this time can be a little shorter, so the loss can be reduced when the database can collapse, once an hour.
/PATH/mysqlbak.sh -h / / this is to help information
These are added to the plan regularly, can realize the automatic execution of the script, without manual backup administrator.
# /bin/bash!
#
Function {HELPTXT
Echo "/PATH/mysqlbak.sh -f: You can backup all databases"
Echo "/PATH/mysqlbak.sh -i: Just backup the exter change from the last backup"
Echo "/PATH/mysqlbak.sh -d: Backup from the last full-backup to the current time"
}
DATE=`date "+%F-%H-%M-%S".
MySQL -e "FLUSH TABLES WITH READ LOCK;"
/dev/null">MySQL -e "SHOW MASTER STATUS >/dev/null;"
Startfile=/tmp/startposition
Exterfile=/tmp/exterposition
While getopts "fdih" OPTS; do
Case $OPTS in
F)
/mybackup/db.$DATE">Mysqldump --all-databases >/mybackup/db.$DATE
$startfile`">STARTPOSITION=`mysql -e "SHOW MASTER STATUS; tail -1 awk'{print" | | $2}'>$startfile`
$exterfile`">ESTARTPOSITION=`mysql -e "SHOW MASTER STATUS; tail -1 awk'{print" | | $2}'>$exterfile`
CD /mybackup
/dev/null">Tar -cjf /root/bakmysql/db.$DATE.tar.gz2 db.$DATE >/dev/null
;;
D)
MySQL -e "FLUSH TABLES WITH READ LOCK;"
/dev/null">MySQL -e "SHOW MASTER STATUS >/dev/null;"
FILE=`mysql -e "SHOW MASTER STATUS; tail -1 awk'{print" | | $1}'`
STARTPOSITION=`cat $startfile`
ENDPOSITION=`mysql -e "SHOW MASTER STATUS; tail -1 awk'{print" | | $2}'`
/mybackup/incre.$DATE">Mysqlbinlog --start-position $STARTPOSITION
--stop-position $ENDPOSITION /mydata/data/$FILE
>/mybackup/incre.$DATE
CD /mybackup
/dev/null">Tar -cjf /root/bakmysql/incre.$DATE.tar.gz2 incre.$DATE >/dev/null
;;
I)
MySQL -e "FLUSH TABLES WITH READ LOCK;"
/dev/null">MySQL -e "SHOW MASTER STATUS >/dev/null;"
FILE=`mysql -e "SHOW MASTER STATUS; tail -1 awk'{print" | | $1}'`
>$exterfile`">EENDPOSITION=`mysql -e "SHOW MASTER STATUS tail -1;" | | awk'{print $2}'>>$exterfile`
ESTARTPOSITION=`tail -n 2 $exterfile head -n 1` |
Exendposition=`tail -n 1 $exterfile`
/mybackup/exter.$DATE">Mysqlbinlog --start-position $ESTARTPOSITION
--stop-position $Exendposition /mydata/data/$FILE
>/mybackup/exter.$DATE
CD /mybackup
/dev/null">Tar -cjf /root/bakmysql/exter.$DATE.tar.gz2 exter.$DATE >/dev/null
;;
H)
HELPTXT
;;
ESAC
Done
 
Add the task plan in crontab -e, can realize the automatic backup of the database!!
 
I hope this little script can make you more convenient management of MySQL database, if there is a problem, can discuss!
Tag:One    script    implementation    Mysql    back  

 

A Mysql backup script的更多相关文章

  1. Python mysql backup

    http://www.linuxidc.com/Linux/2015-02/113057.htm ------------- #!/usr/bin/python#################### ...

  2. MySQL Backup mysqldump备份流程学习

    我们都知道MySQL逻辑备份工具mysqldump可以保证备份数据的一致性,但是它是怎么保持一致性的? 本文不讨论mysqldump具体的选项和用法,一直对mysqldump的工作机制梳理的不太清楚, ...

  3. MySQL Backup myloader

    之前的博文当中提到备份工具mydumper的使用,而软件包中还包含了与之对应的恢复工具myloader,本文就总结下myloader的用法.关于mydumper的安装与使用可以参考之前的博文:MySQ ...

  4. MySQL Backup in Facebook

    本文将较为详细的介绍Facebook对于MySQL数据库的备份策略和方法 文章欢迎转载,但转载时请保留本段文字,并置于文章的顶部 作者:卢钧轶(cenalulu) 本文原文地址:http://cena ...

  5. keepalived+mysql backup服务器可ping通过vip但telnet vip+3306失败问题

    环境: OS:CentOS 7_X64 数据库:mysql-5.7 MASTER:192.168.119.23 BACKUP:192.168.119.24 VIP:192.168.119.138 ke ...

  6. MySQL Backup mysqldump 常用选项与主要用法

    The mysqldump client utility performs logical backups, producing a set of SQL statements that can be ...

  7. MySQL Backup mydumper

    生产环境中有一实例每天使用mysqldump备份时长达到了2个小时53分钟,接近3个小时,还不算上备份文件归档的时间,这个时间对于逻辑备份来说有点久.为了提高逻辑备份效率,打算替换为使用mydumpe ...

  8. 1950261 - SAP HANA Database Backup Policy Recommendations and Regular Backup Script

    =====Symptom For SAP Business One, version for SAP HANA users, SAP HANA provides a range of database ...

  9. shell for mysql backup in linux

    今天上班只有一台linux系统,就学着在linux上写了个脚本,没啥技术含量 省得每天敲代码备份 没有设置自动备份时间,这里可以参照 http://www.th7.cn/db/mysql/201305 ...

随机推荐

  1. MagicNotes:自我管理中的破窗效应

    MagicNotes,思绪随风飞扬,偶尔在这里停留. 在<程序员修炼之道——从小工到专家>这本书里,有这么一段描述: 在市区,有些建筑漂亮而整洁,而另一些却是破败不堪的“废弃船只”.为什么 ...

  2. ios-消息弹框之UIAlertView, UIActionSheet以及UIAlertController小结

    首先storyboard中创建对应按钮并拖线,来演示不同的效果 首先点击了actionSheet按钮效果如图 实现弹框需要遵守设置代理,遵守协议. 效果就是从底部向上弹起来的框框. 通过对按钮的点击输 ...

  3. thttpd增加gzip压缩响应报文体功能,以减少传输数据量

    thttpd thttpd是一个非常小巧的轻量级web server,它非常非常简单,仅仅提供了HTTP/1.1和简单的CGI支持,在其官方网站上有一个与其他web server(如Apache, Z ...

  4. Java基础之一组有用的类——Observable和Observer对象(Horrific)

    控制台程序. Obserable类提供了一个有趣的机制,可以把类对象中发生的改变通知给许多其他类对象. 对于可以观察的对象来说,类定义中需要使用java.util.Observable类.只需要简单地 ...

  5. Lintcode: Binary Tree Serialization (Serialization and Deserialization Of Binary Tree)

    Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a ...

  6. 创建Java类并实例化的基本过程

    package com.sanguosha.java; /* * 面向对象实现的过程 * 1.创建类并设计类的成员(成员变量即属性and成员方法即方法) * 2.通过类来创建类的对象,也称类的实例化 ...

  7. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

  8. Java基础(38):Calendar类的应用(优于Date类)

    Calendar 类的应用 Date 类最主要的作用就是获得当前时间,同时这个类里面也具有设置时间以及一些其他的功能,但是由于本身设计的问题,这些方法却遭到众多批评,不建议使用,更推荐使用 Calen ...

  9. URAL 1018 Binary Apple Tree(树DP)

    Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a bina ...

  10. JSon_零基础_008_将JSon格式的"数组"字符串转换为List集合

    将JSon格式的"数组"字符串转换为List集合. 应用此技术从一个json对象字符串格式中得到一个java对应的对象. JSONObject是一个“name.values”集合, ...