Linux Help - Cshell - Rsync

Posted on 2011-10-26
Medium Priority
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
  • 3
LVL 19

Expert Comment

ID: 37035921
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

ID: 37035929
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

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

Accepted Solution

xterm earned 2000 total points
ID: 37039196
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 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