Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force rsync to create destination folder

Tags:

rsync

Example:

rsync /tmp/fol1/fol2/fol3/foln user@addr:/tmp/fol1/fol2/fol3/foln 

My main problem is folder /tmp/fol1 doesn't exist on remote machine.

Which arguments can I use to force rsync to create this tree?

like image 496
CrazySquirrel Avatar asked Feb 11 '12 17:02

CrazySquirrel


People also ask

Does rsync create destination directory?

Rsync creates a directory with the same name inside of destination directory - Server Fault. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

How do I change the directory in rsync?

Method 1: Updating newer files locally with rsyncThe “-u” or the “–update” option forces rsync to skip that files in your destination directory that are still new, and the “-n” or the “–dry run” option is for testing the update process. Now, remove the “-n” option and quickly update the rsync command execution.

How do I rsync a folder to another directory?

If you want to copy a directory with its sub-directory and all contents from one location to another within your system, you can do so as by typing rsync followed by the source and destination directory. Note: Specifying “/” after the source directory only copies the contents of the directory.

Why is rsync skipping directory?

Similarly, the rsync skipping directory error can occur when miss to put it into a recursive mode like -r or -a. In addition, use -a instead of -r. -a means to reproduce file hierarchies, including special files and permissions. Also, the option -r only to recurse on directories whereas -a needed for a data backup.


2 Answers

I ran into same issue today and found the solution here.

You can either do:

rsync -avR foo/bar/baz.c remote:/tmp/ 

or:

rsync -avR somedir/./foo/bar/baz.c remote:/tmp/ 

to create /tmp/foo/bar/baz.c in the remote machine.

see --relative/-R section of man rsync for more details.

like image 155
Anand Chitipothu Avatar answered Sep 29 '22 18:09

Anand Chitipothu


One trick to do it is to use the --rsync-path parameter with the following value:

--rsync-path="mkdir -p /tmp/fol1 && rsync" 

With --rsync-path you can specify what program is going to be used to start rsync in the remote machine and is run with the help of a shell.

like image 33
barracel Avatar answered Sep 29 '22 16:09

barracel