HELP: need better understanding of "--delete" flag

Alan Chandler alan at
Wed Nov 23 06:48:35 GMT 2005

On Wednesday 23 Nov 2005 04:08, Jeff Martin wrote:
> Need to understand exactly what the "--delete" flag
> does when rsync runs.
> Here is my understanding... If a file is created on
> the source machine on monday, then rsync'd to the
> rsync server on monday night, then deleted on the
> source machine tuesday, then it will be deleted from
> the rsync server on tuesday night when the cron job
> runs again.
> But, would rsync under any circumstances, ever delete
> files on the source machine?

I don't think so.  I use --delete all the time on my backups to make the 
backup directory match exactly the source directory.

If I want to save any files on the backup directory that will get deleted by 
such an operation I also add --backup --backup-dir=XXXX

(where XXXX is somewhere useful)

> My log showed a bunch of these statements, and to be
> quite honest, scared the living daylights out of me.
> (from LOG)
> deleting peachbackups/peachw/Peachtree Archive Data
> Files/archivec/W200001.FRM
> deleting peachbackups/peachw/Peachtree Archive Data
> Files/archivec/W200000.FRM
> .........

Thats deleteing data from the backup directory - so that it matches what's in 
your source directory.  Isn't that what you want?

> I am using the script from the for 7-day
> incremental backups written by tridge.
> Here is the part I am not sure what it does...
> # the following line clears the last weeks incremental
> directory
> [ -d $HOME/emptydir ] || mkdir $HOME/emptydir
> rsync --delete -a $HOME/emptydir/
> rmdir $HOME/emptydir

That is just a technique for clearing out a directory on a machine that you 
connect to via rysncd.   Create an empty directory on you local machine, and 
then rsync --delete this directory to the remote machine, and it makes the 
remote directoy empty.

Alan Chandler
Open Source. It's the difference between trust and antitrust.

More information about the rsync mailing list