AutoMySQLBackup是一个开源的MySQL备份脚本。可以说它是一个轻量级的备份方案,AutoMySQLBackup的安装、配置非常简单、方便。AutoMySQLBackup的sourceforge上介绍有如它本身,也非常的简单:

Description

AutoMySQLBackup with a basic configuration will create Daily, Weekly and Monthly backups of one or more of your MySQL databases from one or more of your MySQL servers.

Other Features include:

- Email notification of backups (备份邮件通知)

- Backup Compression and Encryption(备份压缩与加密)

- Configurable backup rotation (配置备份保留周期)

- Incremental database backups (数据库增量备份)

下载地址

AutoMySQLBackup的下在地址为http://sourceforge.net/projects/automysqlbackup/ 。 目前最新版本为automysqlbackup-v3.0_rc6.tar.gz

安装配置

1:将下载的安装文件automysqlbackup-v3.0_rc6.tar.gz拷贝到/tmp目录下

2:将automysqlbackup-v3.0_rc6.tar.gz解压到新建的目录automysqlbackup下。如下所示,解压后总共有6个文件。

[root@DB-Server tmp]# tar -zxvf /tmp/automysqlbackup-v3.0_rc6.tar.gz  -C /tmp/automysqlbackupautomysqlbackupautomysqlbackup.confCHANGELOGinstall.shREADMELICENSE

automysqlbackup: AutoMySQLBackup的应用程序脚本

automysqlbackup.conf : AutoMySQLBackup的配置文件范本

CHANGELOG: AutoMySQLBackup功能添加、Bug修复历史记录

install.sh: AutoMySQLBackup的安装脚本

README: AutoMySQLBackup的声明、安装、使用说明文档

建议在安装前看一下README文件,里面有介绍如何安装、配置automysqlbackup。AutoMySQLBackup提供了自动和手动安装配置两种功能(如下所示)

自动安装配置

1:运行脚本install.sh安装配置AutoMySQLBackup

[root@DB-Server tmp]# cd automysqlbackup[root@DB-Server automysqlbackup]# ./install.sh### Checking archive files for existence, readability and integrity.automysqlbackup ... exists and is readable ... md5sum okay :)automysqlbackup.conf ... exists and is readable ... md5sum okay :)README ... exists and is readable ... md5sum okay :)LICENSE ... exists and is readable ... md5sum okay :)Select the global configuration directory [/etc/automysqlbackup]:Select directory for the executable [/usr/local/bin]: /usr/bin### Creating global configuration directory /etc/automysqlbackup:success### Copying files.if you are running automysqlbackup under the same user as you run this install script,you should be able to access it by running 'automysqlbackup' from the command line.if not, you have to check if 'echo $PATH' has /usr/bin in itSetup Complete![root@DB-Server automysqlbackup]#

如下所示,你会发现install.sh脚本将automysqlbackup.conf、 LICENSE、 README三个文件拷贝到/etc/automysqlbackup/目录下,并复制了

automysqlbackup.conf文件生成了myserver.conf

[root@DB-Server ~]# cd /etc/automysqlbackup/

[root@DB-Server automysqlbackup]# ls

automysqlbackup.conf LICENSE myserver.conf README

[root@DB-Server automysqlbackup]#

2:配置自己的AutoMySQLBackup的配置文件myserver.conf

默认情况下,这些AutoMySQLBackup的参数都是注释的,你需要取消注释,给予相关参数配置信息,例如使用那个账号做备份、账号密码、

# Username to access the MySQL server e.g. dbuserCONFIG_mysql_dump_username='root'    --备份账号# Password to access the MySQL server e.g. passwordCONFIG_mysql_dump_password='123456'# Host name (or IP address) of MySQL server e.g localhostCONFIG_mysql_dump_host='localhost'# "Friendly" host name of MySQL server to be used in email log# if unset or empty (default) will use CONFIG_mysql_dump_host instead#CONFIG_mysql_dump_host_friendly=''# Backup directory location e.g /backupsCONFIG_backup_dir='/u03/mysqlbackup/'....................................................

下面列出了部分主要的参数设置,具体可以参考automysqlbackup.conf 或 myserver.conf里面的参数的描述参数设置

参数功能

样例

CONFIG_mysql_dump_username

备份时连接数据库的账号

CONFIG_mysql_dump_username='root'

CONFIG_mysql_dump_password

备份账号的密码

CONFIG_mysql_dump_password='******'

CONFIG_mysql_dump_host

备份服务器名称或IP,一般用'localhost'

