directory Syncing

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: sinck@ugive.com
Date:  
Subject: directory Syncing

\_ > #!/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.

Why bother, you get that by default without bother to throw the extra
flags...? Unless you need the files not to go to 0 bytes for even a
little bit. (man tar)

\_ 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.

Hmmm. Can you completely purge /bar prior to the tar? :-)


\_ I will try building on what you sent me though, one question
\_ what is the shift for I am not familiar with that.

shift slurps args from commandline and pulls them out of the list (man
bash)

ex: myscript a b c

# @ARGV = (a b c)
shift
# @ARGV = (b c)
shift
shift
# @ARGV = ()

YMMV on the first argument on whether it's 'myscript' or not, I can
never remember and test until I get it right...and then promptly
forget it. Every time.

David