做为一个系统管理员,数据备份是很是重要的,若是没有作好备份策略,磁盘损坏了,那么你的数据将所有丢失,因此在平常的维护工做中,必定要时刻牢记给数据作备份.vim
rsync
不只能够能够远程同步数据(相似于scp),并且能够本地同步数据(相似于cp
),但不一样于scp
cp
的一点是,它不会覆盖之前的数据(若是数据已经存在),而是先判断已经存在的数据和新数据的差别,只有数据不一样时才会把不相同的部分覆盖.若是Linux没有rsync
命令能够经过yum install rsync -y
安装.安全
经常使用选项 | 解释 |
---|---|
-a | 这是归档模式,表示以递归方式传输文件,并保持全部属性,它等同于-rlptgoD.他后面能够跟一个--no-OPTION,表示关闭-rlptgoD中的某一个,好比-a--no-l等同于-rptgoD. |
-r | 表示以递归模式处理子目录,它主要是针对目录来讲的. |
-v | 表示打印一些信息,好比文件列表,文件数量 |
-l | 表示保留软连接 |
-L | 表示保持软连接,加上该参数后软连接指向的目标文件一块儿复制到目标中. |
-p | 表示标尺文件权限 |
-o | 表示保持文件的属主信息 |
-g | 表示保持文件的属组信息 |
-D | 表示保持设备文件信息 |
-t | 表示保持稳健时间信息 |
--delete | 表示删除DST中SRC没有的文件 |
--excluede=PATTERN | 表示指定排除不须要传输的文件 |
-u | 表示把DST中比SRC还新的文件排除掉,不会覆盖 |
-z | 加上此参数,将会在传输过程当中压缩 |
//直接拷贝 [root@backup ~]# rsync /etc/hosts /mnt [root@backup ~]# rsync -vzrtopg /etc/hosts /mnt/ sending incremental file list hosts sent 184 bytes received 31 bytes 430.00 bytes/sec total size is 294 speedup is 1.37 //本地有的远端就有(即便远端没有我给你),本地没有远端有的也要没有 [root@backup ~]# rsync -avz --delete /test /mnt/ //远程拷贝 [root@backup ~]# rsync -avz /etc/hosts -e 'ssh -p 22' root@192.168.56.31:/mnt/ root@192.168.56.31's password: sending incremental file list hosts sent 184 bytes received 31 bytes 47.78 bytes/sec total size is 294 speedup is 1.37
uid = rsync //用户 远端的命令使用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] //模块名称 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 vim /etc/rsync.password rsync_backup:123456 chmod 600 /etc/rsync.password [root@backup ~]# lsof -i :873