0

I'm executing the following two rsync commands. In the first command, I'm copying files from source to destination and in the second command I'm then checking the files and delete the files in source.

rsync --info=progress2 -r /local/data/ /import/myNAS/data
rsync --info=progress2 -r --checksum --remove-source-files /local/data/ /import/myNAS/data

I would like to only copy and remove files from source to destination which do not exists already in destination. I could do this using the --ignore-existing flag but with this flag files are copied when they are newer. I would like to have a check only on name and not timestamp. That means when a file with the same name exists in destination, the file should not be copied from source and should also not be deleted from source.

Is this possible?

7
  • Remove --checksum. Replace -r with -a. Discard the first of the two commands. – roaima Aug 17 '20 at 23:48
  • @roaima Why not using --checksum? – machinery Aug 18 '20 at 17:27
  • Because it's worse than pointless when both source and destination look like local paths. Without it, rsync will just copy the files in their entirety. With it, it will checksum the files and then copy them anyway. – roaima Aug 18 '20 at 18:02
  • @roaima The source is a local path but the destination is on a NAS. My intention behind using checksum is that errors can occur when copying on a NAS (corrupted files). – machinery Aug 18 '20 at 21:37
  • 1
    @roaima I see but is there no possibility for errors during copying? My intention was with the second command to check for copying errors. – machinery Aug 20 '20 at 21:34
1

Your description does not match how --ignore-existing should work. It should indeed prevent copying (even newer) files that already exist on the destination.

$ rsync -a a/ b/
$ touch a/new a/update
$ rsync -ai --ignore-existing a/ b/
.d..t....... ./
>f++++++++++ new
$ ls -ln */{new,update}
-rw-r--r--  1 34570  344586812  0 Aug 17 14:50 a/new
-rw-r--r--  1 34570  344586812  7 Aug 17 14:50 a/update
-rw-r--r--  1 34570  344586812  0 Aug 17 14:50 b/new
-rw-r--r--  1 34570  344586812  7 Mar 26 17:02 b/update

a/update now has a more recent timestamp, but is not updated by rsync.

Can you try running your rsync again, but add the -i flag and show the output for your existing files? It will add a line for the copied files for the reason it is copying. I'm wondering if there is some information in there that will point to the issue.

4
  • Thanks. You are right I think. But the problem now I have is that I only want to copy and remove files that are not existing. When I add --ignore-existing to the first rsync call then only files not existing in destination are copied but in the second rsync call then all source files are deleted. If I add ignore-existing also in the second rsync call then no files are deleted in source. – machinery Aug 18 '20 at 21:40
  • "existing" only lasts for one run. Your choices are either a) do everything you need in a single rsync run or b) capture the files moved by the first run and explicitly sync/delete them in the second run. – BowlOfRed Aug 18 '20 at 21:44
  • I think b) is what I need. How can I capture files moved in the first run? – machinery Aug 19 '20 at 19:04
  • I don't know of anything official. So I think you're left with either the -v or -i output and parsing it. Either of which might be potentially (but unlikely) ambiguous due to newlines and such. – BowlOfRed Aug 19 '20 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.