Linux 下爬虫即将写满硬盘,有啥实时数据迁移方法?

2017-11-03 00:41:41 +08:00
 cy97cool

概括

有爬取进程如wget正在持续对一个文件夹写入大量较小的文件,如何迁移已经完成写入的文件到其他服务器以腾出空间?

需求

更难一点的需求

如果持续写入的不是多个小文件,而是一个整个大文件,即将写满硬盘

这种情形下可不可能 分块完成迁移 且 对写入这个文件的进程 无感知?

1824 次点击
所在节点    问与答
6 条回复
oott123
2017-11-03 00:53:11 +08:00
自己撸个 fuse 应该是能满足的
cy97cool
2017-11-03 00:57:04 +08:00
@oott123 写入进程已经在运行了。。。即使写 fuse 也来不及了吧 Orz
cy97cool
2017-11-03 00:59:22 +08:00
找到了个靠点边但不完全满足需求的:

rsync 有这个参数可以复制完成之后删除,但它不能识别正在被写入的文件,而要求使用排除*.new 这种方法避免正在被写入的文件

可以用这种方式多次调用逐步迁移进行写好的文件夹

```
--remove-source-files
This tells rsync to remove from the sending side the files (meaning non-directories) that are a
part of the transfer and have been successfully duplicated on the receiving side.

Note that you should only use this option on source files that are quiescent. If you are using
this to move files that show up in a particular directory over to another host, make sure that the
finished files get renamed into the source directory, not directly written into it, so that rsync
can ’ t possibly transfer a file that is not yet fully written. If you can ’ t first write the files
into a different directory, you should use a naming idiom that lets rsync avoid transferring files
that are not yet finished (e.g. name the file "foo.new" when it is written, rename it to "foo"
when it is done, and then use the option --exclude='*.new' for the rsync transfer).
```
cy97cool
2017-11-03 01:04:53 +08:00
可以用这种方式多次调用逐步迁移已经写完整的文件夹

问题来了,有没有轮子自动完成这种事情:
* 判断一个文件夹当前有没有被写入(也许比较 du -s 就够了)
* 如果没有 此次循环跳过
* 如果文件夹已经写好了,记录文件列表,调用 /通知远程调用 rsync --remove-source-files (服务器也许不能主动连接到数据迁移的目标服务器,比如迁移到自己电脑 自己电脑没有公网 IP ); rsync 完成后按文件列表恢复为 0 字节的文件
* 循环直到爬虫进程结束&&所有文件迁移完成
dobelee
2017-11-03 01:48:40 +08:00
这种写个小脚本就能完成吧,爬取的数据校验都不用。没必要搞那么复杂。
stanjia
2017-11-03 08:46:51 +08:00
rsync + mount

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/403099

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX