views:

549

answers:

2

Hi, I have the needs to write a simple backup component to synchronize a folder and its sub folders to a server. For incremental backup I only want to upload the changed files. What would be the best way to track the changes in the file system? Some existing software like tortoisesvn and office groove have such capability to detect file changes. I wonder what is the best way to implement a similar thing.

Thanks!

+2  A: 

Your question is somewhat ambiguous:

If you are trying to go through all of your files and determine which ones need to be sent to the backup server:

The simplest method is to compare the modification times; if the file on your local system was modified after the one one your backup system, then it has changed and the backup needs to be updated. (It is possible to modify the modified times of a file using something like touch, but for the simple case you probably don't need to worry about this)

A more complicated (and computationally expensive) method would be to compute the hash codes of the files, and compare those; if the hash differs, you need to do a backup.

If you're trying to detect the moment that a file is being changed:

You can use a FileSystemWatcher (in C#/Windows), or the equivalent for your language/OS.

Daniel LeCheminant
+1  A: 

If Mac OS X there’s a thing called FSEvents. There must be some service in Windows for that, too.

Ilya Birman