简体   繁体   English

使用FileSystemWatcher备份文件

[英]Use FileSystemWatcher to backup files

I want to use FileSystemWatcher to immediately push newly generated files to the cloud. 我想使用FileSystemWatcher立即将新生成的文件推送到云中。

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? 还是应该使用消息队列?

You could have one process with two FileSystemWatchers. 您可以使用两个FileSystemWatcher进行一个进程。 1. The first watches an incoming file location, and moves (not copies) files from the incoming location to an outgoing location. 1.第一个监视输入文件的位置,然后将文件从输入位置移动(而不是复制)到输出位置。 2. The second watches the outgoing location and pushes files to the cloud. 2.第二个监视输出位置并将文件推送到云中。

In addition to the FileSystemWatchers, the process scans the incoming location on startup. 除了FileSystemWatchers之外,该过程还会在启动时扫描传入的位置。 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. 如果需要更高的可靠性,则可以构建一个更强大的过程,在该位置捕获任何文件的详细信息,并将要复制的文件列表放入队列中(也许在表中)。这样,您就不必依赖于是否存在文件来确定状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM