[Novalug] Re: [Ma-linux] backup/mirror script

Mark Smith mark at winksmith.com
Tue Apr 17 09:46:13 EDT 2007


okay.

On Mon, Apr 16, 2007 at 08:59:10PM -0400, Angelo Bertolli wrote:
> if [ "$ip" != "" ]
> then
>   if nc -v -z -w $timeout $ip $port
>   then
>      mkdir -p $dest/$host
>      rsync $ropts --exclude-from $exfile $ip:/ $dest/$host/
>   else
>      echo "Usage: $usage"
>      exit -1
>   fi
> elif [ "$host" != "" ]
> then
>   if nc -v -z -w $timeout $host $port
>   then
>      mkdir -p $dest/$host
>      rsync $ropts --exclude-from $exfile $host:/ $dest/$host/
>   else
>      echo "Usage: $usage"
>      exit -1
>   fi

you've repeated the same logic twice, once using ip and once
using host.  try and avoid that whenver possible and it's
definitely possible here.

why are you testing the connection with nc when rsync will
do that as a matter of course anyway?  it complicate things
unnecessarily and doesn't help.

don't exit -1 as that's "weird".  the desired range is 0-255.
if you want 255, use 255, but i would suggest 'exit 1' for
"normal failure" or 2 if you want differentiate that between
a usage statement, or pick your exit code.

the rsync exit code is lost.  this will have the affect that
your program may generate errors and then exit successfully
(e.g. exit 0) which is probably not want you want.

when rsync runs, you're losing filesystem information where
you traverse mount points.  that is to say, if the original
host has multiple filesystem points, the target will not.

the script should be run as root to get an accurate representation
of the original disk.  certain modes will not be copied, ownership
will get lost, and you won't be able to open certain files as a
regular user.

make sure it's running as ssh (if applicable) to protect privacy
enroute.

if this is a script that will run in an unattended mode you'll
need to open ssh for root w/o a password from the remote side.
you'll need to take necessary precautions and accept certain
risk with that.

your script can probably be better written by shortening a lot
and checking codes (or passing to user).

-- 
Mark Smith
mark at winksmith.com
mark at tux dot org
nova-instructor at tux dot org



More information about the Novalug mailing list