2

I have a Time Machine-style backup system set up on my NAS (running BusyBox v1.16.1), using rsync --link-dest as described here: http://blog.interlinked.org/tutorials/rsync_time_machine.html

Is there an easy way to find out which files will be deleted if I delete an old backup directory, and which will just be unlinked? I assume one way would be to find which inodes in the old directory have only one link to them, but I don't know a way to do that. rm --dry-run anyone?

Bonus Points: Find a way to do the above, and also calculate the total disk space freed if the old backup is deleted.

2

A simple way would be to just use find with the -links option.

Specifically you would want to do something like find path -type f -links 1.

I haven't tested, but I believe a command like this would delete all the multi-linked files.

# you might not need to escape the !, depends on your shell
# should find all the files that do NOT have a link count of 1 and delete them
find path -type f \! links 1 -print -delete 
  • Thanks! This is perfect. I don't need the second part; since the backup images are full of hard links, I just need to delete the oldest backup directory. find oldest/ -type f -links 1 >> files-lost-forever.txt; find oldest/ -type f -links 1 -print0 | xargs -0 du | awk '{total = total + $1}END{print total " bytes freed"}'; rm -rf oldest; – JDS Jun 26 '12 at 5:15
  • er... s/du/du -k/ and s/bytes/Kb/ – JDS Jun 26 '12 at 6:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.