CentOS 使用rsync进行远程备份

服务器和客户机都需要安装启用rsync服务

安装rsync软件

  #yum install rsync

服务器端设置

  设置/etc/rsyncd.conf

#global settings

pid file = /var/run/rsyncd.pid
port = 873
lock file = /var/run/rsyncd.lock
log file = /var/log/rsync.log
gid = root
uid = root

[auth_data]
path = /bakup
use chroot = no
max connections = 15
read only = no
write only = no
list = no
ignore errors = yes
timeout = 120
auth users = test
secrets file = /etc/rsyncd.passwd

 

  设置客户端连接要使用的账号/etc/rsyncd.passwd

  echo "test:test" > /etc/rsyncd.passwd  ##设置账户-密码

  chmod 600 /etc/rsyncd.passwd

  mkdir -p /bakup

  启动服务:  #rsync --daemon

  查看是否已启动:#netstat -tlnp | grep 873

客户机端设置

  设置连接服务器rsync需要用到的密码:/home/user/rsyncd.passwd  只需要输入密码

  echo "test" > /home/rsyncd.passwd
  chmod 600 /home/rsyncd.passwd

  连接测试(不用输入密码的方式,脚本可以用):

  rsync -avz --progress --password-file=/home/rsyncd.passwd test@192.168.1.x::auth_data /home/  ##下载到客户端home目录

  rsync -avz --progress --password-file=/home/rsyncd.passwd /home/test.txt test@192.168.1.98::auth_data  ##上传本机home目录的test.txt文件到服务端/bakup目录

posted on 2019-07-24 17:26  BI0Swu1y  阅读(189)  评论(0编辑  收藏  举报