Skip to main content
1 of 2

Comparing original & backup folder, then deleting non-existing files

this is my first time asking so please forgive any of my mistakes. Also, I'm pretty new to programming in general and trying to learn by doing.

I'm using Raspbian jessie (ubuntu). I made a .sh that makes a backup .img of everything (excluding mnt, tmp, run, dev, boot, etc.) and let this run once a week with crontab. It checks for modified files and only copies those. This is very useful I find since there is no need to make a big, full backup of everything, every time anew. This works perfectly. The .sh contains following command:

sudo rsync -aAHvpE --delete-during --exclude-from=/etc/rsync-exclude.txt / /mnt/usb0/backup/partition2

However, after checking the backup I noticed it still contained a file that I had already deleted on my original system. For example the file /test.txt was backed up to /mnt/usb0/backup/partition2/test.txt , however after deleting the original and making a new backup it didn't disappear on the backup.

Now my question is: what ways are there to check for files that don't exist in the original folder anymore, then delete those in my backup folder too? (WITHOUT having to delete everything first and then make a full backup from scratch).