日期:2014-05-16 浏览次数:20725 次
一、配置数据库服务器
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.sql
2、设置定时备份周期
本案例中设置的为每日凌晨进行备份一次,具体备份周期根据具体应用
#crontab –e
0 0 * * * /etc/mysqlback.sh
#/etc/init.d/crond restart
3、安装rsync
#tar zxvf rsync-3.0.8.tar.gz
#cd rsync-3.0.8
#./configure && make && make install
创建配置文件,加入如下内容
#vi /etc/rsync.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
port = 873
timeout = 300
[backup]
read only = yes //只读模式
list = yes
ignore errors
comment = This is a file back
path = /opt //需要同步的目录
auth users = test //验证用户
secrets file = /etc/rsync.passwd //验证密码路径
hosts allow = 119.232.33.246 //允许连接的客户端