rdiff-backup 配置参数详解
rdiff-backup 2.2.7 无集中配置文件的「动作+选项」模型详解:全局选项(筛选/压缩/远程/时间)与 v2 动作语法逐项实测,附新旧语法对照与生产配置模板。
rdiff-backup 配置参数详解
目标:讲清 rdiff-backup「无集中配置文件、按动作+选项组织」的配置模型,对常用全局选项(文件筛选、压缩、远程连接、时间与杂项)与 2.2 动作式语法逐项实测,并给出新旧语法对照。全部命令与回显在 Ubuntu 22.04 + rdiff-backup 2.2.7 实测照抄;安装步骤见 《Ubuntu 22.04 安装 rdiff-backup 指南》,工具定位见 《rdiff-backup 介绍与选型指南》。
一、环境信息
- 操作系统:Ubuntu 22.04.5 LTS(x86_64);本机(发起端)主机名
backup-server,远端(备份目标)remote-server(SSH 免密已打通,配置过程见安装篇第七章); - 软件版本:rdiff-backup 2.2.7(
rdiff-backup --version实测);Python 3.10.12; - 实验目录约定:源目录
/root/optest/src(含a.txt、b.log、big.bin、sub1/c1.conf、sub1/sub11/deep.txt、sub2/app.log),各选项演示的备份目录为/root/optest/bak-*;远程实验仓库root@remote-server::/root/optest-rs。
二、前置条件
- 两端已安装 rdiff-backup 2.2.7(跨机选项演示需要远端可连);
- 发起端对远端已配置 SSH 免密(
ssh -o BatchMode=yes root@remote-server可直接回显); - 熟悉本文实验用的源目录结构,可用
rdiff-backup list files <仓库>随时核对筛选结果。
三、参数查看与修改方式
3.1 配置模型:没有集中配置文件
rdiff-backup 没有类似 /etc/rdiff-backup.conf 的集中配置文件——所有配置都体现在「一次命令行调用」里:全局选项 → 动作 → 动作选项 → 位置参数。「持久化配置」靠两种载体:
- 调度单元文件:把完整命令写进 systemd timer 的
ExecStart=或 cron 条目(模板见第十章); - 选择规则文件:把 include/exclude 规则抽到 filelist 文本文件,命令行只留
--include-filelist/--exclude-filelist引用(见 5.3),规则文件本身用 git/配置管理维护。
3.2 两级帮助:--help 与 --help all
--help 只显示全局选项与动作清单;--help <动作> 显示该动作的专属选项;--help all 叠加显示所有动作的选项。顶层 usage 实测回显:
$ rdiff-backup --help
usage: rdiff-backup [-h] [--api-version API_VERSION]
[--current-time CURRENT_TIME] [--force]
[--fsync | --no-fsync] [--null-separator]
[--new | --no-new] [--chars-to-quote CHARS]
[--parsable-output] [--remote-schema REMOTE_SCHEMA]
[--remote-tempdir DIR_PATH]
[--ssh-compression | --no-ssh-compression]
[--tempdir DIR_PATH]
[--terminal-verbosity {0,1,2,3,4,5,6,7,8,9}]
[--use-compatible-timestamps] [-v {0,1,2,3,4,5,6,7,8,9}]
[-V]
{backup,calculate,compare,complete,info,list,regress,remove,restore,server,test,verify}
...
local/remote mirror and incremental backup
💡 说明:从 usage 即可确认 2.2.7 的全局选项集合与 12 个动作。注意
--null-separator、--remote-schema等都是全局选项,必须写在动作名之前——写在动作后会被当作动作选项而报错(实测见 5.4 与 FAQ Q1)。
rdiff-backup backup --help # 查看动作专属选项(示例)
rdiff-backup --help all # 全量帮助
rdiff-backup info # 查看运行时与 API 版本信息
四、参数总览
4.1 全局选项分类表(均为 usage 实测存在的 2.2.7 选项)
| 分类 | 选项 | 默认值/说明(实测依据:usage 帮助文本) |
|---|---|---|
| 文件筛选输入 | --null-separator | filelist 输入/输出用 \0 代替换行分隔 |
| 通用行为 | --force | 强制执行危险动作(如覆盖非空目标) |
| 通用行为 | --fsync / --no-fsync | 默认 --fsync(逐段刷盘更安全,稍慢) |
| 通用行为 | --current-time SECONDS | 伪造当前时间(测试用) |
| 通用行为 | --new / --no-new | 强制使用新参数解析(默认 False) |
| 通用行为 | --chars-to-quote CHARS | 目标文件系统不安全字符的转义集 |
| 输出控制 | --parsable-output | 机器可解析输出 |
| 输出控制 | -v {0..9} / --terminal-verbosity | 日志详细度 0–9 |
| 输出控制 | --use-compatible-timestamps | 兼容时间戳格式 |
| 远程连接 | --remote-schema SCHEMA | 自定义远端启动命令模板 |
| 远程连接 | --remote-tempdir DIR_PATH | 远端临时目录 |
| 远程连接 | --ssh-compression / --no-ssh-compression | 默认 --ssh-compression(ssh 加 -C) |
| 本地临时 | --tempdir DIR_PATH | 本地临时目录 |
| 兼容性 | --api-version VERSION | 强制指定 API 版本(默认 200,最高 201) |
💡 关键差异说明:老版本 1.x/2.0 的部分全局选项在 2.2.7 已移除或改名——
--no-atime、--override-remote-regexp、--ssh-no-compression在 2.2.7 均不存在(实测报错见 7.4 与 FAQ Q1),实际可用的是--no-ssh-compression等新拼写。
4.2 动作清单(12 个)
backup(备份)、restore(恢复)、list(查询 files/increments)、verify(校验)、compare(比对)、remove(删除 increments)、regress(仓库回退修复)、calculate(统计计算)、complete(补全)、info(运行信息)、server(服务端模式)、test(连接测试)。各动作的逐条实测见本专栏 《rdiff-backup 常用 CLI 命令详解》;本章 9.2 给出新旧语法对照。
五、文件筛选参数详解
5.1 --include/--exclude:顺序优先,首个匹配生效
rdiff-backup 的筛选规则按命令行出现顺序处理,一个文件命中第一条匹配规则即定去留;对目录的 exclude 会剪掉整棵子树,但若更早的 include 已命中其内部路径,则该内部路径仍会入库。
实测一(include 在前):sub1/sub11 先被 include,sub1 其余内容被 exclude:
rdiff-backup backup --include /root/optest/src/sub1/sub11 --exclude /root/optest/src/sub1 /root/optest/src /root/optest/bak-e2
rdiff-backup list files /root/optest/bak-e2
实测回显:
.
a.txt
b.log
big.bin
sub1
sub1/sub11
sub1/sub11/deep.txt
sub2
sub2/app.log
💡 说明:
deep.txt入库(include 先命中),c1.conf未入库(被后置 exclude 命中),其余文件不受影响——「首个匹配生效」得到实证。
实测二(include 在尾部触发保护):把 include 放在 exclude 之后:
rdiff-backup backup --exclude /root/optest/src/sub1 --include /root/optest/src/sub1/sub11 /root/optest/src /root/optest/bak-e1
实测回显:
Fatal Error: Last selection expression Command-line include glob: b'/root/optest/src/sub1/sub11'
only specifies that files be included. Because the default is to
include all files, the expression is redundant. Exiting because this
probably isn't what you meant
⚠️ 注意:最后一个筛选表达式不允许是纯 include——默认就是全包含,尾部 include 要么冗余要么笔误,rdiff-backup 直接拒跑保护。这也是「include 规则要放前面、exclude 收尾」的硬性写法依据。
5.2 glob 通配规则
--include/--exclude 接受 glob 表达式,** 可跨目录层级。实测排除所有 .log:
rdiff-backup backup --exclude "**/*.log" /root/optest/src /root/optest/bak-e3
rdiff-backup list files /root/optest/bak-e3
实测回显:
.
a.txt
big.bin
sub1
sub1/c1.conf
sub1/sub11
sub1/sub11/deep.txt
sub2
💡 说明:顶层
b.log与子目录sub2/app.log同时被排除,**/*.log的跨层匹配生效。常用 glob:*单层任意、**跨层任意、?单字符、[abc]字符集。
5.3 filelist 文件:--include-filelist / --exclude-filelist / --include-globbing-filelist
把规则抽成文件便于版本管理与复用。三种形态实测:
exclude-filelist(纯排除,最常用),规则文件每行一个路径:
printf "/root/optest/src/b.log\n/root/optest/src/sub2\n" > /root/optest/fl-exclude.txt
rdiff-backup backup --exclude-filelist /root/optest/fl-exclude.txt /root/optest/src /root/optest/bak-f1
rdiff-backup list files /root/optest/bak-f1
实测回显:
.
a.txt
big.bin
sub1
sub1/c1.conf
sub1/sub11
sub1/sub11/deep.txt
💡 说明:
b.log与整个sub2/(含app.log)被排除;排除目录时其子树整体不进备份。filelist 行也接受-/+前缀(实测-前缀行为与裸路径一致),但混合前缀的可读性差,建议一个文件只写一种语义。
include-filelist(指定入库白名单):单独使用会触发 5.1 的尾部 include 保护,必须后接一条 exclude 收尾,惯用组合是 --exclude "**":
printf "/root/optest/src/sub1/sub11\n" > /root/optest/fl-inc-plain.txt
rdiff-backup backup --include-filelist /root/optest/fl-inc-plain.txt --exclude "**" /root/optest/src /root/optest/bak-f7
rdiff-backup list files /root/optest/bak-f7
实测回显:
.
sub1
sub1/sub11
⚠️ 注意:filelist 行对目录是精确匹配、不自动递归——
deep.txt没进备份(被后置--exclude "**"命中)。要整目录递归入库,用 globbing 版本。
include-globbing-filelist(目录行自动展开为递归 glob):
printf "/root/optest/src/sub1\n" > /root/optest/fl-dir.txt
rdiff-backup backup --include-globbing-filelist /root/optest/fl-dir.txt --exclude "**" /root/optest/src /root/optest/bak-f9
rdiff-backup list files /root/optest/bak-f9
实测回显:
.
sub1
sub1/c1.conf
sub1/sub11
sub1/sub11/deep.txt
💡 说明:同样一行
/root/optest/src/sub1,globbing 版把整棵sub1树收进备份——这是白名单场景的推荐形态。对照实验:普通--include-filelist下同配置只有. sub1两行(实测),差异即「是否把目录行展开为dir/**」。
5.4 --null-separator:全局选项,必须放在动作前
路径含换行等特殊字符时,filelist 用 \0 分隔更安全。实测一(写在动作后,报错):
rdiff-backup backup --null-separator --exclude-filelist /root/optest/fl-null.txt /root/optest/src /root/optest/bak-f3
rdiff-backup: error: unrecognized arguments: --null-separator
实测二(写在动作前,正常执行):
printf "/root/optest/src/b.log\0/root/optest/src/sub2\0" > /root/optest/fl-null.txt
rdiff-backup --null-separator backup --exclude-filelist /root/optest/fl-null.txt /root/optest/src /root/optest/bak-f6
rdiff-backup list files /root/optest/bak-f6
实测回显:
.
a.txt
big.bin
sub1
sub1/c1.conf
sub1/sub11
sub1/sub11/deep.txt
💡 说明:
\0分隔的两个排除路径被正确解析(b.log、sub2/均未入库),效果与换行分隔一致。
六、压缩与性能参数
6.1 --no-compression:关闭增量文件 gzip 压缩
默认情况下 rdiff-backup 对文本类增量做 gzip 压缩(增量文件带 .gz 后缀)。对照实验——同一数据源分别以默认压缩与 --no-compression 各做两轮备份:
rdiff-backup backup /root/optest/src /root/optest/bak-def
echo "backup-a" >> /root/optest/src/a.txt && sleep 2
rdiff-backup backup /root/optest/src /root/optest/bak-def
ls /root/optest/bak-def/rdiff-backup-data/increments/
rdiff-backup backup --no-compression /root/optest/src /root/optest/bak-nc
echo "backup-b" >> /root/optest/src/a.txt && sleep 2
rdiff-backup backup --no-compression /root/optest/src /root/optest/bak-nc
ls /root/optest/bak-nc/rdiff-backup-data/increments/
实测回显:
a.txt.2026-10-22T05:55:57Z.diff.gz
sub1
sub2
a.txt.2026-10-22T05:55:57Z.diff
sub1
sub2
💡 说明:默认仓库的
a.txt反向增量是a.txt.<时间戳>Z.diff.gz,--no-compression仓库则为a.txt.<时间戳>Z.diff(无.gz)。镜像本体始终不压缩,压缩只作用于rdiff-backup-data/下的增量与元数据。压缩策略可用--not-compressed-regexp REGEXP按正则排除(如已压缩的.jpg/.gz),属动作级选项(backup --help可查)。
⚠️ 注意:实验中两次备份间隔若不足 1 秒,会实测报错
ERROR: The last backup is not in the past. Aborting.(rdiff-backup 要求后一次备份时间严格晚于前一次),脚本里连续两次备份需sleep 1以上或用--current-time错开(见 FAQ Q3)。
6.2 --fsync / --no-fsync
默认 --fsync:每写一段就刷盘,掉电最安全但更慢;--no-fsync 关闭刷盘提速,官方帮助注明「faster but can be dangerous」。实测:
rdiff-backup --no-fsync backup /root/optest/src /root/optest/bak-nfs2
实测回显(与普通备份一致,仅省去刷盘等待):
WARNING: Server will be called with deprecated command line interface to guarantee compatibility. It might lead to a deprecation warning from newer rdiff-backup versions. Use '--api-version 201' (or higher) to avoid it.
NOTE: Starting mirror from source path /root/optest/src to destination path /root/optest/bak-nfs2
⚠️ 注意:
--no-fsync只建议在性能压测或可丢弃数据场景使用;生产备份保持默认--fsync。
6.3 --tempdir 与 --remote-tempdir
--tempdir 指定本地临时目录;--remote-tempdir 指定远端临时目录(大文件差分需要在远端落临时文件)。--remote-tempdir 指向的目录必须已存在,否则实测报错并暴露实际下发的远端命令:
rdiff-backup --remote-tempdir /root/rdtmp backup /root/optest/src root@remote-server::/root/optest-rs
远端无 /root/rdtmp 时的实测回显:
ERROR: Temporary directory '/root/rdtmp' doesn't exist.
ERROR: Action server failed on step pre_check
ERROR: Couldn't start up the remote connection by executing 'ssh -C root@remote-server rdiff-backup --tempdir=/root/rdtmp --terminal-verbosity 3 --server'
due to exception 'Truncated header <b''> (problem probably originated remotely)'.
在远端 mkdir -p /root/rdtmp 后重跑,实测成功:
NOTE: Starting increment operation from source path /root/optest/src to destination path /root/optest-rs
💡 说明:报错回显中的
ssh -C root@remote-server rdiff-backup --tempdir=/root/rdtmp --terminal-verbosity 3 --server正是 rdiff-backup 实际执行的远端启动命令(默认 schema),排障时可直接手工执行该命令定位问题。
七、远程连接参数
7.1 远端三段式语法与 --remote-schema
跨机目标写作 [USER@]SERVER::PATH。默认以 ssh -C <host> rdiff-backup --server 在远端拉起服务进程;--remote-schema 可整体替换该模板,%s 是主机占位符。实测自定义 schema(加 -C 压缩并显式指定服务端命令):
rdiff-backup --remote-schema "ssh -C %s rdiff-backup --server" backup /root/optest/src root@remote-server::/root/optest-rs
ssh root@remote-server "ls /root/optest-rs | head -4"
实测回显:
a.txt
b.log
big.bin
rdiff-backup-data
💡 说明:自定义 schema 典型用途:非标准 ssh 端口(
ssh -p 2222 %s rdiff-backup --server)、指定私钥(ssh -i /root/backup_key %s ...)、经跳板机(ssh -J jump %s ...)。schema 里必须保留rdiff-backup --server(或老版rdiff-backup --server等价形态),否则远端无法应答协议。
7.2 --no-ssh-compression:关闭 ssh 传输压缩
默认 schema 带 -C(ssh 压缩)。备份数据本身已压缩(镜像文件、.gz 增量)时,传输层再压缩收益低还耗 CPU,可用 --no-ssh-compression 去掉 -C。用 -v5 观察实际远端命令对照:
rdiff-backup -v5 --no-ssh-compression backup /root/optest/src root@remote-server::/root/optest-rs
实测回显(日志节选):
* Executing remote command ssh root@remote-server rdiff-backup --terminal-verbosity 5 --server
* API version agreed to be 200 with command b'ssh root@remote-server rdiff-backup --terminal-verbosity 5 --server'
💡 说明:对比默认情况——
rdiff-backup test动作实测打印的默认启动命令是b'ssh -C root@remote-server rdiff-backup --terminal-verbosity 3 --server'(含-C),加--no-ssh-compression后-C消失。2.2.7 的选项拼写是--no-ssh-compression(老文档中的--ssh-no-compression写法已不存在,实测unrecognized arguments)。
7.3 test 动作:连通性自检
rdiff-backup test root@remote-server::/root/optest-rs
实测回显(目标路径存在时):
Testing server started by: b'ssh -C root@remote-server rdiff-backup --terminal-verbosity 3 --server'
- Server OK
目标路径不存在时实测报错(便于排障对照):
- Server tests failed due to [Errno 2] No such file or directory: b'/root/optest-remote'
ERROR: Action test failed on step run
7.4 已移除的远程安全选项:--override-remote-regexp
1.x/2.0 时代的 --override-remote-regexp(放宽远端路径正则校验)在 2.2.7 已移除,实测:
rdiff-backup --override-remote-regexp ".*" backup /root/optest/src root@remote-server::/root/optest-rs
rdiff-backup: error: unrecognized arguments: --override-remote-regexp
💡 说明:2.2.x 改由动作解析器直接校验 location 合法性,老教程里出现该选项的一律按已废弃处理。
八、时间与杂项全局参数
8.1 --current-time:伪造当前时间(测试利器)
rdiff-backup --current-time 1791740012 backup /root/optest/src /root/optest/bak-ct
rdiff-backup list increments /root/optest/bak-ct
实测回显:
Found 0 increments:
Current mirror: Sun Oct 11 17:33:32 2026
💡 说明:仓库时间线被伪造到参数指定的 Unix 时间(1791740012),镜像时间戳随之变化。用途:把多次实验备份错开到不同「历史时点」,模拟长期增量链(本文 6.1 与命令篇的时点恢复实验即用到该技巧)。
8.2 --api-version 201:消除 deprecation 警告
2.2.x 默认 api-version 200,每次备份会打印一条「deprecated command line interface」WARNING(见 6.2 实测回显)。改用 201 后实测:
rdiff-backup --api-version 201 backup /root/optest/src /root/optest/bak-api201
实测回显(WARNING 消失,NOTE 格式微调):
NOTE: Starting backup operation from source path /root/optest/src to
destination path /root/optest/bak-api201
8.3 --parsable-output:机器可解析输出
rdiff-backup --parsable-output list increments /root/optest/bak-ct
实测回显:
1791740012 directory
💡 说明:人读格式(
increments.2026-...Z.dir Sun Oct 11 ...)变为「时间戳 类型」两列,供脚本 awk/jq 处理。同类还有-v{0..9}控制日志量(0 静默、9 最详细)、--use-compatible-timestamps用YYYY-MM-DDTHH:MM:SS+00:00风格时间戳。
8.4 关于 --no-atime:2.2.7 已无此选项
老教程常提 --no-atime(读取文件后还原 atime)。实测 2.2.7 的新旧两种写法均不存在:
rdiff-backup --no-atime backup /root/optest/src /root/optest/bak-at
rdiff-backup --no-atime /root/optest/src /root/optest/bak-atold
两条命令的实测回显都是 usage+报错(节选):
rdiff-backup: error: unrecognized arguments: --no-atime
且 --help all 全文检索 atime 零命中——2.2.7 中已无任何 atime 相关选项,老版本遗留的 --compare-verify-atime 亦已移除,实测同样报 usage+错误:
rdiff-backup --compare-verify-atime /root/dtest/src /root/dtest/bak
rdiff-backup: error: unrecognized arguments: --compare-verify-atime
现代文件系统普遍以 relatime 挂载,读文件不再每次更新 atime,这类选项的实际价值本已消失;比对统一使用 compare --method ...(逐项实测见本专栏 《rdiff-backup 常用 CLI 命令详解》 7.3 节)。
九、v2 动作语法与新旧对照
9.1 两套语法
- 旧语法(≤2.0,2.2 仍兼容):全局选项直接携带语义,如
rdiff-backup --list-increments <仓库>、rdiff-backup --restore-as-of now <仓库> <目标>; - 新语法(2.2 起):
rdiff-backup <动作> [动作选项] <位置参数>,如rdiff-backup list increments <仓库>。
旧语法调用时每次会多打印一条提示(实测节选):
WARNING: this command line interface is deprecated and will disappear, start using the new one as described with '--new --help'.
9.2 新旧语法对照表(右列命令均实测通过)
| 操作 | 旧语法(实测回显正常) | 新语法 2.2(实测回显正常) |
|---|---|---|
| 备份 | rdiff-backup /root/optest/src /root/optest/bak-oldsyn | rdiff-backup backup /root/optest/src /root/optest/bak-oldsyn |
| 列增量 | rdiff-backup --list-increments /root/optest/bak-oldsyn | rdiff-backup list increments /root/optest/bak-oldsyn |
| 列变更文件 | rdiff-backup --list-changed-since 1D /root/optest/bak-oldsyn | rdiff-backup list files --changed-since 1D /root/optest/bak-oldsyn |
| 恢复 | rdiff-backup --restore-as-of now /root/optest/bak-oldsyn/a.txt /root/optest/old-restored.txt | rdiff-backup restore --at now /root/optest/bak-oldsyn/a.txt /root/optest/old-restored.txt |
| 比对 | rdiff-backup --compare /root/optest/src /root/optest/bak-oldsyn | rdiff-backup compare /root/optest/src /root/optest/bak-oldsyn |
| 校验 | rdiff-backup --verify /root/optest/bak-oldsyn | rdiff-backup verify /root/optest/bak-oldsyn |
| 清理增量 | rdiff-backup --remove-older-than 1B --force /root/optest/bak-oldsyn | rdiff-backup remove increments --older-than 1B /root/optest/bak-oldsyn |
旧语法代表动作实测回显(其余见对应行):
$ rdiff-backup --list-increments /root/optest/bak-oldsyn
Found 0 increments:
Current mirror: Thu Oct 22 05:58:54 2026
$ rdiff-backup --compare /root/optest/src /root/optest/bak-oldsyn
NOTE: No changes found. Directory matches archive data.
$ rdiff-backup --verify /root/optest/bak-oldsyn
NOTE: All files verified successfully
$ rdiff-backup --remove-older-than 1B --force /root/optest/bak-oldsyn
NOTE: No increments older than Thu Oct 22 05:58:54 2026 found, exiting.
9.3 旧版本不识别新语法(版本混部排障依据)
在 Ubuntu 22.04 仓库版 rdiff-backup 2.0.5 上执行新语法 rdiff-backup backup ...,实测报错:
Fatal Error: Switches missing or wrong number of arguments
See the rdiff-backup manual page for more information.
⚠️ 注意:双机部署时若一端 2.0.5、一端 2.2.x,脚本里写新语法就会在老版本端报上述错误;先
rdiff-backup --version核对两端版本(混装冲突的排查见安装篇 FAQ)。
9.4 --new:强制新参数解析
个别全局选项(如 --remote-tempdir)会把命令行拖回旧式解析路径,导致同时打印两条 WARNING(实测节选,见 6.3):
WARNING: Server will be called with deprecated command line interface to guarantee compatibility. ...
WARNING: this command line interface is deprecated and will disappear, start using the new one as described with '--new --help'.
在新语法前加 --new 可强制按新解析器处理并消除第二条警告:rdiff-backup --new --remote-tempdir /root/rdtmp backup ...(远端临时目录需先创建,见 6.3)。
十、生产配置模板
适用场景:2C4G 及以上通用服务器、备份盘/备份机容量 ≥ 源数据 1.5 倍、每日凌晨增量备份的常规文件服务器。要点:规则抽到 filelist 文件;日志落文件;用 --api-version 201 消警告。
/etc/rdiff-backup/include.fl(白名单示例,globbing 版自动递归目录):
+ /var/www
+ /etc
+ /home
- /var/cache/**
- /tmp/**
- **
/etc/systemd/system/rdiff-backup-daily.service:
[Unit]
Description=rdiff-backup daily job (whitelist filelist, remote target)
[Service]
Type=oneshot
ExecStart=/usr/local/bin/rdiff-backup --new --api-version 201 --include-globbing-filelist /etc/rdiff-backup/include.fl --remote-schema "ssh -C %s rdiff-backup --server" backup / root@remote-server::/backups/main
/etc/systemd/system/rdiff-backup-daily.timer:
[Unit]
Description=Run rdiff-backup-daily at 02:30
[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true
[Install]
WantedBy=timers.target
💡 配置说明:
include.fl采用 globbing filelist 的+/-行内混合语法(globbing 版按行序匹配,- **收尾排除其余);--remote-schema显式写全远端命令便于审计;保留增量时长由独立的remove increments --older-than 3M维护任务控制(命令见命令篇)。启用:systemctl daemon-reload && systemctl enable --now rdiff-backup-daily.timer,验证systemctl list-timers rdiff-backup-daily.timer(启用回显与验证方法同安装篇第九章)。
十一、常见问题(FAQ)
Q1:报 unrecognized arguments: --null-separator(或 --no-atime、--override-remote-regexp)?
两类原因:其一,--null-separator 是全局选项,必须写在动作名之前(正确:rdiff-backup --null-separator backup ...);其二,--no-atime、--override-remote-regexp、--ssh-no-compression 在 2.2.7 已移除/改名(分别见 8.4、7.4、7.2 的实测依据),老教程选项先经 rdiff-backup --help all | grep <选项> 核实。
Q2:报 Fatal Error: Last selection expression ... only specifies that files be included. ...?
最后一个筛选表达式是纯 include 触发的冗余保护(5.1/5.3 实测)。修法:include 规则后补一条 exclude 收尾——白名单场景用 --include-globbing-filelist <文件> --exclude "**" 组合。
Q3:连续两次备份报 ERROR: The last backup is not in the past. Aborting.?
同一秒内两次备份被拒(时间戳必须严格递增)。脚本中两次备份间 sleep 1 以上,或用 --current-time 错开(8.1)。
Q4:--remote-tempdir 报 ERROR: Temporary directory '...' doesn't exist. 并提示 Couldn't start up the remote connection?
远端临时目录需预先创建:ssh root@remote-server "mkdir -p /root/rdtmp" 后重跑(6.3 实测闭环)。报错回显中的 ssh -C ... --server 是实际下发的远端命令,可手工执行定位。
Q5:/usr/bin/rdiff-backup 报 AttributeError: ... has no attribute 'error_check_Main'?
apt(2.0.5)与 pip(2.2.x)混装冲突,模块搜索路径被 pip 版本抢占。排查与二选一清理步骤见 《Ubuntu 22.04 安装 rdiff-backup 指南》FAQ Q1。
十二、参考链接
- man 手册(选项权威定义):https://rdiff-backup.net/rdiff-backup.1.html
- 官方使用示例:https://rdiff-backup.net/examples.html
- 1.x → 2.x 迁移(语法变更背景):https://rdiff-backup.net/migration.html
- Client-Server API 文档:https://rdiff-backup.net/api
- 站内相关篇目:《rdiff-backup 介绍与选型指南》、《Ubuntu 22.04 安装 rdiff-backup 指南》