1

I have a file /home/my/some/filename.xx with always the same datetime stamp (even if it is has been modified) with the same filesize. How could I specify to rsync that only this specific file should be copied each time? My current backup command is this:

sudo rsync -axvq --exclude /home/my/it/ --exclude /oit -e "ssh -i /home/my/.ssh/id_rsa" --rsync-path="sudo rsync" / user@192.168.1.1:/backup
5
  • Does this help ? -c, --checksum skip based on checksum, not mod-time & size. I don't understand the word "only" in your sentence. – pLumo Sep 12 '19 at 9:21
  • Thanks. By "only" I meant, that this rsync command should backup whole HDD to second location but all other files should be "synced" (I meant transfered just if they changed) and just this specific file "/home/my/some/filename.xx" must be transfered every time, regardless it's content has been modified or not. – peter Sep 12 '19 at 12:14
  • 2
    I don't think you can do that. Maybe a second rsync for just this file ... – pLumo Sep 12 '19 at 12:21
  • yes, that was my second idea :) to use second rsync just for that one file and forcibly request file transfer of this file everyday. – peter Sep 12 '19 at 12:31
  • To do that, you would rsync everything first, then scp just that one file. – Jim L. Sep 12 '19 at 21:12
0

The only way to tell rsync to apply different treatment to different files based on their name is via filters. Filters can determine whether a file is synchronized at all, or whether a file is deleted, but they can't determine the method used to check whether a file is up-to-date.

So you'll have to use two separate rsync commands: one that excludes this file and one for this file specifically with a different file comparison method.

rsync -axvq --exclude /home/my/some/filename.xx … / user@192.168.1.1:/backup &&
rsync -axvq --checksum --include / --include /filename.xx --exclude '*' /home/my/some/ user@192.168.1.1:/backup/home/my/some/

In the second command, I synchronize the directory but exclude every file in it except for the file to transfer. The reason I do that is to copy the directory's timestamp, which would otherwise be modified if filename.xx is created. If this edge case doesn't bother you, you can simplify the second line to just copy filename.xx.

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.