Results 1 to 3 of 3

Thread: Rsync script to synchronize all my files between all machines

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Rsync script to synchronize all my files between all machines

    Hi all,
    I am trying to setup a automated rsync script to synchronize all my files between my machines but I have no clue how I would go on with creating an array for the directories I want to synchronize. What I want to accomplish is to sync all the directories in the $DIRS array to machines in the $SERVERS array. This is what I got so far:

    Code:
    #!/bin/bash
    SSHUSER="someuser"
    
    PROGRAM="rsync"
    
    OPTIONS="-razh --size-only"
    
    
    SERVERS=(
        machine1.domain.com 
        machine2.domain.com
        machine3.domain.com
    )
    
    DIRS=(
        /home/folder1/
        /home/folder2/
    )
    
    for server in ${SERVERS[*]} ; do
    
        echo "Synchronizing to $server beginning at" `date`
        $PROGRAM $OPTIONS $DIRS $SSHUSER@$server:/home/$SSHUSER/
         echo "Synchronization to $server completed at" `date`
    
    done
    Any help is much appreciated.

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,514
    Thanks
    17
    Thanked 808 Times in 511 Posts
    Rep Power
    10

    Default

    Go with another for loop inside main for loop:
    Code:
    #!/bin/bash
    SSHUSER="someuser"
    
    PROGRAM="rsync"
    
    OPTIONS="-razh --size-only"
    
    
    SERVERS=(
        machine1.domain.com 
        machine2.domain.com
        machine3.domain.com
    )
    
    DIRS=(
        /home/folder1/
        /home/folder2/
    )
    
    for server in ${SERVERS[*]} ; do
    
        echo "Synchronizing to $server beginning at" `date`
        for d in ${DIRS[*]} ; do
            $PROGRAM $OPTIONS "$d" $SSHUSER@$server:/home/$SSHUSER/
        done
        echo "Synchronization to $server completed at" `date`
    done
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    I appreciate your help a lot Vivek. I have been browsing the forums for the past four months since I work as a junior system administrator and I must say you have an amazing site and a great community that are more than happy to help out whenever someone has any questions. I'm glad to be a part of it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Multiple files uploading by rsync
    By Lilit in forum Shell scripting
    Replies: 1
    Last Post: 17th June 2010, 06:18 AM
  2. Want to integrate Linux machines with AD
    By kumarat9pm in forum Networking, Firewalls and Security
    Replies: 5
    Last Post: 19th February 2010, 10:32 AM
  3. synchronize squirrelmail addresses with outlook
    By ravis007 in forum Mail Servers
    Replies: 1
    Last Post: 9th November 2009, 11:33 AM
  4. Replies: 2
    Last Post: 8th February 2007, 03:45 PM
  5. Require shell script using rsync
    By puppen in forum Shell scripting
    Replies: 4
    Last Post: 23rd April 2006, 12:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •