We’re using rsnapshot for backups. It keeps lots of snapshots of the backuped up file, but it does delete old ones. This is good. However it’s taking about 7 hours to do a rm -rf
on a massive directory tree. The filesystem is XFS. I’m not sure how many files are there, but it numbers in the millions probably.
Is there anyway to speed it up? Is there any command that does the same as rm -rf
and doesn’t take hours and hours?
No.
“rm -rf” does a recursive depth-first traversal of your filesystem, calling unlink() on every file. The two operations that cause the process to go slowly are opendir()/readdir() and unlink(). opendir() and readdir() are dependent on the number of files in the directory. unlink() is dependent on the size of the file being deleted. The only way to make this go quicker is to either reduce the size and numbers of files (which I suspect is not likely) or change the filesystem to one with better characteristics for those operations. I believe that XFS is good for unlink() on large file, but isn’t so good for large directory structures. You might find that ext3+dirindex or reiserfs is quicker. I’m not sure how well JFS fares, but I’m sure there are plenty of benchmarks of different file system performance.
Edit: http://www.t2-project.org/zine/1/ suggests that XFS is terrible at deleting trees, so definitely change your filesystem.
Check more discussion of this question.