CONFIG_mysql_dump_host='localhost'

CONFIG_mysql_dump_host_friendly

设置服务器别名,如果不设置或为空,则使用CONFIG_mysql_dump_host替换

CONFIG_backup_dir

数据库备份路径

CONFIG_backup_dir='/mysqldata/db_backup/mysqlbackup'

CONFIG_multicore

压缩数据时是否启用多核,具体参考文档解释

CONFIG_multicore_threads

多线程数量

CONFIG_db_names

要备份的数据库

CONFIG_db_month_names

要做月备份的数据库

CONFIG_table_exclude

备份时要排除那些表

CONFIG_db_exclude

备份时要排除那些db

CONFIG_do_monthly

在每个月的第几天做月备份

CONFIG_do_weekly

星期几做周备份

CONFIG_rotation_daily

日备的保留周期

CONFIG_rotation_weekly

周备的保留周期

CONFIG_rotation_monthly

月被的保留周期

CONFIG_mysql_dump_port

MySQL的端口号

CONFIG_mysql_dump_compression

备份文件采用的压缩格式

CONFIG_mysql_dump_compression='gzip'

CONFIG_mysql_dump_differential

是否做差异备份

CONFIG_mysql_dump_differential='yes'

CONFIG_encrypt

备份是否加密

CONFIG_encrypt_password

备份加密的密码

README里面关于配置参数的一个参考样本,一般参数设置应该根据具体情况也业务需求来合理设定。

Default configurationCONFIG_configfile="/etc/automysqlbackup/automysqlbackup.conf"CONFIG_backup_dir='/var/backup/db'CONFIG_do_monthly="01"CONFIG_do_weekly="5"CONFIG_rotation_daily=6CONFIG_rotation_weekly=35CONFIG_rotation_monthly=150CONFIG_mysql_dump_usessl='yes'CONFIG_mysql_dump_username='root'CONFIG_mysql_dump_password=''CONFIG_mysql_dump_host='localhost'CONFIG_mysql_dump_socket=''CONFIG_mysql_dump_create_database='no'CONFIG_mysql_dump_use_separate_dirs='yes'CONFIG_mysql_dump_compression='gzip'CONFIG_mysql_dump_commcomp='no'CONFIG_mysql_dump_latest='no'CONFIG_mysql_dump_max_allowed_packet=''CONFIG_db_names=()CONFIG_db_month_names=()CONFIG_db_exclude=( 'information_schema' )CONFIG_mailcontent='log'CONFIG_mail_maxattsize=4000CONFIG_mail_address='root'CONFIG_encrypt='no'CONFIG_encrypt_password='password0123'

3:运行备份脚本并检查备份

[root@DB-Server ~]# /usr/bin/automysqlbackup /etc/automysqlbackup/myserver.confParsed config file "/etc/automysqlbackup/automysqlbackup.conf"# Checking for permissions to write to folders:base folder /u03 ... exists ... ok.backup folder /u03/mysqlbackup/ ... exists ... writable? yes. Proceeding.checking directory "/u03/mysqlbackup//daily" ... exists.checking directory "/u03/mysqlbackup//weekly" ... exists.checking directory "/u03/mysqlbackup//monthly" ... exists.checking directory "/u03/mysqlbackup//latest" ... exists.checking directory "/u03/mysqlbackup//tmp" ... exists.checking directory "/u03/mysqlbackup//fullschema" ... exists.checking directory "/u03/mysqlbackup//status" ... exists.# Testing for installed programsmysql ... found.mysqldump ... found.gzip ... found.# Parsing databases ... done.======================================================================AutoMySQLBackup version 3.0http://sourceforge.net/projects/automysqlbackup/Backup of Database Server - localhostDatabases - mysql,performance_schema,testDatabases (monthly) - mysql,performance_schema,test============================================================================================================================================Dump full schema.Rotating 4 month backups for============================================================================================================================================Dump status.Rotating 4 month backups for======================================================================Backup Start Time Sat Jul 11 22:16:32 CST 2015======================================================================Daily Backup ...Daily Backup of Database ( mysql )Rotating 6 day backups for mysql----------------------------------------------------------------------Daily Backup of Database ( performance_schema )Rotating 6 day backups for performance_schema----------------------------------------------------------------------Daily Backup of Database ( test )Rotating 6 day backups for test----------------------------------------------------------------------Backup End Time Sat Jul 11 22:16:33 CST 2015======================================================================Total disk space used for backup storage...Size - Location750k /u03/mysqlbackup/======================================================================###### WARNING ######Errors reported during AutoMySQLBackup execution.. Backup failedError log below..Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.Warning: Using a password on the command line interface can be insecure.

