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

Angelo Bertolli angelo at freeshell.org
Tue Apr 17 11:29:11 EDT 2007


Mark Smith wrote:
> 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.
>   

If I included an IP address, I wanted to use the IP address for rsync, 
but still HOST for the location.  (This is useful for machines that I 
have running on DHCP.)  Otherwise, with just host name, use the host 
name for rsync.  There's probably a nicer way to do this by setting the 
IP variable from HOST ahead of time or something.

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

I don't like the way rsync fails.  Especially since I have a firewall 
rule that I use that drops packets if someone connects to ssh too 
frequently.  Rsync ends up taking forever to find out it can't connect.

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

Are there any standard numbers I should use?  Like 5 means missing 
arguments or something?

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

Yeah :(  I really need to do more error checking.

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

Yes, that's true.  So far it hasn't been a problem for me, since I can 
go into fstab to recreate partitions.  But do you think it's a problem 
in general, or that I need to exclude /media/* and /mnt/* so it never 
picks up things that are mounted?  Actually that might to be a good 
solution because there may be things under /mnt that I want.

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

Ok, so I should really test to see if you are root when you do this.  
That's another good error to catch.

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

I think this is the default for rsync.

> 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).
>   


Thanks for the comments.  I actually do use this at the command line, 
and not unattended.  Call me crazy, but I'm not too keen on using ssh 
keys with root.

Angelo



More information about the Novalug mailing list