[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using different options to run rsync

From: lisa-asket
Subject: Using different options to run rsync
Date: Mon, 19 Jul 2021 17:01:56 +0200 (CEST)

I have added the following option to call rsync with the --backup option.

      local -r filetr_backup=1
      shift 1

I took the option of using an array to set up `--dry-run`.  I could add the 

  (( filetr_dryrun == 1 )) && oser=(--dry-run)

  if (( filetr_dryrun == 1 )); then 
    rsync "${oser[@]}" -av --progress --log-file="$logfl" "$source" "$destin"
  elif (( filetr_exec == 1 )); then
    rsync "${oser[@]}" -av --progress --log-file="$logfl" "$source" "$destin"
    rsync "${oser[@]}" -av --progress --log-file="$logfl" "$source" "$destin"

From: Greg Wooledge <>
Subject: Re: Using different options to run rsync
Date: 19/07/2021 14:55:13 Europe/Paris

On Mon, Jul 19, 2021 at 02:43:26PM +0200, wrote:
> I am duplicating code here, all those -av, --progress, $source, $destin are 
> the same in both branches.
> Perhaps it is best to avoid that.  Since I am running `bash`, I could collect 
> the arguments to an array.

That's certainly one possible choice.

>   if (( filetr_dryrun == 1 )); then 
>     echo "rsync -av --progress --dry-run --log-file=$logfl"
>     echo "  $source $destin"
>     rsync -av --progress --dry-run --log-file="$logfl" "$source" "$destin"
>   elif (( filetr_exec == 1 )); then
>     # use rsync archive option -a (equivalent to -rlptgoD)
>     echo "rsync -av --progress --log-file=$logfl $source $destin"
>     rsync -av --progress --log-file="$logfl" "$source" "$destin"
>   else
>     echo "rsync -av --progress --log-file=$logfl $source $destin"

Let's look at what's *different* in the two invocations. The only
difference between them is that one has --dry-run and the other does

So, another approach would be to put the --dry-run option (or the absence
of it) into an array, instead of putting all of the common options into
an array.

((filetr_dryrun)) && dryrun=(--dry-run)

if ((filetr_dryrun || filetr_exec)); then
rsync "${dryrun[@]}" -av --progress --log-file="$logfl" "$source" "$destin"

I suspect you've misspelled "filter" a few times, but no big deal. More
confusing is how you're using the _exec option. I'm unclear on exactly
why you want the default case to be "echo the command as if I were going
to run it, but don't actually run it, not even with --dry-run", so I
suspect I'm missing some pieces of the goal.

It's something for you to think about.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]