检查备份目录,你会发现生成了daily、fullschema、 latest、 monthly、 status、 tmp、 weekly等目录,刚刚备份的文件位于daily目录下,如下所示

手动安装配置

AutoMySQLBackup也可以手动配置,在文档README里面有介绍如何手工配置,也非常的简单

1. Create the /etc/automysqlbackup directory.

2. Copy in the automysqlbackup.conf file.

3. Copy the automysqlbackup file to /usr/local/bin and make executable.

4. cp /etc/automysqlbackup/automysqlbackup.conf /etc/automysqlbackup/myserver.conf

5. Edit the /etc/automysqlbackup/myserver.conf file to customise your settings.

6. See usage section.

AutoMySQLBackup的使用

AutoMySQLBackup使用mutt发送邮件,它是linux下的一个email程序,由于我们一般都使用sendmail发送邮件,所以一般在配置文件里面不启用改参数。所以使用AutoMySQLBackup时,一般自己写shell脚本,调用AutoMySQLBackup来备份数据,如下所示automysqlbackup.sh

#REM backup script#REM ----------------------------------------#REM  Backup script for EEL Mysql#REM  Tommy Wang -  08-14-2012#REM  Kerry Kong -  07-12-2015 Modify this Script#REM ----------------------------------------#REM - USER DEFINED VARIABLES -export DATESTAMP=`date '+%F'`#REM - Logfiles -export BACKUP_FULL_LOG=/mysqldata/db_backup/logs/auto_backup_$DATESTAMP.log/usr/local/bin/automysqlbackup /etc/automysqlbackup/myserver.conf >>$BACKUP_FULL_LOGchown mysql.mysql /mysqldata/db_backup -R >>$BACKUP_FULL_LOGfind  /mysqldata/db_backup -type f -exec chmod 400 {} \; >>$BACKUP_FULL_LOGfind  /mysqldata/db_backup -type d -exec chmod 700 {} \; >>$BACKUP_FULL_LOGEMAILTMP=/mysqldata/db_backup/logs/auto_backup_db_$DATESTAMP.TMP##################################### config email parameters ####################################echo 'Content-Type: text/html' > $EMAILTMPecho 'To: dba@xxxx.com' >> $EMAILTMPecho 'Subject: Backup Status - The server xxxx  MYSQL (dump backup)' >> $EMAILTMPecho '

' >> $EMAILTMP#################################################################################################echo "==============================================================================" >> $EMAILTMPecho "======================== Daily Backup for Mysql Database =====================" >> $EMAILTMPecho "==============================================================================" >> $EMAILTMPecho " " >> $EMAILTMPcat $BACKUP_FULL_LOG >> $EMAILTMP 2>&1echo " " >> $EMAILTMPecho "================================== End of Backup =============================" >> $EMAILTMPecho "==============================================================================" >> $EMAILTMP/usr/sbin/sendmail -t -f "BackupAdmin" < $EMAILTMPrm $EMAILTMPchown mysql.mysql $BACKUP_FULL_LOG

使用AutoMySQLBackup发送邮件时,会有下面告警提示,这个是因为我们将连接数据库的账号密码配置在配置文件中,这样非常不安全。如何去掉这个告警提示呢? AutoMysqlBackup: Warning: Using a password on the command line interface can be insecure. 这篇博客里面介绍了一种方法

找到automysqlbackup文件,找到removeIO,然后在其下面加上下面这段脚本后,你就不会收到告警信息。

[root@getlnx20 ~]# cd /usr/local/bin

[root@getlnx20 bin]# vi automysqlbackup

removeIOAdd this after removeIO:# Remove annoying warning message since MySQL 5.6if [[ -s "$log_errfile" ]]; thensedtmpfile="/tmp/$(basename $0).$$.tmp"grep -v "Warning: Using a password on the command line interface can be insecure." "$log_errfile" > $sedtmpfilemv $sedtmpfile $log_errfilefi

关于AutoMySQLBackup的介绍到这里,其实AutoMySQLBackup还有很多细节地方值得我们去学习、研究。限于篇幅,不在此一一赘述。

