I'm finding multiple answers to the question, so wanted to ask people that actually use it, rather than just want to make the biggest blog by filling out with random semi useless information.
Scenario: I
rsync -av --progress /dir/a /dir/b
and it does its thing.
I add new files to /dir/a and run the same command again, it knows what it did and only copies the new files.
I add new files to /dir/a and rename some files in /dir/b, and maybe delete a few too.
If I run rsync -av --progress /dir/a /dir/b
again, what will be copied? Just the new files because it knows what it has previously copied, or the files that were renamed/deleted ones too, because they are no longer present.
And as a bonus, if the previously copied files are copied again, is there a way to prevent that, so that only new additions to /dir/a are copied?
At the moment I'm happy checking things manually, but as the data gets bigger I'm going to need more automation to perform this task.
No, it doesn't know what it did in a previous run. It compares the data on the receiving side with the data to be send. With small enough data, this won't be apparent, but when you have large enough directories, the time spent comparing before the copying actually starts is easily felt.
The default check is for file modification times and sizes. From
man rsync
:And:
Note that these are not implied by the options you used.
-a
is:General
If I understand correctly,
rsync -av
has no memory, so it will copy the files that were renamed/deleted too, because they are present in the source but no longer present in the target.Tips
Use the option
-n
, 'dry run', to check what happens before you run yourrsync
command line.Notice the special meaning of a trailing slash after the source directory, and see the difference between
and
which is described in the manual
man rsync
.Example
Your special case (adding a file to the source directory 'a' and removing a file from the target directory 'b') will add both the added file and the previously copied file, because it is still in the source directory. This will happen both with and without the option
-u
and I don't know any option inrsync
to fix that easily, if you want to keep it in the source directory.But you can remove it from the source directory or put the file name into the file
excluded
and use the option--exclude-from=excluded
(for many files) or simply--exclude=PATTERN
for one or a few files.Alternative:
unison
You may want to test the tool
unison
, which is a synchronizing tool. It provides a visual method to identify special cases and decide what to do. There is a GUI version (unison-gtk
).It only copies the new files in /dir/a. Whatever you do in /dir/b will be ignored, unless you use the --delete option. In that case, renamed files in /dir/b will be deleted. It will force /dir/b to become exactly like /dir/a.
About the bonus, do you mean like in the case of renaming files in /dir/a, and then rsyncing to /dir/b? I dont think there is a way to prevent rsync from just copying the files again in that case.