directory Syncing

Jason jkenner@mindspring.com
Thu, 21 Sep 2000 22:32:17 -0700


Bill Warner wrote:
> 
> > Bill Warner wrote:
> > >
> > > Sorry if this is like the 5th time this gets posted
> > > but I am not seeing my mail go through to the list even
> > > after 3-4 hours.  It might be my end but I have been
> > > able to send a few test messages to other lists and my
> > > self.
> > >
> > > Anyway,
> > >
> > > what is the best way to get rsync capabilities between
> > > two local directories.  such as /foo and /bar need to be
> > > synced.  I have looked at rsync and rdist but both seem
> > > to be for syncing across two or more hosts and not for
> > > just two directories.  Searching on freshmeat turned up
> > > pretty much nothing, but I am not sure exactly what I should
> > > be looking for. be looking for.> >
> >
> > #!/bin/bash
> > #
> > CURRENTDIR=`pwd`
> > cd $2
> > TARGETDIR=`pwd`
> > cd $CURRENTDIR
> > cd $1
> > shift
> > shift
> > # allow passing of arguements to the extracting tar, such as keep
> > existing files, etc
> > tar -cvf - * | tar $@ -xvC $TARGETDIR -f -
> 
> This seems to be close to what I need. A few questions.
> this doesn't seem to account for if i have /foo/test and
> /bar/test and sync them it still copies test over.  I
> only want it to copy if they have changed or if it doesn't
> exist.  Also would be ince if I was trying to sync /foo to
> /bar if it would delete all files if /bar that were not
> in /foo.
> 
> I will try building on what you sent me though, one question
> what is the shift for I am not familiar with that.

Shift removes arguements from the commandline after the command
itself. 
In this case, the target dir and source dir are the first two
arguements to the command. ($1 and $2). Since it wants to pass
everything from $3 onward to the extracting tar, using shift twice
brings $3 to the $1 position (and $4 to $2, etc).

How about:

#!/bin/bash
#
CURRENTDIR=`pwd` ; cd $2 ; TARGETDIR=`pwd`
cd $CURRENTDIR ; cd $1
shift ; shift
# make this one line after saving...
tar -cf - `diff . $TARGETDIR | grep -v ">" | grep -v "<" |
 grep "diff" | cut -d " " -f 2` `diff . $TARGETDIR |
 grep "Only" | cut -d ":" -f 2` |
 tar $@ -xvC $TARGETDIR -f -
#





-- 
jkenner@mindspring.com    __
I Support Linux:           _> _  _ |_  _  _     _|
Working Together To       <__(_||_)| )| `(_|(_)(_|
To Build A Better Future.       |                   <s>