bitsCN.com
mysql自动化备份方案 一、配置数据库服务器1、撰写mysql自动备份脚本mysql备份主要包括热备和冷备,在此使用热备,也就是利用mysqldump导出SQL语句的方式进行备份#vi /etc/mysqlback.sh#!/bin/bash DB_NAME="luwenju" //需要备份的数据库DB_USER="luwenju" //数据库用户名DB_PASS="luwenju" //数据库密码BIN_DIR="/usr/local/mysql/bin" //mysql的环境变量BACK_DIR="/opt" //备份文件保存数据DATE="`date +%Y%m%d`"$BIN_DIR/mysqldump –opt -u$DB_USER -p$DB_PASS $DB_NAME > $BACK_DIR/luwenju_$DATE.sql#chmod +x /etc/mysqlback.sh测试#/etc/mysqlback.sh#ls /opt/luwenju_20110626.sql2、设置定时备份周期本案例中设置的为每日凌晨进行备份一次,具体备份周期根据具体应用#crontab –e0 0 * * * /etc/mysqlback.sh#/etc/init.d/crond restart3、安装rsync#tar zxvf rsync-3.0.8.tar.gz#cd rsync-3.0.8#./configure && make && make install创建配置文件,加入如下内容#vi /etc/rsync.confuid = nobody gid = nobodyuse chroot = nomax connections = 10pid file = /var/run/rsyncd.pidlock file = /var/run/rsyncd.locklog file = /var/log/rsyncd.logport = 873timeout = 300[backup]read only = yes //只读模式list = yesignore errorscomment = This is a file backpath = /opt //需要同步的目录auth users = test //验证用户secrets file = /etc/rsync.passwd //验证密码路径hosts allow = 119.232.33.246 //允许连接的客户端 作者 ibmfahsion bitsCN.com