[CentOS] rsync同步目录进行备份文件

操作不难,网上一堆。这里列几个

 

CentOS7

参考地址: https://www.server-world.info/en/note?os=CentOS_7&p=rsync

 

Copy files or directories from one location to an another host by rsync.

If you'd like to set rsync automatically by cron or others, it need to configure like follows because authentication is required without settings. For example, Copy files or directories under the [/root/work] on dlp.srv.world to [/home/backup] on www.srv.world.

+----------------------+          |          +----------------------+
|     dlp.srv.world    |10.0.0.30 | 10.0.0.31|     www.srv.world    |
|                      +----------+----------+                      |
|     /root/work/*     |   ------------->    |     /home/backup/*   |
+----------------------+        copy         +----------------------+

 

[1] Configure on source host.

[root@dlp ~]# yum -y install rsync
[root@dlp ~]# vi /etc/rsync_exclude.lst

# specify files or directories you'd like to exclude to copy
test
test.txt

 

[2] Configure on destination host.

[root@www ~]# yum -y install rsync
[root@www ~]# vi /etc/rsyncd.conf

# any name you like
[backup]
# destination directory for copy
path = /home/backup
# hosts you allow to access
hosts allow = 10.0.0.30
hosts deny = *
list = true
uid = root
gid = root
read only = false

[root@www ~]# mkdir /home/backup 
[root@www ~]# systemctl start rsyncd 
[root@www ~]# systemctl enable rsyncd 

 

[3] It's OK. Execute rsync on Source Host like follows.

[root@dlp ~]# rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /root/work/ www.srv.world::backup

# Add in cron if you'd like to run reguraly
[root@dlp ~]# crontab -e

# for example, run at 2:00 AM in a day
00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /root/work/ www.srv.world::backup

 

 

 

CentOS6

参考地址:

https://www.server-world.info/en/note?os=CentOS_6&p=rsync

http://www.centoscn.com/CentosServer/ftp/2015/1123/6442.html

 

Synchronizes files and directories from one location to another by rsync.
The example below is for automatical settings. Ecxample ⇒ Copy files and directories in /var/www/html on a HostA[10.0.0.31] to in /home/backup on HostB[10.0.0.30].

 

[1] Configure on Destination Host.

[root@dlp ~]# yum -y install rsync xinetd
[root@dlp ~]# vi /etc/xinetd.d/rsync

# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#      allows crc checksumming etc.
service rsync
{
    disable= no# change
    flags= IPv6
    socket_type= stream
    wait= no
    user= root
    server= /usr/bin/rsync
    server_args= --daemon
    log_on_failure+= USERID
}

[root@dlp ~]# /etc/rc.d/init.d/xinetd start 
Starting xinetd:[ OK ]
[root@dlp ~]# chkconfig xinetd on

[root@dlp ~]# mkdir /home/backup 
[root@dlp ~]# vi /etc/rsyncd.conf

# any name you like
[website]
# destination directory
path = /home/backup
# Hosts you allow to copy (specify source Host)
hosts allow = 10.0.0.31
hosts deny = *
list = true
uid = root
gid = root
read only = false

[root@dlp ~]# /usr/bin/rsync --daemon

 

[2] Configure on Source Host.

[root@www ~]# yum -y install rsync
[root@www ~]# vi /etc/rsync_exclude.lst

# specify files or directories you'd like to exclude to copy
test
test.txt

 

[3] It's OK. Execute rsync on Source Host like follows.

[root@www ~]# rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /var/www/html/ 10.0.0.30::website

# Add in cron if you'd like to run reguraly
[root@www ~]# crontab -e

# run at 2:00 AM in a day
00 02 * * * rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /var/www/html/ 10.0.0.30::website

 

转载于:https://www.cnblogs.com/davidhhuan/p/8196111.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值