• [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
  • 相关阅读:
    洛谷 P1593 因子和
    洛谷 P1167 刷题
    洛谷 P1613 跑路
    洛谷 P1629 邮递员送信
    洛谷 P1654 OSU!
    洛谷 P1967 货车运输
    FPGA开平方的实现
    FPGA设计思想之串并转换
    verilog乘法器的设计
    FPGA浮点数定点数的处理
  • 原文地址:https://www.cnblogs.com/davidhhuan/p/8196111.html
Copyright © 2020-2023  润新知