使用说明:
1. 修改文件里的配置部分包括访问mysql的用户名密码,要备份的数据库,备份地址,发送邮件的地址(默认使用postfix):
[cce] # Username to access the MySQL server e.g. dbuser USERNAME=debian # Password to access the MySQL server e.g. password PASSWORD= # Host name (or IP address) of MySQL server e.g localhost DBHOST=localhost # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3" DBNAMES="all" # Backup directory location e.g /backups BACKUPDIR="/srv/backup/db" # Mail setup # 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. # - quiet : Only send logs if an error occurs to the MAILADDR. MAILCONTENT="log" # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs]) MAXATTSIZE="4000" # Email Address to send mail to? (user@domain.com) MAILADDR="maintenance@example.com" [/cce]
也可以把上面的东西写到一个配置文件里:
[cce]CONFIGFILE="/etc/automysqlbackup/automysqlbackup.conf"[/cce]
2. 给脚本增加可执行权限
[cce]chmod +x /root/automysqlbackup-2.5.1-01.sh[/cce]
3.用crontab定一个任务:比如每周一的零点备份
[cce] crontab e #输入下面的任务: #格式为dom=day of month #m h dom mon dow command 0 0 * * 1 /var/www/sqlback/automysqlbackup.sh [/cce]
4.安装postfix,备份日志会自动发送到上面指定的邮箱
[cce] # for redhat yum install postfix # for ubuntu apt-get install postfix [/cce]
大功告成,该脚本会在备份文件夹里自动建立monthly,weekly,daily的文件夹