Question

I have an onsite backup folder /backup/ that has an offsite rsynced copy mounted locally as /mnt/offsite/backup/. My onsite backup drive is getting full, so I'd like to delete files older than 365 days, but first check to see if that file exists offsite, and log to file the filenames that were removed (to exclude from rsync).

I've come close with this:

cd /mnt/offsite/backup && find . -type f -mtime +365 -exec rm /backup/{} \; | >> file.lst

However the redirection isn't working. I've tried placing the >> in different places, and can't get it to work with exec in there. I've also tried using xargs rm, and can get the redirect working, but can't get xargs to delete from the second path:

cd /mnt/offsite/backup && find . -type f -mtime +365 >> file.lst | xargs rm /backup/

What's the best approach?

Was it helpful?

Solution

Hope this helps

find /mnt/offsite/backup -type f -mtime +365 -exec rm {} \; -print >> file.lst
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top