Linux Labs

Storage / Stage 10 of 11

Rsync — mirrors, comparison and deletion boundaries

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 8 · theory · 5 min

Removing extras from the copy

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:

text
$ rsync -ain --delete source/ mirror/
*deleting   obsolete.txt
>f+++++++++ new.txt
>f..t...... data/orders.csv

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.

Warning

Running such a plan without -n wipes the whole copy. With --delete, look at the plan first and read every *deleting line.

Check yourself 1 question

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 site first.

  • Without the slash rsync puts the site directory itself inside the destination, into /backup/site/site/, and an empty source stays empty.

  • -c changes how files are compared, not which ones get deleted: whatever is missing from the source, --delete removes with -c too.

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

  • --delete removes from the destination whatever the source lacks, and only inside the directory being copied into.
  • A plan with nothing but deletions and no >f transfers points to an empty or wrong source.
Ubuntu 24.04
Loading…