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. Ubuntu下如何将普通用户提升到root权限

    在ubuntu的系统操作中,我们经常会使用到系统权限的,因为权限不足,导致在一些操作当中非常麻烦.要获取权限,最长使用的方法就是使用sudo指令,但是来回使用还是比较麻烦,有没有直接提升我们的用户权限 ...

  2. java类的加载、链接、初始化

    JVM和类的关系 当我们调用JAVA命令运行某个java程序时,该命令将会启动一条java虚拟机进程,不管该java程序有多么复杂,该程序启动了多少个线程,它们都处于该java虚拟机进程里.正如前面介 ...

  3. windows下使用pthreads

    pthread-win32在Windows上实现了线程相关的Posix标准,接口一模一样 包含: thread mutex cond swlock spin sem barrier https://s ...

  4. PAT 解题报告 1007. Maximum Subsequence Sum (25)

    Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, ...

  5. GTA项目 二, JSON接口开放跨域访问

    public class CORSAttribute : ActionFilterAttribute { public string Domains { get; set; } public CORS ...

  6. 《30天自制操作系统》09_day_学习笔记

    harib06a: 在昨天的最后一部分,我们已经变成了32位的模式,目的就是希望能够使用电脑的全部内存. 虽然鼠标的显示处理有一些叠加问题,不过笔者为了不让我们感到腻烦,先带我们折腾一下内存 这里笔者 ...

  7. .net开发,html ajax开发架构之我见 bs ajax最简化法 Knock out Request,totally oo

    .net开发中,无论ajax还是webform,webpage, 总免不了要和request这个静态全局,可以远程通信的对象打交道. 而对于软件来讲,按照Matin Fowler的的面向对象,可利用软 ...

  8. 最新RubyMine2016.2开发Ruby ON Rails(ROR)程序的流程

    1.RubyMine新建ROR工程 File->New Project     选择Rails下的"New Application"     点击OK 后生成ROR项目   ...

  9. centos每天一句命令

    shutdown -h now 立刻关机  后面可以加上关键的时间  -r 重启 reboot 重启  同时记载以下,仅仅给刚刚接触的新手来说的  按两次tab 键会自动命令 cd 到目录下 su r ...

  10. cocos2d对动画的各种操作

    瞬时动作:瞬时动作的基类是InstantAction 1.放置位置   CGPoint p = ccp(width,height); [sprite runAction:[CCPlace action ...