mysql backup_MySQL备份还原——AutoMySQLBackup介绍相关推荐

  1. [ MySQL ] 使用Navicat进行MySQL数据库备份 / 还原(Part 2:备份.sql文件方式)

    本文主要讲解如何用Navicat(Navicat Premium ,或者Navicat for mysql)进行MySQL备份和恢复数据库(利用.sql文件的方式). 关于MySQL数据库备份,本博客 ...

  2. 十一、MYSQL数据库备份还原

    十一.MYSQL数据库备份还原 数据库冷备份 mysqldump备份和还原数据库 备份 主从数据库备份 备份指定数据库 备份多个数据库 备份所有数据库 备份数据表 方法1: `mysqldump`备份 ...

  3. [ MySQL ] 使用Navicat进行MySQL数据库备份 / 还原(Part 1:备份.nb3文件方式)

    本文主要讲解如何用Navicat(Navicat Premium ,或者Navicat for mysql)进行MySQL备份和恢复数据库. 本文主要大纲为:使用Navicat备份工具方式进行备份和还 ...

  4. 备份校验两不误,MySQL自动备份还原校验设计详解

    作者介绍 庞阔,优朋普乐传媒运维基础部经理.负责数据库运营管理及平台设计开发,监控设计改进,问题跟踪处理,机房网络维护管理,目前四个专利已在专利局申请中.擅长数据库运维管理及Shell.Perl.PH ...

  5. mysql数据库备份还原

    首先进入cmd.exe 然后进入进入mysql C:\Windows\SysWOW64>cd C:\mysql\binC:\mysql\bin>mysql -u root -p 创建数据库 ...

  6. MYSQL数据库备份还原,并还原到最新状态(mysqldump,xtrabackup)

    启用二进制日志文件 vim /etc/my.cnf 配置文件位置及文件名根据实际情况确定 sql_log_bin=ON|OFF:是否记录二进制日志,默认为ON //在需要的时候设置为OFF log_b ...

  7. linux怎么把mysql数据库备份还原,MySQL数据库备份和还原

    MySQL数据库备份和还原 打开cmd命令行,一定不是mysql的命令行,我第一次就错在这个地方,郁闷了很久 备份MySQL数据库的命令 mysqldump -hhostname -uusername ...

  8. MySQL增量备份还原

    增量备份还原 前提: 备份后插入数据 模拟用户破坏数据 增量备份,恢复过程 1.查看凌晨的完全备份 2.检查全备后所有binlog 3.立即刷新并备份出binlog mysqlbinlog增量恢复 恢 ...

  9. SharePoint2010网站备份还原简单介绍

    今天尝试了SharePoint2010网站的备份和还原,从网上搜一些文档看看,然后自己试试,感觉和2007的操作没什么太大的区别,跟大家分享下自己尝试的命令行方式和数据库的方式,2007自己常用的也是 ...

最新文章

  1. [PKUWC2018]随机算法
  2. webpack4 系列教程: 前言
  3. rabbitMQ第一篇:rabbitMQ的安装和配置
  4. Cocoa如何应用设计模式
  5. NLP-基础知识-006(机器学习)
  6. 【机器学习】算法面试知识点整理(持续更新中~)
  7. python什么是数据结构_〖Python〗-- 数据结构
  8. 粉红噪音_粉红的常绿力量
  9. Cisco 胖AP和瘦AP的区别
  10. 【dfs】简单游戏(jzoj 2121)
  11. 阿里巴巴获评《福布斯》全球最有投资价值公司
  12. php首字母 大写 数组去重复
  13. 在rem布局下使用背景图片以及sprite
  14. 用Matlab分享一个软件低通滤波算法
  15. C语言开定时器做呼吸灯程序,用定时器实现呼吸灯程序
  16. 小米笔记本linux系统下载,传小米笔记本不用Win10用Linux系统 推12.5寸/13.3寸两款...
  17. 【windows10】 CH340/CH341 USB转串口驱动安装
  18. Vue安装步骤及教程(详细)
  19. 我对大学的憧憬||每个人都有自己的罗马
  20. MySQL5.7官方下载链接导航

热门文章

  1. 计算机二级公共基础知识总结百度云,计算机二级公共基础知识总结详细版本[精]...
  2. catia 创成钣金设计_弯曲的钣金设计技巧
  3. 消息队列面试经典十连问
  4. 【RocketMQ工作原理】消息的生产过程
  5. Springboot swagger2教程
  6. Swift3的playground中对UI直接测试支持的改变
  7. 本地Windows 7/8上搭建IIS服务器
  8. 群同态基本定理证明_近世代数(3)——群的基本性质
  9. python 私有云_利用Docker+NextCloud搭建私有云盘
  10. 这款开源测试神器,圆了我玩游戏不用动手的梦想