logging - 使用 rsync 检索日志文件

标签 logging rsync system-administration

这个问题很难通过 Google 搜索,因为存在 rsync 生成的日志文件,而这不是我感兴趣的内容。

我想做的是使用 rsync 从一组服务器检索日志文件。通常,当我想要将一堆个人文件从我的家庭服务器传输到我的笔记本电脑时,我会执行以下操作:

rsync --rsh='ssh' -av --progress --partial user@host:源目标

也就是说检索我的假期视频以向我的家人展示。但我现在想使用 rsync 将文件从服务器检索到备份位置。由于我的日志文件只是追加,并且经常写入,有没有一种方法可以使 rsync 足够智能以“跟踪”更改,而不是一遍又一遍地重新验证最初的一百万行?如果没有,人们是否还有其他应用程序用于此目的?我不想使用 UDP 连接,因为我希望能够在不丢失数据的情况下处理流量峰值,而 TCP 会太慢,因此我希望对本地文件进行备份,以便在不活动期间进行备份。

最佳答案

我也遇到同样的问题。我想使用 rsync 构建日志集中化。问题是,每当源日志文件获得更新时,rsync 就会将整个日志文件传输到远程服务器并删除旧的日志文件。这种行为实在是太彻底了,让我失去了理智。

事实证明,rsync 有一个--append 标志,允许rsync 仅更新日志文件的“新部分”。 (我只在日志文件上测试)

来自手册页:

--append     append data onto shorter files

来自explainshell.com :

--append

This causes rsync to update a file by appending data onto the end of the file, which presumes that the data that already exists on the receiving side is identical with the start of the file on the sending side. If a file needs to be transferred and its size on the receiver is the same or longer than the size on the sender, the file is skipped. This does not interfere with the updating of a file’s non-content attributes (e.g. permissions, ownership, etc.) when the file does not need to be transferred, nor does it affect the updating of any non-regular files. Implies --inplace, but does not conflict with --sparse (since it is always extending a file’s length).

例如

rsync -avz --append /source/dir /dest/dir

它不会重新验证整个文件,但只会附加更改。

关于logging - 使用 rsync 检索日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32185895/

相关文章:

docker - Rancher 服务器前缀

java - 格式化记录器文件处理程序问题

ruby-on-rails - 在 Rails 服务器日志中查看 Resque 日志输出

mysql - 在插入或更新时获取完整的 MySQL 查询字符串

javascript - shell 命令到 child_process.spawn(command, [args], [options]) node.js

python - 如果从源代码安装,如何卸载包管理器 "pip"?

linux - 如何在 linux (debian) 上获取文件访问信息

django - 跨机器同步 PostgreSQL 数据库的替代解决方案

php - 在发布过程中什么时候应该缩小我的 css 和 js 文件?

windows - 映射服务使用的网络驱动器