blipman17 blipman17 - 3 months ago 15
Linux Question

watching a directory tree whitout inotify

I'm trying to write a backup utility that is supposed to handle a rough 2 terrabytes of data in a lot of folders.

I want it to perform actions on files when they get created/edited/deleted preferrably also file moves or renames.

I've messed around with fanotify, only to realize it only works with file edits.
And I'm against using inotify if I can since I would have to edit the maximum file watches, which I don't want to do.
It would have a big performance impact I presume.

I'd preferably just set a single filewatch that works recursively to all files underneath it.
Is there anyone who has experience with this who knows what a good method is?
Should I go for inotify and just take the performance hit?
Or is there a different approach I can take?

Answer

I don't think there is a way to recursively watch for changes in a directory tree. On the other hand, with inotify, you don't need to create one file descriptor per directory you watch. You create a single inotify object and then add many directories to it with inotify_add_watch

int inotify_add_watch(int fd, const char *pathname, uint32_t mask);
Comments