Rsync 是一款开源的、快速的 多功能的 能够实现全量以及增量的本地或者是远程的数据同步备份的优秀工具,而且能够不进行改变原有的数据属性信息,实现数据的备份和迁移的特性 ,Rsync 软件适用于 Linux/unix/windows 等多种操做系统上 。html
本地备份; 远程备份; 无差别备份;
全量备份数据 增量备份数据
[root@pre2 ~]# rpm -qa | grep rsync rsync-3.0.9-17.el7.x86_64 puppet-rsync-0.4.0-3.447685fgit.el7.noarch
[root@pre2 ~]# rsync --version rsync version 3.0.9 protocol version 30 Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, xattrs, iconv, symtimes rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details.
cat >/etc/rsyncd.conf<<EOF uid = rsync gid = rsync use chroot = no max connections = 200 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log ignore errors read only = false list = false hosts allow = 192.168.3.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password [backup] path = /root/backup EOF
#rsync_config ##rsyncd.conf start## uid = rsync # 用户 远端的命令使用rsync访问共享目录 gid = rsync # 用户组 use chroot = no # 安全相关 max connections = 200 # 最大链接数 timeout = 300 # 超时时间 pid file = /var/run/rsyncd.pid # 进程对应的进程号文件 lock file = /var/run/rsyncd.lock # 锁文件 log file = /var/log/rsyncd.log # 日志文件 ignore errors # 忽略错误 read only = false # 可写 list = false # 不能列表 hosts allow = 172.16.1.0/24 # 容许链接的服务器 hosts deny = 0.0.0.0/32 # 后勤组链接的服务器 auth users = rsync_backup # 虚拟用户 secrets file = /etc/rsync.password # 虚拟用户对应的用户和密码文件 [backup] # 模块名称 path = /backup # 服务端提供访问的目录
[root@pre2 ~]# mkdir -p backup #建立目录 [root@rsync ~]# ls backup install.log install.log.syslog optimize-init_sys.sh sysctl.conf [root@pre2 ~]# useradd rsync -s /sbin/nologin -M #建立rsync备份目录的管理用户与用户组 [root@pre ~]# chown -R rsync.rsync backup/ #受权
第二步;建立服务端和客户端的身份认证文件git
[root@pre2 ~]# echo "rsync_backup:rsync123" >/etc/rsync.password [root@pre2 ~]# chmod 600 /etc/rsync.password #配置文件权限只容许 root 用户查看 [root@pre2 ~]# cat /etc/rsync.password rsync_backup:rsync123
启动 rsync 服务redis
[root@pre2 ~]# rsync --daemon [root@pre2 ~]# netstat -lntup |grep rsync tcp6 0 0 :::873 :::* LISTEN 14564/rsync
CentOS 默认以 xinetd 方式运行 rsync 服务。rsync 的 xinetd 配置文件 在 /etc/xinetd.d/rsync。windows
要配置以 xinetd 运行的 rsync 服务须要执行以下的命令,也能够rsync --daemon 这样独立运行 。安全
# chkconfig rsync on # service xinetd restart
[root@pre1 ~]# rpm -qa|grep rsync rsync-3.0.9-17.el7.x86_64 puppet-rsync-0.4.0-3.447685fgit.el7.noarch [root@pre1 ~]# echo "rsync123" >/etc/rsync.password [root@pre1 ~]# cat /etc/rsync.password rsync123 [root@pre1 ~]# chmod 600 /etc/rsync.password [root@pre1 ~]# ls -ld /etc/rsync.password -rw-r--r-- 1 root root 9 May 13 17:15 /etc/rsync.password