Linux系统下的数据镜像备份工具——Rsync

1、什么是rsync

rsync,remote synchronize顾名思意就知道它是一款实现远程同步功能的软件,它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。 rsync是用“rsync 算法”提供了一个客户机和远程文件服务器的文件同步的快速方法,而且可以通过ssh方式来传输文件,这样其保密性也非常好,另外它还是免费的软件。

  rsync 包括如下的一些特性:

  能更新整个目录和树和文件系统;
  有选择性的保持符号链链、硬链接、文件属于、权限、设备以及时间等;
  对于安装来说,无任何特殊权限要求;
  对于多个文件来说,内部流水线减少文件等待的延时;
  能用rsh、ssh 或直接端口做为传输入端口;
  支持匿名rsync 同步文件,是理想的镜像工具;

2、rsync的安装,通用方式:yum install rsync

3、rsync服务器的配置文件

cat /etc/rsyncd/rsync.conf 
# Distributed under the terms of the GNU General Public License v2
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script

pid file = /var/run/rsync.pid
port = 873
#address = 192.168.1.171
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = yes
read only = no

#limit access to private LANs
hosts allow=*
#hosts deny=*
max connections = 5
motd file = /etc/rsyncd/rsync.motd

#This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes

log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

[data]
path = /data1
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd/rsync.secrets
comment = rsync data1 dir
#exclude = beinan/ samba/

[garbagekrc]
path = /data1/garbagekrc
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd/rsync.secrets
comment = rsync garbagekrc dir

用户密码文件:

cat /etc/rsyncd/rsync.secrets 
root:test123

其中用户名必须是服务器上已经存在的用户
4、启动rsync服务:/usr/bin/rsync --daemon --config=/etc/rsyncd/rsync.conf

5、备份文件到服务器:

rsync -az --password-file=rsync.password jsoncpp/* root@IP::data/mydata/

其中:password-file可以指定密码。

6、rsync也可以从服务器上拉文件到本地。结合crontab可以实现定时同步的功能。

7、更多用法请:man rsync。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值