rsync软件 rsync log日志时间与系统时间差8小时问题处理

本文介绍了一种使用rsync进行远程实时同步备份时遇到的日志时间偏差问题及其解决方案。通过修改系统的环境变量,成功将rsync日志的时间与实际时间对齐。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:

用rsync+sersync配置远程实时同步备份,两边配置完成,正常同步。后发现同步日志rsync.log时间比系统时间慢8个小时问题,如下:

系统时间信息:

[root@rsync ]# timedatectl

      Local time: Wed 2020-10-28 14:38:55 CST
  Universal time: Wed 2020-10-28 06:38:55 UTC
        RTC time: Wed 2020-10-28 06:27:57
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

time文件:

[root@rsync 427]# ls -l /etc/localtime 
lrwxrwxrwx. 1 root root 35 Oct 27 17:17 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

[root@rsync 427]# date
Wed Oct 28 14:39:28 CST 2020

rsynclog日志文件信息:

2020/10/28 03:33:50 [14630] connect from sersync (192.192.101.96)
2020/10/27 19:33:50 [14630] rsync to docshare/ from rsyncuser@sersync (192.192.101.96)
2020/10/27 19:33:50 [14630] receiving file list
2020/10/27 21:02:34 [14630] sent 1906166 bytes  received 157271577 bytes  total size 545619813056
2020/10/28 05:03:50 [15569] connect from sersync (192.192.101.96)
2020/10/27 21:03:50 [15569] rsync to docshare/ from rsyncuser@sersync (192.192.101.96)
2020/10/27 21:03:50 [15569] receiving file list
2020/10/27 22:48:52 [15569] sent 1905998 bytes  received 157271429 bytes  total size 545619813056

解决办法:

修改/etc/profile文件,添加export TZ=‘CST-8'

source  /etc/profile 使修改立即生效。

再查看日志时间rsync.log,显示正常,如下:

2020/10/28 14:32:53 [21159] rsyncd version 3.1.2 starting, listening on port 873
2020/10/28 14:33:07 [21170] connect from sersync (192.192.101.96)
2020/10/28 14:33:07 [21170] rsync to docshare/ from rsyncuser@sersync (192.192.101.96)
2020/10/28 14:33:07 [21170] receiving file list

再次查看timedatectl,发现有告警,不知道有没有影响,待测

[root@rsync 427]# timedatectl
Warning: Ignoring the TZ variable. Reading the system's time zone setting only.

      Local time: Wed 2020-10-28 14:38:55 CST
  Universal time: Wed 2020-10-28 06:38:55 UTC
        RTC time: Wed 2020-10-28 06:27:57
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

### Delta Dump 技术实现数据处理 Delta dump 是一种增量备份技术,主要用于减少全量备份所需的时间和存储空间。它通过记录自上次备份以来发生的变化来完成这一目标。以下是关于 delta dump 的技术和数据处理的相关内容: #### 1. Delta Dump 的基本原理 Delta dump 的核心在于识别和保存自上次备份以来发生变化的数据部分。这种机制通常依赖于文件系统元数据或数据库中的变更日志。例如,在文件系统中,可以通过比较修改时间戳(mtime)、inode 或哈希值来检测变化;而在数据库场景下,则可能利用事务日志(Transaction Log)或二进制日志(Binary Log)。这种方法显著减少了重复数据的传输和存储需求[^4]。 #### 2. 实现细节 在实际应用中,delta dump 的实现涉及以下几个方面: - **差异计算**:使用算法(如 Rsync 算法)对比源数据和已有备份之间的差异,生成仅包含新增或更改部分的数据集。 - **压缩优化**:为了进一步节省带宽和存储资源,通常会对差分数据进行压缩编码。常见的方法包括 Gzip、LZMA 和 Zstandard。 - **恢复策略**:当需要还原时,必须能够基于基础镜像以及一系列增量更新重建完整的原始状态。这要求设计良好的版本管理和合并逻辑。 对于 Java 应用程序而言,如果采用 Arthas 工具执行 heapdump 操作,则可通过参数控制是否只导出存活对象 (`--live`) 来模拟简单的增量行为[^1]。然而严格意义上的 delta dump 需要更复杂的跟踪机制。 #### 3. 数据处理流程 典型的 delta dump 数据处理过程如下所示: 1. 初始化阶段创建初始快照作为基线; 2. 定期扫描监控区域内的变动情况; 3. 提取出新产生的或者被改动过的片段形成增量包; 4. 将这些增量打包上传至远程服务器或其他持久化位置存档; 5. 清理本地缓存以释放空间并准备下次迭代。 下面是一个 Python 脚本示例演示如何构建简易版文件级 delta backup 功能: ```python import os import hashlib from datetime import timedelta, datetime def calculate_hash(file_path): hasher = hashlib.md5() with open(file_path, 'rb') as f: buf = f.read(65536) while len(buf) > 0: hasher.update(buf) buf = f.read(65536) return hasher.hexdigest() def generate_delta(base_dir, target_dir, output_file="delta.txt"): base_hashes = {} current_hashes = {} # Load hashes from previous run or initialize empty dict. try: with open(os.path.join(target_dir, ".hashes"), "r") as hashfile: for line in hashfile.readlines(): fname, hsh = line.strip().split(": ") base_hashes[fname] = hsh except FileNotFoundError: pass # Calculate current state of files. for root, dirs, files in os.walk(base_dir): rel_root = os.path.relpath(root, start=target_dir) for name in files: full_path = os.path.join(root, name) relative_name = os.path.normpath(os.path.join(rel_root, name)) current_hashes[relative_name] = calculate_hash(full_path) changes = [] now = datetime.now() # Compare states and record differences. for filename, cur_hash in current_hashes.items(): prev_hash = base_hashes.get(filename) if not prev_hash or prev_hash != cur_hash: action = "MODIFIED" if prev_hash else "ADDED" timestamp = (now - datetime.fromtimestamp( os.stat(os.path.join(base_dir, filename)).st_mtime)).total_seconds() / 60 changes.append(f"{action} {filename}, last modified {int(timestamp)} minutes ago.") removed_files = set(base_hashes.keys()) - set(current_hashes.keys()) for rm_file in removed_files: changes.append(f"REMOVED {rm_file}") # Save new snapshot. with open(os.path.join(target_dir, ".hashes"), "w") as hashfile: for fnm, hshtxt in current_hashes.items(): hashfile.write(f"{fnm}: {hshtxt}\n") # Write change log. with open(output_file, "a+") as logfile: logfile.writelines([f"[{datetime.strftime(now, '%Y-%m-%d %H:%M:%S')}]{line}\n" for line in changes]) if __name__ == "__main__": source_directory = "/path/to/source/" destination_directory = "/path/to/destination/" generate_delta(source_directory, destination_directory) ``` 此脚本会递归遍历指定目录树下的所有文件,并将其 MD5 散列值同之前保存的状态相比较找出任何增删改动作,最后把结果追加写入到指定的日志文档里去[^5]。 #### 4. 总结 Delta dump 不仅仅是理论概念,而是已经被广泛应用于各种领域的一项成熟技术。无论是操作系统层面还是应用程序内部都可以见到它的身影。理解其背后的运作机理有助于我们更好地运用这项工具解决实际问题。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

king_harry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值