MySQL备份还原——AutoMySQLBackup介绍

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个文件。

[[email protected] tmp]# tar -zxvf /tmp/automysqlbackup-v3.0_rc6.tar.gz  -C /tmp/automysqlbackup
automysqlbackup

automysqlbackup.conf

CHANGELOG

install.sh

README

LICENSE

automysqlbackup: AutoMySQLBackup的应用程序脚本

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

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

install.sh: AutoMySQLBackup的安装脚本

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

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

自动安装配置

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

[[email protected] tmp]# cd automysqlbackup
[[email protected] 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 it

 

Setup Complete!

[[email protected] automysqlbackup]# 

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

automysqlbackup.conf文件生成了myserver.conf

[[email protected] ~]# cd /etc/automysqlbackup/

[[email protected] automysqlbackup]# ls

automysqlbackup.conf LICENSE myserver.conf README

[[email protected] automysqlbackup]#

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

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

# Username to access the MySQL server e.g. dbuser
CONFIG_mysql_dump_username=‘root‘    --备份账号

 

# Password to access the MySQL server e.g. password

CONFIG_mysql_dump_password=‘123456‘

 

# Host name (or IP address) of MySQL server e.g localhost

CONFIG_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 /backups

CONFIG_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 configuration
CONFIG_configfile="/etc/automysqlbackup/automysqlbackup.conf"

CONFIG_backup_dir=‘/var/backup/db‘

CONFIG_do_monthly="01"

CONFIG_do_weekly="5"

CONFIG_rotation_daily=6

CONFIG_rotation_weekly=35

CONFIG_rotation_monthly=150

CONFIG_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=4000

CONFIG_mail_address=‘root‘

CONFIG_encrypt=‘no‘

CONFIG_encrypt_password=‘password0123‘

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

[[email protected] ~]# /usr/bin/automysqlbackup /etc/automysqlbackup/myserver.conf
Parsed 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 programs

mysql ... found.

mysqldump ... found.

gzip ... found.

 

# Parsing databases ... done.

======================================================================

AutoMySQLBackup version 3.0

http://sourceforge.net/projects/automysqlbackup/

 

Backup of Database Server - localhost

Databases - mysql,performance_schema,test

Databases (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 - Location

750k /u03/mysqlbackup/

 

======================================================================

 

###### WARNING ######

Errors reported during AutoMySQLBackup execution.. Backup failed

Error 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_LOG

chown mysql.mysql /mysqldata/db_backup -R >>$BACKUP_FULL_LOG

find  /mysqldata/db_backup -type f -exec chmod 400 {} \; >>$BACKUP_FULL_LOG

find  /mysqldata/db_backup -type d -exec chmod 700 {} \; >>$BACKUP_FULL_LOG

 

EMAILTMP=/mysqldata/db_backup/logs/auto_backup_db_$DATESTAMP.TMP

 

##################################### config email parameters ####################################

echo ‘Content-Type: text/html‘ > $EMAILTMP

echo ‘To: [email protected]‘ >> $EMAILTMP 

echo ‘Subject: Backup Status - The server xxxx  MYSQL (dump backup)‘ >> $EMAILTMP

echo ‘<pre style="font-family: courier; font-size: 9pt">‘ >> $EMAILTMP

#################################################################################################

 

echo "==============================================================================" >> $EMAILTMP

echo "======================== Daily Backup for Mysql Database =====================" >> $EMAILTMP

echo "==============================================================================" >> $EMAILTMP

echo " " >> $EMAILTMP 

 

cat $BACKUP_FULL_LOG >> $EMAILTMP 2>&1

echo " " >> $EMAILTMP 

echo "================================== End of Backup =============================" >> $EMAILTMP

echo "==============================================================================" >> $EMAILTMP

 

/usr/sbin/sendmail -t -f "BackupAdmin" < $EMAILTMP

rm $EMAILTMP

 

chown mysql.mysql $BACKUP_FULL_LOG

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

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

[[email protected] ~]# cd /usr/local/bin

[[email protected] bin]# vi automysqlbackup

removeIO
 

Add this after removeIO:

 

# Remove annoying warning message since MySQL 5.6

 

if [[ -s "$log_errfile" ]]; then

 

sedtmpfile="/tmp/$(basename $0).$$.tmp"

 

grep -v "Warning: Using a password on the command line interface can be insecure." "$log_errfile" > $sedtmpfile

 

mv $sedtmpfile $log_errfile

 

fi

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

时间: 2024-11-07 03:11:07

MySQL备份还原——AutoMySQLBackup介绍的相关文章

MySql 备份还原

mysql备份还原方法 mysql备份和还原我们一般会执行这样的操作:在现场mysql数据库(一般是linux系统)上备份数据库(一般有几十G到上百G)到windows机器上,然后到公司后将windows机器上的文件还原到公司的linux系统的mysql数据库上. 本文档主要用于需要备份的数据库很大的情况下的操纵(数据库很小的话有很多其他简便的方法).在现实情况当中我们一般是在现场做1,2步,然后3,4步是在公司做. 1.本文操作的场景:将192.168.1.207(centos)上的mysql

Linux运维 第四阶段 (六)MySQL备份&&还原(mysqldump、LV’s snapshot、xtrabackup)

Linux运维 第四阶段 (六)MySQL备份&&还原(mysqldump.LV's snapshot.xtrabackup) 一.相关概念 备份:副本,mysql-database备份不同于RAID(RAID是保证硬件损坏而不会业务终止) 备份内容:数据.配置文件.二进制日志.事务日志 1.备份类型: >热备份.温备份.冷备份 热备份:读写不受影响,复杂度高,InnoDB(xtrabackup,mysqldump),lvm快照功能可实现几乎热备: 温备份:仅可执行读操作,MyISA

(4.1)mysql备份还原——mysql常见故障

(4.1)mysql备份还原——mysql常见故障 1.常见故障类型 在数据库环境中,常见故障类型: 语句失败,用户进程失败,用户错误 实例失败,介质故障,网络故障 其中最严重的故障主要是用户错误和介质故障. 2.具体故障情况 故障问题大致分为以下几类 [2.1]语句错误:单个数据库操作(选择.插入.更新.删除)失败,软件逻辑问题. [2.2]用户进程错误:单个数据库会话失败,一般不需要敢于,分析日志观察 [2.3]网络故障:与数据库的链接断开,如:网卡坏,网络配置问题 [2.4]用户错误:用户

(4.3)mysql备份还原——mysql备份策略

(4.3)mysql备份还原——mysql备份策略 1.指定备份策略时需要考虑的点 [1.1]备份周期:2次备份间隔时长 [1.2]备份方式:在备份周期中,使用什么备份方式.备份模式 [1.3]实现方式:自动/手动备份 [1.4]备份介质:思考好存放介质,介质目录,raid等 [1.5]保证良好的一致性 [1.6]备份成本:时间.空间.性能 的消耗 [1.7]恢复成本:数据恢复消耗时间,数据恢复容忍丢失量,业务宕机时间 2.一般备份策略 [2.1]小型(10G以内): 直接拷贝数据库文件(文件系

Percona XtraBackup 关于 MySQL备份还原的详细测试

一. Percona XtraBackup 的优点. (1)无需停止数据库进行InnoDB热备: (2)增量备份MySQL: (3)流压缩传输到其它服务器: (4)在线移动表: (5)能够比较容易地创建主从同步: (6)备份MySQL时不会增大服务器负载. 二. Percona XtraBackup 工具集组成 在旧版本中,Percona XtraBackup 工具集里主要包含两个程序:innobackupex 和 xtrabackup. xtrabackup是C/C++编译的二进制程序,用来备

C#程序调用cmd执行命令-MySql备份还原

1.简单实例 //备份还原mysql public static void TestOne() { Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.

(4.12)mysql备份还原——mysql逻辑备份之mysqldump

关键词:mysql逻辑备份介绍,mysqldump 1.mysql逻辑备份介绍 [1.1]备份内容:数据库的结构定义语句+数据内容的插入语句,备份出来的文件可以编辑 [1.2]使用场景:数据量较少的库,比较适合100G数据量以内的 逻辑备份的特点 (1)sql语句组成的文件,可以编辑截取部分单独使用. (2)备份文件比物理文件小 (3)可以细化到表/表的内容 (4)速度慢 (5)可以跨平台恢复/迁移 2.逻辑备份工具 [1.1]mysqldump(单线程).mysqlpump(多线程,5.7以后

Mysql备份还原的一个bug

备份文件中索引的语法格式不对 从mysql备份出来的sql文件进行还原操作时报错,查看错误日志,内容如下: Error Code: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE) ENGINE=InnoDB AUTO_INCREMENT=

(4.2)mysql备份还原——备份概述

1.什么情况下会用到备份呢? [1.1]灾难恢复 [1.2]单位审计:数据库在过去某一个点是什么样的 [1.3]跨机房灾备:异地备份 [1.4]认为的DDL或者DML语句,导致主从库的数据消失 [1.5]业务测试,构建测试库 2.备份的分类 分为冷备份.温备份.热备份 [2.1]冷备份(离线备份:读写操作均中止) 优点:设备投资较少,节省费用,对环境要求不高. 缺点:恢复时间较长,一般要数天至1周,数据完整性与一致性比较差: [2.2]温备份(只可以执行读操作) 优点:设备投资较少,节省费用,对