I am using rsync with --files-from option with a file named 'rsync.in' that contains 37K+ directories that are queried from a database. One of the directories looked like this:
I know the directory should NOT end with a './' but this was stored in the database that way by another process. When performing the rsync, this one directory caused all files from the root '/' directory on down to be deleted. However,
if ran without the --files-from option it works as expected. It is because of the ‘./’ on the end and using the ‘files-from’ option but I don’t know why rsync would do that.
Obviously not allowing these directories to be stored in the database in the first place is the thing to do, but I just want to understand why rsync would do this so I can ensure I prevent things like this in the future. Here's the command
(with the dry-run option for safety).
I am using rsync with --files-from option with a file named 'rsync.in' that contains 37K+ directories that are queried from a database. One of the directories in the database actually looked like this:
Probably some sort of typo when the directory was entered. When performing the rsync command below, this one directory caused all files on the destination server to be deleted from the root '/' directory on down. Obviously I have put in
safeguards now to filter invalidly formatted directories, but I want to understand why rsync would do this in case there are other things I should be looking for. BTW, it only seems to happen if using the –files-from option. If ran manually from the command
line it does not delete all files. I have searched the web and can find no one else who has experienced this.
Note: If you test this, please use the –dry-run option
On Mon, Jun 6, 2016 at 8:52 AM, Koehn, Troy N. <[hidden email]> wrote:
One of the directories in the database actually looked like this:
In the manpage under the "--relative" option (which is implied by --files-from) there is this information:
It is also possible to limit the amount of path information that is sent as implied directories for each path you specify. With a modern rsync on the sending side (beginning with 2.6.7), you can insert a dot and a slash into the source path, like this:
rsync -avR /foo/./bar/baz.c remote:/tmp/
That would create /tmp/bar/baz.c on the remote machine. (Note that the dot must be followed by a slash, so "/foo/." would not be abbreviated.)
Thus, your path tells rsync to take the contents of the /home/usr/directory path and send its contents without any implied directories, which puts its content at the root of the transfer.