[clug] rsync - how to create path on remote server

Tony Breeds tony at bakeyournoodle.com
Fri Jun 15 00:17:48 GMT 2007

On Fri, Jun 15, 2007 at 09:50:47AM +1000, Stephen Hodgman wrote:
> I have a problem that I cannot see a way to solve with rsync.
> We have a remote rsync server that we do not have shell access to, only 
> rsync.
> I need to create a backup of a directory tree on that server but I do 
> not know if the the complete remote path exists.
> e.g. My path is /A/B/C/D/ and I need to put this under the remote server 
> tree /A etc
> However, if for example the "C" directory does not pre-exist on the 
> remote server my command
> rsync -zav /A/B/C/D remotehost::Share/A/B/C
> will not work.  If the "C" folder does exist it will.  How do I get 
> rsync to "auto create"  the "C" folder?

I Assume the is some other directory in C that you don't wnat to
transfer and hence your avoiding:
	rsync -zav /A/B/C remotehost::Share/A/B/C
> Or, alternatively, what am I missing here? :-)
> Thanks for your time

I can't think of a better way to do this but you could do:
cd /
find A -type d -print0 | ( cd /tmp ; xargs -r0n1 mkdir -p )
cd /tmp
rsync -zav A remotehost::Share/.
rm -rf A # or leave it around for later.

This will duplicate the directory structure of /A to /tmp/A
and then clone the empty directories to the remote host.

After that you can just do your rsync, If I understand the problem

Yours Tony

  linux.conf.au        http://linux.conf.au/ || http://lca2008.linux.org.au/
  Jan 28 - Feb 02 2008 The Australian Linux Technical Conference!

More information about the linux mailing list