Get notified about the change in raw data in hard

2019-08-15 01:45发布

问题:

I'm trying to make a software that backups my entire hard drive.

I've managed to write a code for reading the raw data from hard disk sectors. However, i want to have incremental backups. For that i need to know the changed made to OS settings, file changes, everything.

My question is -

Using FileSystemWatcher and Inotify, will i be able to know every change made to every sector in the hard drive ? (OS settings etc)

I'm coding it in C++ for linux and windows.

(Saw this question on Stackoverflow which gave me some idea)

回答1:

Inotify is to detect changes while your program is running, I'm guessing that FilySystemWatches is similar.

One way to solve this is to have a checksum on each sector or multiple of sectors, and when making a backup you compare the checksums to the list you have and only backup blocks that have been changed.



回答2:

The MS Windows FileSystemWatcher mechanism is more limited than Linux's Inotify, but both probably will do what you need. The Linux mechanism provides (optional) notification for file reads, which causes the "access timestamp" to be updated.

However, the weakness from your application's perspective is that all file modifications made from system boot up to your program getting loaded (and unload to shutdown) will not be monitored. Your application might need to look through file modification timestamps of many files to identify changed files, depending on the level of monitoring you are targeting.

Both architectures maintain a timestamp for each file tracking when the file was last accessed. If that being updated is a trigger for a backup notification, the Windows mechanism lacking such notification will cause mismatched behavior on the platforms. Windows' mechanism can also drop notifications due to buffer size limitations. Here is a real gem from the documentation:

Note that a FileSystemWatcher does not raise an Error event when an event is missed or when the buffer size is exceeded, due to dependencies with the Windows operating system. To keep from missing events, follow these guidelines:

  • Increasing the buffer size with the InternalBufferSize property can prevent missing file system change events.

  • Avoid watching files with long file names. Consider renaming using shorter names.

  • Keep your event handling code as short as possible.

At least you can control two out of three of these....