rsync same directory on two servers

Discussion in 'Programming/Scripts' started by fweijers, Sep 17, 2014.

  1. fweijers

    fweijers New Member

    I have two NAS servers which I want to sync using rsync.

    What path settings do I need when I have the same directory-name on both servers, and I want to synchronize both directories?
    It doesn’t seem to work for me.

    I have the directory /NAS/PICS on server 1 and /NASBACKUP/PICS on server 2.

    I use this command:
    rsync -av /mnt/HD_a2/NAS/PICS root@<ip>:/shares/NASBACKUP/PICS

    I end up with /shares/NASBACKUP/PICS/PICS on server 2 every time. I tried with and without trailing / on de server-1-path /mnt/HD_a2/NAS/PICS, but I don’t think it makes a difference.

    When I use this command with a server-1-directory which is not on server-2 (e.g. /mnt/HD_a2/NAS/PICS-TEST), then it works, but no succes when the directory already exists on both ends.
    Any ideas?
     
  2. srijan

    srijan New Member HowtoForge Supporter

    I will suggest you to use different mount points for the two drives

    e.g. One harddrive at /mnt and other at /media
     
  3. fweijers

    fweijers New Member

    Thanks, but I think this is already the case? server1 is /mnt/..
    server2 is /shares/...
     
  4. srijan

    srijan New Member HowtoForge Supporter

    I will prefer use of sshfs for that. Install sshfs in server-1

    Then mount the second server2 drive as follows:

    where xxx.xxx.xxx.xxx will be IP of server2

    Then you have mounted the remote drive locally and finally run the rsync as

     
  5. harryz

    harryz New Member

    Try:
    rsync -av /mnt/HD_a2/NAS/PICS/ root@<ip>:/shares/NASBACKUP/PICS/
    you need a "/" after PICS. you have no Slash at the end of the source-path, the recent path
    will be created on destination .
     
  6. fweijers

    fweijers New Member

    Thanks for all the answers! I am not sure what I did wrong before, but I'm using this script now and everything works fine!

    #!/bin/sh
    #

    RSYNC=/usr/bin/rsync
    SSH=/usr/bin/ssh
    RUSER=root
    RHOST=-ip-
    RPATH=/mnt/HD_a2/NASBACKUP
    LPATH='/shares/NASBACKUP/FOTOS /shares/NASBACKUP/DOCUMENTEN /shares/NASBACKUP/VIDEO /shares/NASBACKUP/COMPLETE_SHOOTS'


    echo BEGIN >> /var/log/rsync.log
    datum=`date "+%Y%m%d_%H%M%S"`
    echo $datum >> /var/log/rsync.log 2>&1

    $RSYNC -av --ignore-existing "$SSH" $LPATH $RUSER@$RHOST:$RPATH >> /var/log/rsync.log 2>&1

    datum=`date "+%Y%m%d_%H%M%S"`
    echo $datum >> /var/log/rsync.log 2>&1
    echo EIND >> /var/log/rsync.log
     
  7. budgierless

    budgierless Member HowtoForge Supporter

Share This Page