<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jojo's blog--快樂憂傷都與你同在
    為夢想而來,為自由而生。 性情若水,風起水興,風息水止,故時而激蕩,時又清平……
    posts - 11,  comments - 30,  trackbacks - 0

    Remote Backups With Rsync


    In this article we explain how to automate the backup of files on remote machines to a centralized server using rsync.

    rsync is a command line utility that is used to synchronize files between two computers over a network to synchronize files between two filesystems. It was written as a replacement for rcp but with many new features. For example it uses an algorithm that will only transfer files that have been modified. SSH will be used to authenticate between the machines and to encrypt the network traffic.

    The situation: We have four machines named: server, machine1, machine2, and machine3. The server has a tape drive that is used to do nightly backups. machine1 is used as a development box and has files that need to be backed up in /src and in /home. machine2 is used for mail and needs /home and /mail to be backed up. machine3 is a web server and needs /home, /var/www, and /etc/httpd backed up.

    Create a shell script for each machine. Simplify your maintenance by placing the scripts in a central location. I like to use /root/scripts. Decide on where you want to log your output. I like /root/logs but another common option is to have the script mail you the output.

    Add entries to your crontab to call the scripts. Make sure you leave enough time before your normal backups of the server that the rsync jobs complete.

    Each night the following will occur:

    1. rsync machine1 -> Server
    2. rsync machine2 -> Server
    3. rsync machine3 -> Server
    4. backup server to tape
    Let's take a look at the flags used for rsync in the examples:

    rsync -ave ssh --numeric-ids --delete machine1:/home /machine1

    • -a:
      Archive mode
    • -v:
      Verbose output
    • -e ssh:
      Specify the remote shell as ssh
    • --numeric-ids:
      Tells rsync to not map user and group id numbers local user and group names
    • --delete:
      Makes server copy an exact copy of the source by removing any files that have been removed on the remote machine
    • machine1:/home:
      The remote machine name, then the directory to be backed up
    • /machine1:
      The directory to place the backup

    Next generate a public private key pair with ssh. Place the public key in the ~/.ssh/authorized_keys file in an account on machine1, machine2, and machine3 that has read access to the directories that need to be backed up. It is best not to use the root account on the remote machines, but you should evaluate the risk in your environment. Test that you can login to these accounts using ssh without using a password.

    Test each one of the rsync scripts. The first time you run rsync will take the longest as it will need to copy all the files from the remote machines and not just the files that have changed.

    Add the /machine1, /machine2, and /machine3 (or whatever you have named them) directories to the servers backup script.

    While this process does not backup the entire remote machine, it will ensure that you will not lose irreplaceable data.

    Starting with the example scripts included in this tutorial there are many changes that can be made to fit your specific circumstances.

    The frequency of the rsyncs can be modified to occur more often or at different times. Simply by adding additional crontab lines the backup from the remote machines could be done everyday at lunch, multiple times a day or even hourly.

    The scripts could also be changed to rotate between multiple backups on the server or could be changed to do some sort of processing on the files before they are backed up. For example if the home directories you are backing up contain web browser caches, they could be removed after the rsync but before the system backup.

    Using this article as a starting point you should create a backup plan that fit your needs.


    Example rsync script for machine1:
    #!/bin/bash

    rsync -ave ssh --numeric-ids --delete machine1:/home /machine1
    rsync -ave ssh --numeric-ids --delete machine1:/src /machine1


    Example rsync script for machine2:
    #!/bin/bash

    rsync -ave ssh --numeric-ids --delete machine2:/home /machine2
    rsync -ave ssh --numeric-ids --delete machine2:/mail /machine2


    Example rsync script for machine3:
    #!/bin/bash

    rsync -ave ssh --numeric-ids --delete machine3:/home /machine3
    rsync -ave ssh --numeric-ids --delete machine3:/var/www /machine3
    rsync -ave ssh --numeric-ids --delete machine3:/etc/httpd /machine3



    Example crontab file logging to a directory:
    # Scripts to rsync machines
    59 20 * * * /root/scripts/sync-machine1.sh >/root/logs/sync-machine1.log 2>&1
    59 21 * * * /root/scripts/sync-machine2.sh >/root/logs/sync-machine2.log 2>&1
    59 22 * * * /root/scripts/sync-machine3.sh >/root/logs/sync-machine3.log 2>&1
    #
    # Nightly Backup script
    59 23 * * * /root/scripts/backup.sh > /root/logs/backup.log 2>&1

    Example crontab file mailing the output:


    # Scripts to rsync machines
    59 20 * * * /root/scripts/sync-machine1.sh
    59 21 * * * /root/scripts/sync-machine2.sh
    59 22 * * * /root/scripts/sync-machine3.sh
    #
    # Nightly Backup script
    59 23 * * * /root/scripts/backup.sh
    posted on 2009-01-20 16:29 Blog of JoJo 閱讀(199) 評論(0)  編輯  收藏 所屬分類: Linux 技術相關

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产亚洲成av人片在线观看 | 亚洲高清最新av网站| 亚洲国产视频久久| 男女免费观看在线爽爽爽视频| 日韩精品人妻系列无码专区免费 | 女性自慰aⅴ片高清免费| 91情国产l精品国产亚洲区| 久久福利青草精品资源站免费| 国产精品亚洲精品日韩已满| 成人片黄网站色大片免费观看APP| 国产亚洲综合一区柠檬导航| 成全视频高清免费观看电视剧| 亚洲中久无码永久在线观看同| 久久国产精品免费| 亚洲国产精品无码专区影院| 无码精品人妻一区二区三区免费看| 亚洲邪恶天堂影院在线观看| 国产黄色免费网站| 亚洲AV成人精品一区二区三区| 亚洲av无码专区在线观看素人| 国产免费网站看v片在线| 精品亚洲麻豆1区2区3区| 国产成人午夜精品免费视频| 五月天婷亚洲天综合网精品偷| 久久免费视频观看| 深夜福利在线免费观看| 亚洲综合色视频在线观看| 中文字幕无码毛片免费看| 亚洲国产成人久久综合一| 免费看国产成年无码AV片| 立即播放免费毛片一级| 亚洲级αV无码毛片久久精品| h片在线免费观看| 国内成人精品亚洲日本语音| 亚洲精品成人无限看| 一个人免费观看在线视频www| 免费夜色污私人影院网站| 4480yy私人影院亚洲| 特级淫片国产免费高清视频| 日本免费一区尤物| 精品一区二区三区免费观看 |