1

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)

Eike Pierstorff
  • 29,331
  • 4
  • 35
  • 52
Nuv
  • 81
  • 1
  • 2
  • 6
  • 1
    Are you sure you want to back up *every sector*? Even deleted files? Even space never allocated since the disk was initialized (with a filesystem)? If not, then the O/S modification notification is the way to go. – wallyk Oct 10 '12 at 09:32
  • You are correct. I wouldn't want to do that. Thankyou – Nuv Oct 10 '12 at 09:45
  • It is operating system specific and file system specific – Basile Starynkevitch Mar 01 '18 at 07:52
  • I'm afraid that your approach is rather naive! For starters, try reading up a bit about [ZoL](https://github.com/zfsonlinux/zfs/) and its replication methods. If you have ZFS on your disk, this is already taken care. It has clean ways to replicate(backup?) incrementally, by blocks! It's effective and probably the most elegant filesystem! If you are running Linux, give it a go. There are various ports of ZFS for the popular operating systems. – six-k Mar 18 '18 at 17:07

2 Answers2

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.

Some programmer dude
  • 363,249
  • 31
  • 351
  • 550
0

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....

wallyk
  • 53,902
  • 14
  • 79
  • 135