Results 1 to 5 of 5
The first rsync script works, the second returns an error. The only difference is that the 2nd uses a variable for the rsync options. I'd like to expand this script ...
- 07-19-2009 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 8
2 nearly identical bash rsync scripts. One works, one doesn't...
The first rsync script works, the second returns an error. The only difference is that the 2nd uses a variable for the rsync options. I'd like to expand this script with parameters and custom options but this little problem is in my way. Anybody see what's wrong or how it can be fixed?
Code:#!/bin/bash # # This script will backup the selected files I have in $RSYNC_FILES. It will # recurse into directories. It will check for the $RSYNC_FILTER file in each # directory for further rules on what files to include/exclude/etc. # SOURCE="$HOME/" DEST="$HOME/test/" RSYNC_FILES="$HOME/.rsync-files" RSYNC_FILTER=".rsync-filter" # We must use the delete-after flag in order for the excluded files to be # deleted from the destination. Only files from the $RSYNC_FILES file will be # loaded. # this rsync works as intended rsync -aur --stats --progress \ --files-from=$RSYNC_FILES \ --filter=": /$RSYNC_FILTER" \ --delete-excluded --delete-after \ $SOURCE $DEST OPTS="-aur --stats --progress \ --files-from=$RSYNC_FILES \ --filter=\": /$RSYNC_FILTER\" \ --delete-excluded --delete-after" # this rsync does not work echo "$OPTS $SOURCE $DEST" # this works rsync $OPTS $SOURCE $DEST # output: # # -aur --stats --progress --files-from=/home/josh/.rsync-files --filter=": /.rsync-filter" --delete-excluded --delete-after /home/josh/ /home/josh/test/ # Unknown filter rule: `":' # rsync error: syntax or usage error (code 1) at exclude.c(817) [client=3.0.5]
- 07-19-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Try this:
Code:eval rsync $OPTS $SOURCE $DEST
- 07-19-2009 #3Just Joined!
- Join Date
- Dec 2008
- Posts
- 8
Well, that fixed it. Thank you!
However, just because I like to know why and how things work, why is eval required? What does it do that simple bash substitution does differently?
- 07-19-2009 #4Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
From the bash manpage ;
So without using 'eval' rsync sees '$OPTS $SOURCE $DEST' as parameters. Whereas when you use 'eval' the variables are expanded and then the whole command is passed to the shell to be executed. The options specified in $OPT are now seen by rsync as options.eval [arg ...]
The args are read and concatenated together into a single command. This command is then read and
executed by the shell, and its exit status is returned as the value of eval. If there are no args,
or only null arguments, eval returns 0.
Hopes that makes some sense.
- 07-20-2009 #5Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
I changed you script to echo the "rsync" command and got
rsync -aur --stats --progress --files-from=/home/balbir/.rsync-files --filter=: /.rsync-filter --delete-excluded --delete-after /home/balbir/ /home/balbir/test/
rsync -aur --stats --progress --files-from=/home/balbir/.rsync-files --filter=": /.rsync-filter" --delete-excluded --delete-after /home/balbir/ /home/balbir/test/
the issue I think is the \" in the second invoctaion?, take them out and it should work without doing the eval.
the reason being is --filter=\": /$RSYNC_FILTER\" either you quote the whole item (eg \"--filter=: /$RSYNC_FILTER\") or none of it (eg . --filter=: /$RSYNC_FILTER)In a world without walls and fences, who needs Windows and Gates?


Reply With Quote