Prevent --max-delete from deleting any files?

Marco Moreno mmoreno at
Wed Jun 2 11:30:51 MDT 2010

Is there a way to prevent rsync from deleting any files if --max-delete is exceeded?
I want to avoid having my hourly cron job inadvertently destroy my backup a chunk 
at a time.  By morning, the damage would already be done.  Ideally, it should just
stop and not sync or delete anything since something is horribly wrong.

The only way I could see to do it is by running rsync twice - something like:

  rsync --dry-run -a --delete --max-delete=1000 /foo /bar && rsync -a --delete --max-delete=1000 /foo /bar

I found bug 2408 ( that described my concerns:

> If you specify the --max-delete option to rsync and there are more files to be
> deleted than the specified number, all the deletes upto that number are normally
> performed and other files that would otherwise be deleted are now silently
> ignored. Also, if more files are scheduled for removal, no error code is returned.
> The --max-delete option is especially usefull if by some misconfiguration a
> great number of files would be deleted. If it is a job that runs daily, all the
> files would be silently deleted after a few days rather than all at once more or
> less defeating the purpose.
> What I would like to see would be a test that would exit rsync with an error
> code if too many deletes would take without actually deleting any files.
> Returning an error code is the least that should be done IMHO.

The response was:

> ------- Comment #4 From Wayne Davison 2005-03-06 00:02:57 CST [reply] -------
> I have updated the source in CVS so that it complains at the end of the run and
> returns a new status code (25) when the max-delete value is exceeded.  It also
> mentions how many deletions were skipped.  This will let you run rsync with
> --dry-run --max-delete=1 to see a count of the number of deleted files minus
> one. I don't have any plans to make rsync check the delete count automatically
> before starting the deletions.

While adding the return code was a big improvement, is there any possibility of 
revisiting this issue to prevent deletions altogether if something is wrong?  
Perhaps a new option such as --max-safe-delete or something?  While I understand 
that it is inefficient to count up all the files in advance before doing the 
deletions, it cannot be as inefficient as having to run rsync twice.



Marco Moreno

More information about the rsync mailing list