标签:rsync服务
RSYNC服务备份服务器是架构中最重要的服务器
实现增量复制的原理:
Rsync通过其独特的“quick check”算法,实现增量传输数据
rsync == cp命令
[root@backup ~]#
[root@backup ~]# cp -a /etc/hosts /tmp/
[root@backup ~]# ls /tmp/hosts
/tmp/hosts
[root@backup ~]# rm -f /tmp/hosts
[root@backup ~]# ls /tmp/hosts
ls: cannot access /tmp/hosts: No such file or directory
[root@backup ~]# rsync /etc/hosts /tmp/
[root@backup ~]# ls /tmp/hosts
/tmp/hosts
rsync == scp命令
[root@backup ~]# scp -rp /etc/hosts 10.0.0.31:/tmp/
The authenticity of host ‘10.0.0.31 (10.0.0.31)‘ can‘t be established.
RSA key fingerprint is 4d:00:46:ff:a3:4d:1d:2e:5b:f0:72:28:ec:54:29:86.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘10.0.0.31‘ (RSA) to the list of known hosts.
root@10.0.0.31‘s password:
hosts 100% 371 0.4KB/s 00:00
[root@backup ~]# rsync -rp /etc/hosts 10.0.0.31:/tmp/
root@10.0.0.31‘s password:
rsync == rm命令
[root@backup tmp]# mkdir /oldboy01
[root@backup tmp]# cp -a /tmp/ /oldboy01/
[root@backup tmp]# ll /oldboy01/
total 16
-rw-r--r-- 1 root root 371 Oct 11 15:12 hosts
-rw-r--r-- 1 root root 4165 Oct 10 12:24 optimize-init_sys.sh
-rw-r--r-- 1 root root 2184 Aug 5 2015 sysctl.conf
[root@backup tmp]# rm -rf /oldboy01/
[root@backup tmp]# ll /oldboy01/
total 0
[root@backup tmp]# mkdir /null
[root@backup tmp]# cp -a /tmp/* /oldboy01/
[root@backup tmp]# rsync --delete /null/ /oldboy01/
rsync: --delete does not work without -r or -d.
rsync error: syntax or usage error (code 1) at main.c(1422) [client=3.0.6]
[root@backup tmp]# rsync -r --delete /null/ /oldboy01/
[root@backup tmp]# ll /oldboy01/
total 0
rsync == ls -l命令
[root@backup tmp]# # rsync == ls
[root@backup tmp]# ls -l /etc/hosts
-rw-r--r--. 2 root root 371 Oct 10 15:45 /etc/hosts
[root@backup tmp]# rsync /etc/hosts
-rw-r--r-- 371 2017/10/10 15:45:09 hosts
将备份/home 目录自 2008-01-29 以来修改过的文件
tar -N 2008-01-29 -zcvf /backups/inc-backup$(date +%F).tar.gz /home
将备份 /home目录昨天以来修改过的文件
tar -N $(date -d yesterday "+%F") -zcvf /backups/inc-backup$(date +%F).tar.gz /home
添加文件到已经打包的文件
tar -rf all.tar *.gif
说明:这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。
Rsync的企业工作场景说明
SYNOPSIS
Local: rsync [OPTION...] SRC... [DEST]
本地数据同步方式
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
远程数据同步方式:
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
守护进程方式数据同步:
Local: rsync [OPTION...] SRC... [DEST]
rsync -- 数据同步命令
[OPTION...] -- rsync命令参数信息
SRC -- 要同不得数据信息(文件或目录)
[DEST] -- 将数据传输到什么位置
实例演示命令:
rsync /etc/hosts /tmp/
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
说明:需要进行交互传输数据。如果想实现免交互传输数据,需要借助ssh+key方式实现
pull:
[USER@] : 以什么用户身份传输数据信息
HOST: 远程主机信息(IP地址信息 主机名称信息)
SRC: 远端要恏过来的数据信息
[dest] 恏到本地什么位置
push:
SRC: 本地要怼过去的数据信息
DEST 怼到远端什么位置
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
第一部分:配置rsync服务端(将服务端配置到backup服务器上)
第二个里程碑:进行软件服务配置
[root@backup tmp]# ll /etc/rsyncd.conf
ls: cannot access /etc/rsyncd.conf: No such file or directory
cat >/etc/rsyncd.conf <<EOF
#rsync_config
#created by HQ at 2017
##rsyncd.conf start##
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
[backup]
comment = "backup dir by oldboy"
path = /backup
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
EOF
常见问题:
问题01:
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
sending incremental file list hosts
rsync: mkstemp ".hosts.U5OCyR" (in backup) failed: Permission denied (13)
sent 200 bytes received 27 bytes 13.76 bytes/sec
total size is 371 speedup is 1.63
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
说明:备份目录权限设置不正确
标签:rsync服务
原文地址:http://blog.51cto.com/12908831/2128754