Search code examples
.netbackupfilesystemwatcher

Use FileSystemWatcher to backup files


I want to use FileSystemWatcher to immediately push newly generated files to the cloud.

My concern is that if the app which is doing the watching is shut down for some time then it will miss some files and they'll never make it to the back-up.

Is there anyway around this? Or should I use a message queue?


Solution

  • You could have one process with two FileSystemWatchers. 1. The first watches an incoming file location, and moves (not copies) files from the incoming location to an outgoing location. 2. The second watches the outgoing location and pushes files to the cloud.

    In addition to the FileSystemWatchers, the process scans the incoming location on startup. That way if it was down and new files were added, when it restarts those new files still get moved to the outgoing location. While the process is down nothing is getting moved to the outgoing location so there's nothing for it to miss.

    Update I suppose it also depends on the nature of the files. If you need greater reliability then you could build a more robust process, capturing the details of any file in the location and enqueuing a list of files to be copied (perhaps in a table.) That way you don't have to rely on the presence or absence of file to determine status.