rsync parameters errors

Volker Kuhlmann hidden at paradise.net.nz
Thu Jan 24 15:58:11 MST 2013


On Fri 25 Jan 2013 00:08:52 NZDT +1300, Joe wrote:

> In my new bash script, I'm doing what I think is a very simple rsync
> command the way I'm used to doing it.  I just do a lot of setup and
> checking before I get to it.
> 
> When I run it, it gets very unhappy with me.  It's probably something
> very simple.

Your problem is with shell programming, not rsync, but that is
frequently a requirement with rsync because of its stellar argument
lists...

> ##COMMAND="rsync ${DRY_RUN} -avushi ${DELETE} --stats --progress
> --log-file=\"${LOGFILE1}\" \"${MOUNT_POINT[0]}/${DIRECTORY[0]}/\"

ARRGGHHH. 

Do yourself a favour and increase the legibility and coding standard of
your programs no end by using array variables that hold argument lists
only but no commands, and preferably no arguments that need a path name.
Like this

  rsyncargs=(
      -avushi
      -stats
      #--log-file=  # don't do this, you will be paying for it
  )

  LOGFILE="..."

  logargs=(
      ....
  )

Make it a rule to always program in a way that allows spaces in every
argument. Anything going belly-up with a space in a file name is plain
incompetent.

Then run your commands

  rsync "${rsyncargs[@]}" --log-file="$LOGFILE" | tee "${logargs[@]}"

You could set LOGFILE to /dev/null if desirable.

Avoid having to eval huge strings, it's always risky and almost always
bad, and avoid putting variables that need to be expanded later into
argument lists held by other variables. That way you solve all your
problems with when "|" is expanded, having to quote variables containing
paths twice and so on, and your code stays legible and maintainable.

If you need progress logging, I've found this to be easy, safe and
effective (at the cost of a bit of performance - which you're not caring
about as you're using bash):

  Log() {
      if [ -n "$logging" ]; then
          (
	  set -x
	  "$@"
	  )
      else
          "$@"
      fi
  }

  Log yourcommand

Don't bother trying to be compatible with other *sh-type shells on other
*nix systems, trying to get any use out of such retarded constructs only
leads to mental illness.

HTH,

Volker

-- 
Volker Kuhlmann			is list0570 with the domain in header.
http://volker.dnsalias.net/	Please do not CC list postings to me.


More information about the rsync mailing list