Linux Help - Cshell - Rsync

Posted on 2011-10-26
Last Modified: 2012-05-12
I Need help to write a CShell script that coiesy subdirectories in FolderA  to  FolderB using CShell + Rsync on a CentOsServer:

Here is the scenario:

•      I have 2 remote servers ServerA and SeverB.
•      I mounted 2 Directories from the remote servers to my local CentOsServer.  Mount details: ServerA( Folder1), and ServerB (Folder2) .
•      The Cshell script should copy folders from ServerA( Folder1) to ServerB (Folder2).
•      The script should check to see if the folder exsist in ServerB (Folder2). If the folder does not exsist copy the folder including all files

Can someone please help me with the Cshell script to do this?

Question by:wademi
    LVL 19

    Expert Comment

    You actually don't need a script for this, it's very simple.  The -u option to sync tells it to run in update mode, which will not overwrite a folder that already exists, however, it will copy files inside a folder to the matching folder on the other end if the files themselves do not exist.  Let me know if there's a different behavior you would like to achieve.  If not, then simply do (where Folder1 is the top directory where you mounted ServerA, and Folder2 is the top directory where you mounted ServerB):
    rsync -avu Folder1 Folder2

    Open in new window

    LVL 19

    Expert Comment

    Sorry one small error.  Folder1 needs a trailing / which means, everything INSIDE Folder1 gets synced to the inside of Folder2.  So:
    rsync -avu Folder1/ Folder2

    Open in new window


    Author Comment

    Hi xterm:. That worked but how would I view my rsync log
    LVL 19

    Accepted Solution

    You would need to tell it to keep a log file
    rsync -avu --log-file=/path/to/mylog.txt Folder1/ Folder2

    Open in new window


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
    Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now