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. Inside Flask - flask.__init__.py 和核心组件

    Inside Flask - flask.__init__.py 和核心组件 简单的示例 首先看看一个简单的示例.使用 Flask ,通常是从 flask 模块导入 Flask . request 等 ...

  2. 通过 ec2-api / boto 调用 OpenStack 功能

    通过 ec2-api / boto 调用 OpenStack 功能 OpenStack 支持 amazon ec2 的 api,并能通过 python 库 boto 来进行调用.目前,社区在把 ec2 ...

  3. UIlabel多行文字自动换行 (自动折行)

    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(, , , )]; UILabel *label = [[UILabel al ...

  4. iOS - (简单平移动画/弹出View的使用)

    在iOS 开发中,使用平移动画的频率越来越高,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,但我目前是使用较多的是平移动画,顺便也在此做一些小小的总结,大 ...

  5. lua对模块接口扩展的一种方法

    module lua中模块的实现,对于使用者来说就是一个库,引用此库后,可以调用库中实现的任意函数. 使用库,可以将一类功能相关的接口做封装,并提供开放接口. 参考: http://blog.codi ...

  6. [转] 被遗忘的Logrotate

    FROM : http://huoding.com/2013/04/21/246 我发现很多人的服务器上都运行着一些诸如每天切分Nginx日志之类的CRON脚本,大家似乎遗忘了Logrotate,争相 ...

  7. wampserver环境下,apache本地下设置多个域名

    Apache在安装之后默认只是指向一个站点,即127.0.0.1,如果要进行多站点的配置,需要更改一些配置. 步骤.方法: 1,)让Apache在启动时能加载虚拟主机模块. 打开Apache安装目录下 ...

  8. 学习OpenCV——OpenMP

    转自:http://www.cnblogs.com/yangyangcv/archive/2012/03/23/2413335.html openMP的一点使用经验   最近在看多核编程.简单来说,由 ...

  9. switch为什么不能用string类型?

    switch()括号里面的参数是一个int型值啊  你要可以转换为int型的参数才行得通啊

  10. Python学习总结14:时间模块datetime & time & calendar (一)

    Python中的常用于处理时间主要有3个模块datetime模块.time模块和calendar模块. 一.time模块 1. 在Python中表示时间的方式 1)时间戳(timestamp):通常来 ...