0

I'm using

rsync -avh --progress --delete `find /path/to/files -type f -printf "%p\n" | sort -rn | head -n 5` /path/to/backup/

to backup the newest 5 files. The --delete option is supposed to delete the files in the destination folder, if they are not within the 5 files which find outputs. Unfortunately the --delete option is not working. How to get it working or how to do what I do differently?

2
  • I think rsync don't know the found file is in sub-directory which find is looking, except current working directory rsync is executed Sep 27, 2017 at 12:37
  • You would need rsync each of the 5 files one by one through a for loop Sep 27, 2017 at 12:50

2 Answers 2

1

The rsync manual states:

--delete

This tells rsync to delete extraneous files from the receiving side (ones that aren’t on the sending side), but only for the directories that are being synchronized.

You are transmitting multiple individual files, therefore --delete won't work.

1
  • Thanks for your reply. I think I'm going to replace the --delete by an extra command which deletes the files that come of when sorting in reverse (-r removed).
    – rsyncUser
    Sep 27, 2017 at 14:56
0

I don't appear to have enough reputation yet to comment on your question, so I will do so in an answer.

First, I think it would help if you posted the file names that you are working with. I also wonder what the subdirectory structure is on /path/to/files. I say this because I want to know if the find you are running is actually printing the newest files. You aren't operating on timestamps here, which why I ask. So on that note, you may want to also paste the output of the find to help clarify.

Also, I'm wondering if the -n on sort is necessary. Sorta beside the point, but you could do a sort | tail -5.

Without seeing more output on what your files are, including in the destination, I'm not sure that this sort of rsync --delete is going to work. Had this ever worked for you, or are you just now seeing this up?

Alternatively, you may look into find's -newer, -delete, and/or mtime flags.

1
  • Thanks for your reply. I think --delete isn't working because rsync expects a directory. I think I'm going to replace the --delete by an extra command which deletes the files that come of when sorting in reverse (-r removed).
    – rsyncUser
    Sep 27, 2017 at 14:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .