Linux - rsync (李作强)

rsync是lunix系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。
默认的端口:873

服务端
安装yum源
yum -y install xinet* rsync*
创建配置文件:
vim /etc/rsyncd.conf (自创建)

uid = root //运行RSYNC守护进程的用户
gid = root //运行RSYNC守护进程的组
port = 873 // 默认的端口
hosts allow = 172.16.0.132, …….. //添加允许访问的IP,客户端。
hosts deny = 0.0.0.0/32 //禁止所有的IP访问。
use chroot = no //不使用chroot,改变根目录
max connections = //最大的链接数
timeout= //超时时间
pid file = /var/run/rsyncd.pid //pid文件存放的位置
lock file = /var/run/rsync.lock //锁文件的存放位置
log file = /var/log/rsyncd.log //日志记录文件的存放位置

motd file = /etc/rsyncd.motd
【模块参数】
[mysql132] //这里是认证的模块名,在服务端需要指定
path = /backup/mysql/mysql_132 //这里是认证的模块名,在服务端需要指定
comment = rsync file //这个模块的注释信息
ignore errors //忽略错误信息
read only = no // 只读
list = no //不允许列文件
auth users = backup //认证的用户名,如果没有这行则表明是匿名,此用户与系统无关
secrets file=/etc/rsync.passwd //密码和用户名对比表,密码文件自己生成

创建存放密码的配置文件
vim /etc/rsync.passwd

backup:1q2w3e4r

给密码文件权限,只能是600。
chmod 600 /etc/rsync.passwd
chown root.root /etc/rsync.passwd
创建一个存放备份文件的路径
mkdir -p /backup/mysql/mysql_132
修改配置文件,在7的虚拟机没有这一部:
vim /etc/xinetd.d/rsync
service rsync
{
disable = no #把yes改成no
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = –daemon
log_on_failure += USERID
}
开机自启:
/usr/bin/rsync –daemon –config=/etc/rsyncd.conf
开机自启的配置的配置文件。
vim /etc/rc.local

/usr/bin/rsync –daemon –config=/etc/rsyncd.conf

客户端
yum -y install rsync
mkdir /backup
touch /etc/rsync.passwd
chmod 600 /etc/rsync.passwd
echo “1q2w3e4r” > /etc/rsync.passwd
mkdir /usr/sbin/shell
touch /usr/sbin/shell/backup.sh
chmod +x /usr/sbin/shell/ -R

手动测试
rsync -avzuP –password-file=/etc/rsync.passwd –delete /backup/ [email protected]::mysql132

C7的测试方法
rsync -avzuP –password-file=/etc/rsync.passwd –delete /backup/[email protected]::mysql132 //上传
rsync -avzuP –password-file=/etc/rsync.passwd [email protected]::http133 /tmp //下载

添写备份脚本
vim /usr/sbin/shell/backup.sh

/bin/bash
time=/bin/date +%Y%m%d
/opt/zbox/run/mysql/mysqldump –single-transaction zentao | /bin/gzip > /backup/zentao_ {time}.sql.gz  /opt/zbox/run/mysql/mysqldump –single-transaction zentaopro | /bin/gzip > /backup/zentaopro_ {time}.sql.gz
/bin/tar -zcvf /backup/svn_${time}.tar.gz /opt/svn/ >/dev/null 2>&1 //错误的信息不输出到屏幕。

/bin/find /backup/ -mtime +2 -exec /bin/rm -f {} \; //保留两天的数据。

/usr/bin/rsync -avzuP –password-file=/etc/rsync.passwd –delete /backup/*.sql.gz [email protected]::mysql132 >/dev/null 2>&1
/usr/bin/rsync -avzuP –password-file=/etc/rsync.passwd –delete /backup/*.tar.gz [email protected]::svn132 >/dev/null 2>&1

if [[ ? == 0 ] ] t h e n / b i n / e c h o {DATE}:backup complete”>>backup.log
else
/bin/echo “${DATE}:backup failed”>>backup.log
fi

crontab -e

10 1 * * * /usr/sbin/shell/backup.sh

find -mtime参数解析
http://www.cnblogs.com/wanqieddy/archive/2011/06/09/2076785.html

猜你喜欢

转载自blog.csdn.net/weixin_41949714/article/details/81877155
今日推荐