rsync - 相关问题 - --log-file

本文介绍了rsync命令中的--log-file选项,该选项允许用户将rsync的操作记录到指定的文件中,对于调试连接异常关闭等问题十分有用。文中提供了一个示例命令,展示如何配置远程服务器端的日志记录。

rsync - 相关问题 - --log-file

# rsync - 相关问题 - --log-file
# --log-file=FILE
# This option causes rsync to log what it is doing to a file. This is similar to the logging that a daemon does, but can be requested for the client side and/or the server side of a non-daemon transfer. If specified as a client option, transfer logging will be enabled with a default format of "%i %n%L". See the --log-file-format option if you wish to override this.
# 该选项使rsync将行为记录到一个文件中。类似于守护进程的日志,但是客户端 和/或 非守护进程的服务器传输时可能会要求使用。如果指定为一个客户端选项,传输日志将使用默认格式"%i %n%L",如果希望替换则参见--log-file-format选项。
#
# Here's a example command that requests the remote side to log what is happening:
# 这是一个请求远程端记录日志的示范命令:
#
# rsync -av --rsync-path="rsync --log-file=/tmp/rlog" src/ dest/
#
# This is very useful if you need to debug why a connection is closing unexpectedly.
# 当一个连接不正常关闭时进行调试非常有用。

[rsync - 官方网站]

http://rsync.samba.org/

[rsync - 关键词]

rsync
rsyncd

[rsyncd.conf - 官方文档]

http://samba.org/ftp/rsync/rsyncd.conf.html

[rsync - 相关问题]

全局部分中常用全局参数配置说明

全局部分中常用模块参数配置说明

模块常用配置说明

认证相关参数配置说明

客户端常用参数

客户端其他参数

for Windows (cygwin)

远程shell模式和rsync守护进程模式

22.6. File Synchronization. Building Internet Firewalls, 2nd Edition

Hack 92 Mirroring Web Sites with wget and rsync. Spidering Hacks

Linux Security Cookbook - Recipe 1.16 Integrity Checking with rsync

Linux Security Cookbook - Recipe 1.6 Remote Integrity Checking

Linux Security Cookbook - Recipe 6.3 Copying Files Remotely

正确设置gid参数

--backup-dir 使用示例

hosts allow

hosts deny

gid

synopsis提要

翻译 - daemon options summary守护进程选项概述

--log-file

### 如何配置 rsync 减少 `-v` 选项的日志输出频率 为了减少 `rsync -v` 的日志输出频率,可以考虑以下方法: 1. **使用 `--info` 和 `--log-file` 参数替代 `-v`** `-v` 选项会提供详细的同步过程信息,但如果希望减少日志输出的频率,可以使用 `--info` 参数来控制具体的日志级别。例如,通过指定 `--info=progress2` 可以仅显示传输进度而不输出每个文件的详细信息[^2]。同时,可以通过 `--log-file` 将日志记录到文件中,而不是直接输出到终端。 示例命令如下: ```bash rsync -a --delete --info=progress2 --log-file=/var/log/rsync.log /path/to/source/ /path/to/destination/ ``` 2. **结合 `--out-format` 定制日志输出格式** 使用 `--out-format` 参数可以自定义日志内容,从而减少不必要的信息输出。例如,仅记录文件名和时间戳,忽略其他细节。 示例命令如下: ```bash rsync -a --delete --out-format="[%t] %n" /path/to/source/ /path/to/destination/ > /var/log/rsync.log 2>&1 ``` 3. **通过脚本实现增量同步并限制日志范围** 如果只需要同步部分文件夹或特定日期的文件,可以通过脚本限制日志输出范围。例如,使用 `--include` 和 `--exclude` 参数仅同步当天、昨天和前天的文件夹,并将日志记录到文件中。 示例脚本如下: ```bash current_date=$(date +"%Y-%m-%d") yesterday_date=$(date -d "yesterday" +"%Y-%m-%d") two_days_ago_date=$(date -d "2 days ago" +"%Y-%m-%d") while true; do rsync -azP --port 9879 --timeout=600 \ --include='*/' \ --include="$current_date/**" \ --include="$yesterday_date/**" \ --include="$two_days_ago_date/**" \ --exclude='*' \ --no-g --checksum --ignore-missing-args \ $src $user@$host::$des >> /tmp/rsync.log 2>&1 echo "${files} was rsynced" >> /tmp/rsync.log sleep $interval done ``` 4. **调整日志重定向策略** 如果日志输出过于频繁,可以通过脚本限制日志记录的频率。例如,每小时清空一次日志文件或将日志文件分割为多个小文件。 示例命令如下: ```bash rsync -avz --delete /path/to/source/ /path/to/destination/ > >(tee -a /var/log/rsync.log) 2>&1 ``` 5. **禁用冗余日志输出** 如果不需要任何详细日志,可以直接移除 `-v` 或 `--info` 参数,仅保留基本的同步功能。 示例命令如下: ```bash rsync -a --delete /path/to/source/ /path/to/destination/ > /dev/null 2>&1 ``` ### 注意事项 - 如果需要监控同步过程但又不希望日志过于冗长,建议使用 `--info=progress2` 或 `--out-format` 参数。 - 对于大规模文件同步任务,建议结合定时任务(如 `cron`)或脚本实现增量同步,以减少不必要的日志输出[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值