Without a separate option rsync only adds and updates. Here is what --delete removes, and where.
After the sync at the start of the lesson, mirror still had obsolete.txt, which is not in source. With --delete rsync removes from the destination everything the source lacks; in the plan these are the *deleting lines:
rsync deletes only inside the directory it copies into. The keep directory next to mirror stays untouched. With a source without the slash it deletes only in mirror/source/: obsolete.txt at the top of mirror stays.
rsync does not check the source: whichever directory comes first is the reference. An empty source, such as a directory where a disk is not mounted, gives a plan where every file of the copy is marked *deleting and there is not a single >f line.
Running such a plan without -n wipes the whole copy. With --delete, look at the plan first and read every *deleting line.
The plan of rsync -ain --delete site/ /backup/site/ is a hundred *deleting lines and not a single >f line. What do you do?
-
A hundred deletions and no transfers point to an empty or wrong source. Running it wipes the copy: look at
ls sitefirst. -
Without the slash rsync puts the
sitedirectory itself inside the destination, into/backup/site/site/, and an empty source stays empty. -
-cchanges how files are compared, not which ones get deleted: whatever is missing from the source,--deleteremoves with-ctoo.
A plan of nothing but deletions means the source is empty or wrong: for example, the disk is not mounted at site. Check the source first, then run.
Key points
-
--deleteremoves from the destination whatever the source lacks, and only inside the directory being copied into. -
A plan with nothing but deletions and no
>ftransfers points to an empty or wrong source.