Ubuntu Server使用automysqlbackup脚本(一)

2014-11-24 16:57:48 · 作者: · 浏览: 0
Ubuntu Server使用automysqlbackup脚本
昨天服务器意外关闭,导致开发环境数据库文件损坏,所以想起了做自动备份的事情,原本是打算自己用Mysqldump写个脚本来做计划任务的,不过出于偷懒的角度考虑,在网上找了找,发现了automysqlbackup,看评论都还不错,而且本身也是shell脚本实现的。本着不重复造轮子的精神,就 下载来使用了。
地址:http://sourceforge.net/projects/automysqlbackup/
选择的版本是最新的automysqlbackup-v3.0_rc6.tar.gz。
安装非常简单,比较麻烦的地方,是后面配置邮件客户端,以及脚本中的一个小bug。
1、在任意目录下,解压文件包
tar –xzf automysqlbackup-v3.0_rc6.tar.gz
2、省事起见,切个权限
sudo su -
3、安装(若对路径没有什么特别的要求,出现提示回车即可)
./install.sh
默认配置文件位置:/etc/automysqlbackup
默认sh文件位置:/usr/local/bin
4、修改配置文件
安装完成,默认会有两个配置文件,一个是automysqlbackup.conf,还有一个是myserver.conf。
实际上看了安装脚本就知道,这两个文件本来就是拷贝冗余了一个出来,猜测用途是防止二次安装或者误操作的情况下,误操作覆盖已经配置好的配置文件。不过从脚本逻辑上看起来,貌似没太大用,因为他重装,照样两个文件一块会覆盖。不过如果发现automysqlbackup.conf配置有值的话,会给出提示就是了。
依旧,为了偷懒期间,就直接修改automysqlbackup.conf了,毕竟这是默认配置,sh执行的时候,不用带任何参数。
主要需要注意的配置,有以下几个:(配置文件中,带有默认值,如果不需要更改,直接保持被注释的状态就好)
# 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='密码'
# "Friendly" host name of MySQL server to be used in email log
# if unset or empty (default) will use CONFIG_mysql_dump_host instead(dump的时候,数据库host显示的别名,不配的话,基本就都是localhost之流了)
CONFIG_mysql_dump_host_friendly='DataBaseAlias'
# Backup directory location e.g /backups(不用多说了,重中之重,备份路径)
CONFIG_backup_dir='/srv/backup/mysql'
# List of databases for Daily/Weekly Backup e.g. ( 'DB1' ' DB2' 'DB3' ... )
# set to (), i.e. empty, if you want to backup all databases(需要日备份和周备份的数据库名称)
CONFIG_db_names=('TestDB')
# List of databases for Monthly Backups.
# set to (), i.e. empty, if you want to backup all databases(需要月备份的数据库名称)
CONFIG_db_month_names=('TestDB')
# Which day do you want monthly backups (01 to 31) (月备份的日期,如果配置的日期大于当月最大日期,会在当月最后一天的时候执行)
# If the chosen day is greater than the last day of the month, it will be done
# on the last day of the month.
# Set to 0 to disable monthly backups.
#CONFIG_do_monthly="01"
# Which day do you want weekly backups (1 to 7 where 1 is Monday)(周备份在星期几发生)
# Set to 0 to disable weekly backups.
#CONFIG_do_weekly="5"
# Set rotation of daily backups. VALUE*24hours
# If you want to keep only today's backups, you could choose 1, i.e. everything older than 24hours will be removed.(日备份文件保留多少天)
CONFIG_rotation_daily=7
# Set rotation for weekly backups. VALUE*24hours(周备份文件保留多少天)
#CONFIG_rotation_weekly=35
# Set rotation for monthly backups. VALUE*24hours(月备份文件保留多少天)
#CONFIG_rotation_monthly=150
# Use ssl encryption with mysqldump (是否使用ssl,本地的话,开ssl找抽?远程就另算了)
CONFIG_mysql_dump_usessl='no'
# What would you like to be mailed to you (是不是想要备份完的时候,自动给你发个邮件?)
# - log : send only log file(邮件内容仅包含日志)
# - files : send log file and sql files as attachments (see docs)(邮件内容除了日志意外,把备份的压缩包也发给你)
# - stdout : will simply output the log to the screen if run manually.(表邮件了,屏幕显示下就好。问题是谁吃饱没事一天到晚盯着server屏幕看?)
# - quiet : Only send logs if an error occurs to the MAILADDR.(出错了的话,给个信儿就好)
CONFIG_mailcontent='files'
# Email Address to send mail to (user@domain.