rsync --delete doen not delete some things

I’m cloning a system to a virtual machine. The source system has a ext4 / partition with almost everything (except /boot).
The target VM has some partitions, I have booted it with a Live CD, mounted all of them on a /tutatis directory

/dev/sda1 on /tutatis type btrfs (rw,relatime,space_cache,subvolid=257,subvol=/@)
/dev/sda1 on /tutatis/var type btrfs (rw,relatime,space_cache,subvolid=258,subvol=/@/var)
/dev/sda1 on /tutatis/boot/grub2/i386-pc type btrfs (rw,relatime,space_cache,subvolid=259,subvol=/@/boot/grub2/i386-pc)
/dev/sda1 on /tutatis/boot/grub2/x86_64-efi type btrfs (rw,relatime,space_cache,subvolid=260,subvol=/@/boot/grub2/x86_64-efi)
/dev/sda1 on /tutatis/opt type btrfs (rw,relatime,space_cache,subvolid=261,subvol=/@/opt)
/dev/sda1 on /tutatis/srv type btrfs (rw,relatime,space_cache,subvolid=262,subvol=/@/srv)
/dev/sda1 on /tutatis/tmp type btrfs (rw,relatime,space_cache,subvolid=263,subvol=/@/tmp)
/dev/sda1 on /tutatis/usr/local type btrfs (rw,relatime,space_cache,subvolid=264,subvol=/@/usr/local)
/dev/sda1 on /tutatis/software type btrfs (rw,relatime,space_cache,subvolid=265,subvol=/@/software)
/dev/sdb1 on /tutatis/home type ext4 (rw,relatime)
/dev/sdc1 on /tutatis/imagenes type ext4 (rw,relatime)

And then I have enabled rsyncd and run rsync from the source:

tutatis:~ # rsync  -aAxXHu --times --delete -v --log-file=rsync.log /

I ran it and it seems to work (it copied over 1TB and all seemed to be in order), then I realized I have some junk directories in the source, I delete them and run again rsync (same command), new stuff was copied, but the junk directories were not deleted.

I think --delete should have deleted them … what am I doing wrong?

best regards

Try without the -u Update option “Skip files that are newer on the receiver”. A file existing is newer than a file not-existing (since not-existing is nothing) and rsync probably skips them from the --delete option.

You can also remove the --times option since it is automatically a part of the -a “Archive” option.

I did, but after doing it

rsync  -aAxXhH --delete -v --log-file=rsync.log /

on the source

tutatis:~ # tree -ah /
289565 directories, 2047732 files

on the target

[root@sysrescue ~]# tree -ah /tutatis
254719 directories, 1773403 files

and the directories that should be delete are still there

The -H Preserve Hard Links option could also be the problem. Obviously, with that option, if that data is referenced by anything else in the system, it won’t get deleted. I don’t think you don’t need to preserve hard links since you’re copying to an entirely separate system.

I suggest keeping it simple with just using -av --delete and fine-tune from there.

Add –dry-run while experimenting so rsync only outputs what it would have done until you’re confident you have it working.

After a lot of tests I have discover what was the problem.
I have two different filesystems in the source ( / and /boot) and three in the target ( / and btrfs subvols, /home and /imagenes ).
I was using

rsync  -aAxXhH --delete -v  /
rsync  -aAxXhH --delete -v  /boot/

any other filesystem (
with “x” option (not jump to another filesystem) in order to copy both filesystems from the source to the target avoiding problems with any other filesystem like /dev, /run .etc.

I didn’t that the “x” option would affect also the target, but it does. In the source /home is included in the / filesystem, but in the target is a separate filesystem, so I had to run

rsync  -aAxXhH --delete -v  /
rsync  -aAxXhH --delete -v  /boot/
rsync  -aAxXhH --delete -v  /home/
rsync  -aAxXhH --delete -v  /imagenes/

Now it seems everything is synced

best regards

I don’t think -u has any affect. Here’s my backup script with different -u and -v options, and they all delete the same number of files:

> sudo rsync -vnaRsu --delete --info=del1,stats1,name1 --exclude=/root/.cache --exclude=/home/*/{.cache,.local/share/libvirt/images,.mozilla,.xsession-errors*,.config/chromium,.config/discord,.config/ibus,.config/pipewire/media-session.d,.sword/InstallMgr,.zoom/logs,.Xauthority} /etc /root /usr/etc /usr/local/bin /home/gene /mnt/backups/openSUSE | grep '^deleting' | wc -l

> sudo rsync -naRsu --delete --info=del1,stats1,name1 --exclude=/root/.cache --exclude=/home/*/{.cache,.local/share/libvirt/images,.mozilla,.xsession-errors*,.config/chromium,.config/discord,.config/ibus,.config/pipewire/media-session.d,.sword/InstallMgr,.zoom/logs,.Xauthority} /etc /root /usr/etc /usr/local/bin /home/gene /mnt/backups/openSUSE | grep '^deleting' | wc -l

> sudo rsync -naRs --delete --info=del1,stats1,name1 --exclude=/root/.cache --exclude=/home/*/{.cache,.local/share/libvirt/images,.mozilla,.xsession-errors*,.config/chromium,.config/discord,.config/ibus,.config/pipewire/media-session.d,.sword/InstallMgr,.zoom/logs,.Xauthority} /etc /root /usr/etc /usr/local/bin /home/gene /mnt/backups/openSUSE | grep '^deleting' | wc -l

I don’t specify --delete on a regular basis, so there are quite a few orphaned files.