[ale] rsync + ssh + cron

Nathan J. Underwood ale1 at cybertechcafe.net
Tue May 23 15:21:53 EDT 2006


further testing:

I ran the script which echos the $COMMAND variable to the screen rather 
than actually executing it.  I then copied and pasted that $COMMAND into 
another script called 'rsynctest.sh' and that worked.  So, the script 
(snapshot.sh, posted with my original message) does work, it just 
doesn't work when ran from the [snapshot.sh] script.

The idea here is that the script can be put in a cron job to backup 
server(s) remotely.  That's why it *needs* to run from a script and not 
just from the command line (in a terminal window or shell).

Nathan J. Underwood wrote:
> The error that I'm getting (figured that may be handy) when I try to 
> run it is:
>
> /usr/bin/rsync -av -e 'ssh -p 2201' /home/nathan/source/ 
> nathan at lint-1:/home/nathan/destination --progress --stats --compress 
> --delete
> Missing trailing-' in remote-shell command.
> rsync error: syntax or usage error (code 1) at main.c(335) [sender=2.6.8]
> [nathan at linux-fs2 scripts]$
>
>
> If I just copy and paste the command line and execute it it works.
>
> Nathan J. Underwood wrote:
>> I'm trying to come up with a script to do remote backups with rsync + 
>> ssh + cron.  I got the idea initially from a couple of articles and 
>> based mine on this one -> 
>> http://www.mikerubel.org/computers/rsync_snapshots/ (sortof).  At any 
>> rate, I'm having trouble getting the script to connect to a remote 
>> computer via rsync using SSH.  To test, I can echo the command line 
>> being sent by the script and copy + paste it and run it with no 
>> errors, but I just can't run it from the script. 
>>
>> Environment :
>> rsync v2.6.8
>> openssl v0.9.7a-40
>>
>>
>> I have a user setup to log in using rsa keys with no passphrase and 
>> have tested to make sure this works (i.e. log into the destination 
>> box from the source box via ssh using this username and I am not 
>> prompted for a password / passphrase).
>>
>> I've been googling for a couple of hours trying to avoid the 'rtfm' 
>> response and have found a couple that indicate that my script 
>> *should* work but I'm still missing something.
>>
>> Below is the script:
>>
>> #!/bin/bash
>> # version 0.01a
>> #
>> # snapshot2.sh - This will use rsync to backup the files in SOURCE
>> #
>> # Dependancies:
>> # rsync - last tested with v2.6.8
>> # openssl - last tested with v0.9.7a-40
>> # ssh login with RSA keys with no pw
>> #
>> # CREDITS
>> # This script uses some of the concepts and ideas from Mike Rubel's 
>> script at http://www.mikerubel.org/computers/rsync_snapshots/
>>
>> configFile=                     # if you wish to put all of these 
>> configs in a separate file,
>>                                 # enter the full filesystem path to 
>> it here (all other configs
>>                                 # will be ignored)
>> srcLoc="/home/nathan/source/"    # full filesystem path to the files 
>> being backed up
>> srcHost=""                      # hostname or IP address of host with 
>> source.  leave blank for local
>> srcUserName="nathan"            # username on source system (not req 
>> if local)
>> dstLoc="/home/nathan/destination"            # full filesystem path 
>> to the backup destination
>> dstHost="lint-1"             # hostname or IP address of host to 
>> backup to.  leave blank for local
>> dstUserName="nathan"            # username on dest system (not req if 
>> local)
>> method="/usr/bin/ssh -p 2201"            # this will be used for the 
>> -e argument to rsync
>> preFlags="-av"                  # any flags / arguments to be added 
>> to the beginning of the backup script
>> postFlags="--progress --stats --compress --delete"  # any flags / 
>> arguments to be added to the end of the backup script
>> numOfHist="4"                   # how many old copies to keep
>>
>>
>>
>> #------------------------------------------
>> # no tinkering beyond this point
>> #------------------------------------------
>>
>> PATH="$PATH:/usr/bin"
>> # Get Commands
>> RSYNC=$(which rsync)            # rsync
>> CP=$(which cp)                  # cp (copy)
>> MV=$(which mv)                  # mv (move)
>> ID=$(which id)                  # id
>> ECHO=$(which echo)              # echo
>> SSH=$(which ssh)                # ssh
>>
>> # Check to make sure that this is being ran by root
>> #if (( `$ID -u` != 0 )); then
>> #    { $ECHO "Sorry, must be root.  Exiting..."; exit; }
>> #fi
>>
>>
>> #------------------------------------------
>> # Build rsync command to be ran
>> #------------------------------------------
>> #rsync -av -e 'ssh -p 2201' ../source/ nathan at linux-fs2:destination 
>> --progress --stats --compress --delete --link-dest=destination.1
>>
>> # Get flags to be added before the source
>> if [ -n "$preFlags" ]; then
>>     PREFLAGS=" $preFlags";
>> fi
>>
>> # Get the method
>> if [ -n "$method" ]; then
>>     METHOD=" -e '$method'"
>> fi
>>
>> # Setup the source.  Check for a source host (i.e. the source is 
>> another computer) and, if one is there, verify
>> # that a source username has been added.
>> if [ -n "$srcHost" ]; then
>>         if [ -z "$srcUserName" ]; then
>>             $ECHO "Sorry, source host specified but no source 
>> username.  Exiting..."; exit;
>>         else
>>             SRC="$srcUserName@$srcHost:$srcLoc"
>>         fi
>>     else
>>         SRC="$srcLoc"
>> fi
>>
>> # Setup the destination.  Check for a destination host (i.e. the 
>> destination is another computer) and, if one is there, verify
>> # that a destination username has been added.
>> if [ -n "$dstHost" ]; then
>>         if [ -z "$dstUserName" ]; then
>>             $ECHO "Sorry, destination host specified but no 
>> destination username.  Exiting..."; exit;
>>         else
>>             DST="$dstUserName@$dstHost:$dstLoc"
>>         fi
>>     else
>>         DST="$dstLoc"
>> fi
>>
>> #if [ "$postFlags" ]; then
>> #    POSTFLAGS= " $POSTFLAGS";
>> #fi
>>
>> COMMAND="$RSYNC $PREFLAGS $METHOD $SRC $DST $POSTFLAGS"
>>
>>
>> echo $COMMAND
>> $COMMAND
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://www.ale.org/mailman/listinfo/ale
> ------------------------------------------------------------------------
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
-------------- next part --------------
An HTML attachment was scrubbed...




More information about the Ale mailing list