Bug 2375 - Support (a la Gnu tar) for --directory DIR
Support (a la Gnu tar) for --directory DIR
Status: CLOSED WONTFIX
Product: rsync
Classification: Unclassified
Component: core
2.6.3
All Linux
: P3 enhancement
: ---
Assigned To: Wayne Davison
Rsync QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-02-22 05:48 UTC by Eric Maryniak
Modified: 2005-04-01 11:22 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Maryniak 2005-02-22 05:48:23 UTC
Dear reader,
I have request: could you add an option:

    -C, --directory DIR         change to directory DIR

to rsync? Especially when (like we do) backing up with rsync -R (--relative)
it's nice to have the command in 1 line, like:

rsync -C / -aRz ... usr/local/blackboard rsync://localhost:1873/backup/client/rsync/

instead of:

cd /
rsync -aRz ... usr/local/blackboard rsync://localhost:1873/backup/client/rsync/

Furthermore, it's nice to orthogonality and consistency in (Gnu) tars and rsyncs
options (increases usability).
Comment 1 Wayne Davison 2005-02-22 10:53:56 UTC
With rsync, you don't need to drop the leading slash like you do with tar, so
that command doesn't require a separate "cd /", just leave the slash on the
source.  However, there are other directories than "/", and a --directory option
would allow the sending side to bump the starting dir in a generic way, so I
will accept this as a future-enhancement request (note that -C is already used
by rsync).

One other note: rsync currently allows the setting of the starting dir outside
the relative transfer if you use the --files-from command, if we assume that
your example command had put the "usr" into the "cd /usr" instead of in the
source path (just to make this a non-root example), this command would do what
you want:

echo local/blackboard | rsync -az --files-from=- /usr rsync://host/dest/

Yeah, that's pretty convoluted, but it works.  It's mainly useful for pulling
files from a remote rsync where it is harder (or impossible) to set the base dir
of the transfer using cd.
Comment 2 Eric Maryniak 2005-02-22 11:46:27 UTC
I see, but I'm still not sure (may be me).
With our current rsync setup, we have in /path/to/destdir (which is what
rsync://localhost:1873/backup/client/rsync/ points to) a nice and very handy
verbatim copy of the directory structure, like:

/path/to/destdir/usr/local/blackboard
/path/to/destdir/etc
/path/to/destdir/var/spool

including, most notably, the same permissions/ownerships of the top level dirs
(like /usr and /var) themselves (as compared to the source host). I like this,
because it means I can just simple mv such a dir to a thrashed server and worry
about perms/ownerships.
I may be missing something, but are you sure that:

echo "usr/local/blackboard" rsync -aRz --files-from=- /
rsync://localhost:1873/backup/client/rsync/

would accomplish the same? I tried it, but it does not transfer any (of the
changed) files... Please excuse me if I'm missing some subtle point.
Comment 3 Wayne Davison 2005-02-22 11:57:14 UTC
> I may be missing something, but are you sure that:
> 
> echo "usr/local/blackboard" | rsync -aRz --files-from=- /
> rsync://localhost:1873/backup/client/rsync/
> 
> would accomplish the same? I tried it, but it does not transfer any (of the
> changed) files...

Sorry, I forgot to include the -r option (because -r is not implied by -a when
--files-from is used).  Note also tat the -R option you added is already assumed
by --files-from.  So replace the "R" with a "r" and it will work.

However, as I said in my first reply, you don't need to do any of that for a
transfer that is rooted at "/".  Just do this:

rsync -aRz /usr/local/blackboard rsync://localhost:1873/backup/client/rsync/

Rsync knows how to properly handle a leading slash on the source path.
Comment 4 Eric Maryniak 2005-02-22 14:10:56 UTC
(In reply to comment #3)
> ...
> However, as I said in my first reply, you don't need to do any of that for a
> transfer that is rooted at "/".  Just do this:
> 
> rsync -aRz /usr/local/blackboard rsync://localhost:1873/backup/client/rsync/
> 
> Rsync knows how to properly handle a leading slash on the source path.

Works like a gem, great! Tnx very much --- I guess I was somewhat 'put on the
wrong foot' (as we say in Holland) by the examples for -R/--relative in the man
page that all use relative paths.
As far as I'm concerned this bug may be closed, but of course that's up to you.
Comment 5 Wayne Davison 2005-02-22 14:51:37 UTC
I looked into adding a --directory (-like) option for rsync, and created a patch
named "source-cd.diff" in the "patches" dir with the result.  I don't like this
implementation, though, because it doesn't (and can't) work properly with
wildcards, so I am not going to add this option.

In the future I may add an option named --omit-path that will cause a path
prefix to be removed from the --relative dirs, but that isn't quite the same
thing as this option so I'll close this.