First of all, --delete
option can lead to some unwanted destructive results if you are unaware of the background. For example, if the source becomes empty then all the existing files at the destination will be removed or if some files are removed from source then those files will be removed from destination too.
What happens if my hard drive gets corrupted, and some files can not
be read anymore?
If rsync
can not read the source, it would show a permission denied message and won't do anything further. So your existing files at the destination will be safe.
Is there any scenario other than "me deleting the files on my hard
drive" that will lead to deletion of the files on the USB stick?
Unless your USB itself gets corrupted, no, there is no scenario where (you don't remove files from source, the hard drive and) the existing files on the USB will get deleted by rsync
with --delete
option.
Test:
% ls -1 source dest
dest:
source:
foo
% rsync -av --delete source/ dest
sending incremental file list
./
foo
sent 143 bytes received 38 bytes 362.00 bytes/sec
total size is 16 speedup is 0.09
% ls -1 source dest
dest:
foo
source:
foo
% chmod 000 source
% rsync -av --delete source/ dest
sending incremental file list
rsync: change_dir "/source" failed: Permission denied (13)
sent 20 bytes received 12 bytes 64.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]
% ls -1 source dest
dest:
foo
ls: cannot open directory source: Permission denied