Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #8525

Re: rsync: exclude all, then include only specified, wildcard problems..

From dave.gma+news002@googlemail.com.invalid (Dave Gibson)
Newsgroups uk.comp.os.linux, comp.os.linux.misc
Subject Re: rsync: exclude all, then include only specified, wildcard problems..
Followup-To comp.os.linux.misc
Date 2013-06-20 18:37 +0100
Organization A noiseless patient Spider
Message-ID <28rb9axqm3.ln2@perseus.wenlock-data.co.uk> (permalink)
References <kpsi1n$37d$1@dont-email.me>

Cross-posted to 2 groups.

Followups directed to: comp.os.linux.misc

Show all headers | View raw


[ Followup-To: set to colm ]

In comp.os.linux.misc, David <david@55952163-3189045.bogus.domain.invalid>
> wrote:
> I've been struggling with rsync (and its helpfully voluminous, but
> somewhat confusing, man page) all day.. :-(

> explicitly allow only the folder hierarchies that are supposed to be 
> synced.

You want to rsync a few directories from a hierarchy while retaining
the directory structure?

> SRCROOT="/data/import/svn-test/svn-checkedout/$REPONAME/data"
> #SRCROOT="/data/import/svn-holding/svn-checkedout/$REPONAME/data"
> 
> DSTROOT="/data/import/svn-test/data-test"
> DSTROOT_LIVE="/data"

[snip]

> RS_INCLUDE="
> --include='/webs/web1/php_includes/'
> --include='/webs/web1/php_snippets/'
> --include='/webs/web2/php/'
> "

[snip: building up a command line in a string]

You have

 "$SRCROOT"/webs/web1/php_includes/
 "$SRCROOT"/webs/web1/php_snippets/
 "$SRCROOT"/webs/web1/irrelevant_things
 "$SRCROOT"/webs/web2/php/
 "$SRCROOT"/webs/web2/something_to_be_ignored
 "$SRCROOT"/webs/other/stuff

You want

 "$DSTROOT"/webs/web1/php_includes/
 "$DSTROOT"/webs/web1/php_snippets/
 "$DSTROOT"/webs/web2/php/

Right?  Use -R (note use of '/./' to strip preceding path elements).

rsync -av -R                            \
  "$SRCROOT/./webs/web1/php_includes/"  \
  "$SRCROOT/./webs/web1/php_snippets/"  \
  "$SRCROOT/./webs/web2/php/"           \
  "$DSTROOT"



Referring back to the attempt to have embedded quotes within a string,
when the shell expands RS_INCLUDE it will treat the embedded single
quotes as ordinary characters.  To have the behaviour you were aiming
for (are there spaces in there?) you'd have to use eval.  Don't use
eval.  Use arrays.

  RS_INCLUDE=(
    --include='/webs/we 1/php includes/'
    --include='/webs/we 1/php snippets/'
    --include='/webs/web2/php/'
  )
  printf '%s\n' "${RS_INCLUDE[@]}"

Contrast the output from that with the following

  RS_INCLUDE="
    --include='/webs/we 1/php includes/'
    --include='/webs/we 1/php snippets/'
    --include='/webs/web2/php/'
  "
  printf '%s\n' $RS_INCLUDE



The script would look something like this

include=(
  "$SRCROOT/./webs/web1/php_includes/"
  "$SRCROOT/./webs/web1/php_snippets/"
  "$SRCROOT/./webs/web2/php/"
 )

opts=(
  -av
  --relative
  $DRYRUN
 )

rsync "${opts[@]}" "${include[@]}" "$DSTROOT"

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

rsync: exclude all, then include only specified, wildcard problems.. David <david@55952163-3189045.bogus.domain.invalid> - 2013-06-19 15:17 +0000
  Re: rsync: exclude all, then include only specified, wildcard problems.. Rikishi42 <skunkworks@rikishi42.net> - 2013-06-20 00:49 +0200
    Re: rsync: exclude all, then include only specified, wildcard problems.. David <david@55952163-3189045.bogus.domain.invalid> - 2013-06-25 11:50 +0000
      Re: rsync: exclude all, then include only specified, wildcard problems.. Rikishi42 <skunkworks@rikishi42.net> - 2013-06-26 01:59 +0200
  Re: rsync: exclude all, then include only specified, wildcard problems.. Richard Kettlewell <rjk@greenend.org.uk> - 2013-06-20 10:16 +0100
    Re: rsync: exclude all, then include only specified, wildcard problems.. The Natural Philosopher <tnp@invalid.invalid> - 2013-06-20 14:19 +0100
      Re: rsync: exclude all, then include only specified, wildcard problems.. David <david@55952163-3189045.bogus.domain.invalid> - 2013-06-25 11:17 +0000
  Re: rsync: exclude all, then include only specified, wildcard problems.. Chris Davies <chris-usenet@roaima.co.uk> - 2013-06-20 10:57 +0100
    Re: rsync: exclude all, then include only specified, wildcard problems.. David <david@55952163-3189045.bogus.domain.invalid> - 2013-06-25 11:40 +0000
      Re: rsync: exclude all, then include only specified, wildcard problems.. Chris Davies <chris-usenet@roaima.co.uk> - 2013-06-25 21:00 +0100
  Re: rsync: exclude all, then include only specified, wildcard problems.. dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2013-06-20 18:37 +0100
    Re: rsync: exclude all, then include only specified, wildcard problems.. David <david@55952163-3189045.bogus.domain.invalid> - 2013-06-25 14:00 +0000
      Re: rsync: exclude all, then include only specified, wildcard problems.. Richard Kettlewell <rjk@greenend.org.uk> - 2013-06-25 15:24 +0100
      Re: rsync: exclude all, then include only specified, wildcard problems.. dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2013-06-25 19:23 +0100
  Re: rsync: exclude all, then include only specified, wildcard problems.. Chick Tower <c.tower@deadspam.com> - 2013-06-20 18:04 +0000
  Re: rsync: exclude all, then include only specified, wildcard problems.. dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2013-06-25 23:37 +0100
    Re: rsync: exclude all, then include only specified, wildcard problems.. dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2013-06-26 01:54 +0100
    Re: rsync: exclude all, then include only specified, wildcard problems.. David <david@55952163-3189045.bogus.domain.invalid> - 2013-06-28 16:12 +0000
      Re: rsync: exclude all, then include only specified, wildcard problems.. dave.gma+news002@googlemail.com.invalid (Dave Gibson) - 2013-06-29 01:30 +0100
      Re: rsync: exclude all, then include only specified, wildcard problems.. Chris Davies <chris-usenet@roaima.co.uk> - 2013-07-01 09:51 +0100

csiph-web