Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] rsync v. cp in data migration



Greg,

> TIMING="$(time ( rsync -avSHPz root@$SOURCE:/home/$USER/ /nas_home/$USER/ )
> 2>&1 1>/dev/null )"
> echo $TIMING | tee -a $LOGFILE

A couple minor points here...  

The way you've written this, all your error messages will be munged
together into one (potentially very) line, which will make them rather
hard to read, e.g.: 

$ TIME="$(time (cat foo; cat foo; cat foo) 2>&1 >/dev/null)"
$ echo $TIME
cat: foo: No such file or directory cat: foo: No such file or directory cat: foo: No such file or directory real 0m0.007s user 0m0.000s sys 0m0.004s

You probably don't care, but I just wanted to point out that this runs
rsync in a subshell, and as a result the time command is giving you
the statistics of the subshell rather than the rsync command.  You'll
still get the clock time, obviously, but if you're interested in
user/sys statistics they'll be wrong.

You don't actually need the subshell...  There are a couple of ways to
write this without it.  rsync offers a -q option which eliminates all
output other than error messages; for starters I'd use that, and
eliminate the redirection of the rsync output to /dev/null.  Then I'd
probably write something like this:

#!/bin/sh
while read USER; do
    echo "Working on $USER"
    time rsync -qavSHPz root@$SOURCE:/home/$USER/ /nas_home/$USER/ 
    echo "/home/$USER copied to new NAS"
    echo
done < users | tee $LOGFILE

Lastly I would recommend that you always invoke your shell scripts as
/bin/sh rather than /bin/bash unless you absolutely need features that
you only get with the latter (or you expressly want to use bash but
/bin/sh isn't bash on your system).  Invoking as /bin/bash changes the
way bash reads start-up files, such that it may include things in your
environment that may surprise you, possibly altering the way your
script runs.  If you don't have much in your .bashrc/.[bash_]profile
etc. files, this probably won't matter to you, but if you do, it
might, especially if you use $ENV or $BASH_ENV.  See the INVOCATION
section of the bash man page for details.

-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org