The Samba-Bugzilla – Bug 2375
Support (a la Gnu tar) for --directory DIR
Last modified: 2005-04-01 11:22:44 UTC
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/
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).
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
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
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.
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:
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
I may be missing something, but are you sure that:
echo "usr/local/blackboard" rsync -aRz --files-from=- /
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.
> I may be missing something, but are you sure that:
> echo "usr/local/blackboard" | rsync -aRz --files-from=- /
> 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.
(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.
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.