在Ubuntu系统下通过rsync备份数据库

每天定时在mysql server端(假设IP为:23.x.x.1)打包备份/var/lib/mysql,然后通过rsync备份至远端rsync备份服务器(假设IP为:23.y.y.2)上保存。

Mysql Server(IP: 23.x.x.1)----rsync---->Rsync Server(IP: 23.y.y.2)

Step 1).远程备份服务器, rsync服务端:

apt-get install rsync

vi /etc/default/rsync
RSYNC_ENABLE=true
:wq!

vi /etc/rsyncd.conf
[backup]
# destination directory for copy
path = /home/backup
# hosts you allow to access 若有多个IP以空格隔开
hosts allow = 23.x.x.1
hosts deny = *
list = true
uid = root
gid = root
read only = false
:wq!

mkdir /home/backup

/etc/init.d/rsync start

Step 2).MYSQL Server, rsync客户端:

apt-get install rsync
vi /etc/rsync_exclude.lst
/home/mysqlbak
:wq!

mkdir /home/mysqlbak

vi /usr/sbin/rsyncbaksql.sh
#!/bin/sh
filename=`date +%a`
tar -czPf /home/mysqlbak/sqlbak-$filename.tar.gz /var/lib/mysql/
rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /home/mysqlbak/ 23.y.y.2::backup
:wq!

chmod +x /usr/sbin/rsyncbaksql.sh

vi /etc/crontab
01 23 * * * root /usr/sbin/rsyncbaksql.sh > /dev/null 2>&1

上一篇: