rsync --log-file-format errors from bash script

I’m writing a bash script to use rsync to backup a local directory to an
external HDD.

At the moment the script generates the following command


/usr/bin/rsync --archive --update --delete --log-file=/var/log/rsync-
client.log --log-file-format='[110306105704.share] %i %n %L' --dry-run
/share/. /media/backup/share/.

If I execute it within the bash script I get the following errors

rsync: link_stat “/root/%i” failed: No such file or directory (2)
rsync: link_stat “/root/%n” failed: No such file or directory (2)
rsync: link_stat “/root/%L’” failed: No such file or directory (2)
IO error encountered – skipping file deletion
rsync error: some files/attrs were not transferred (see previous errors)
(code 23) at main.c(1042) [sender=3.0.7]

If I run it from the command line it runs without errors.

Just cutting out the code building up the command line …
Code

BIN=which rsync
rsync_DfltArgs="$rsync_DfltArgs --log-file-format=’$rsync_RunID] %i %n
%L’"
CMD="$BIN $rsync_DfltArgs"
-n $rsync_NoMotd ]] && CMD="$CMD --no-motd"
-n $rsync_DryRun ]] && CMD="$CMD --dry-run"
-n ${rsync_FilterFile} && -f ${rsync_FilterFile} ]] && CMD="$CMD –
filter=’. ${rsync_FilterFile}’"

CMD="$CMD $rsync_SrcDir/. $rsync_TgtDir/."
$CMD

I must be doing something dumb here but what it is is eluding me. The really
annoying bit is most of this code has been cribbed from another bash script
which I use to keep local repositories up to date and that script runs every
night without problems - the only difference being that I’m running on a
local machine - do I need an rsync daemon running?


Alan

Where’s the closing single quote expected between the %L and "?

Fudokai wrote:

> I’m writing a bash script to use rsync to backup a local directory to an
> external HDD.
>
> At the moment the script generates the following command
>
>


> /usr/bin/rsync --archive --update --delete --log-file=/var/log/rsync-
> client.log --log-file-format='[110306105704.share] %i %n %L' --dry-run
> /share/. /media/backup/share/.
> 

If I execute it within the bash script I get the following errors

rsync: link_stat “/root/%i” failed: No such file or directory (2)
rsync: link_stat “/root/%n” failed: No such file or directory (2)
rsync: link_stat “/root/%L’” failed: No such file or directory (2)
IO error encountered – skipping file deletion
rsync error: some files/attrs were not transferred (see previous errors)
(code 23) at main.c(1042) [sender=3.0.7]

If I run it from the command line it runs without errors.

Just cutting out the code building up the command line …
Code

BIN=`which rsync`

> rsync_DfltArgs="$rsync_DfltArgs --log-file-format=’$rsync_RunID] %i
> %n
> %L’"
> CMD="$BIN $rsync_DfltArgs"
> -n $rsync_NoMotd ]] && CMD="$CMD --no-motd"
> -n $rsync_DryRun ]] && CMD="$CMD --dry-run"
> -n ${rsync_FilterFile} && -f ${rsync_FilterFile} ]] && CMD="$CMD –
> filter=’. ${rsync_FilterFile}’"
> #
> CMD="$CMD $rsync_SrcDir/. $rsync_TgtDir/."
> $CMD
> --------
>
> I must be doing something dumb here but what it is is eluding me. The
> really annoying bit is most of this code has been cribbed from another
> bash script which I use to keep local repositories up to date and that
> script runs every night without problems - the only difference being that
> I’m running on a local machine - do I need an rsync daemon running?
>

The usual thing happens :-/

I spend a couple of hours banging my head against something and get totally
stuck. Finally I admit defeat and beg for help - 2 minutes later I spot the
error myself :frowning:

I should be running
eval $CMD

Sorted :slight_smile:


Alan

ken yap wrote:

>
> fudokai;2299028 Wrote:
>> rsync_DfltArgs="$rsync_DfltArgs --log-file-format=’$rsync_RunID] %i %n
>> %L’"
>
> Where’s the closing single quote expected between the %L and "?
>
>

It’s there - you just need a magnifying glass (or change of font/font size)
to see it :slight_smile:


Alan

I see what your problem is: You are expanding a variable without requoting. The first time $rsync_DfltArgs has the single quotes in it. But next time it’s expanded, the single quotes are lost. Put some echo commands at various points and you will see that at some point $CMD no longer has single quotes around the format.

The original scripting is faulty.

ken yap wrote:

>
> I see what your problem is: You are expanding a variable without
> requoting. The first time $rsync_DfltArgs has the single quotes in it.
> But next time it’s expanded, the single quotes are lost. Put some echo
> commands at various points and you will see that at some point $CMD no
> longer has single quotes around the format.
>
> The original scripting is faulty.
>
>

I did try debugging by putting in echo in various places including echo $CMD
on the line directly before invoking $CMD - this is the output I then pasted
in the console which ran Ok while just invoking the same $CMD in the script
produced the errors.

As I’ve posted elsewhere on this thread it’s now sorted by using eval $CMD -
apparently it’s down to variable expansion according to what I’ve googled.


Alan