Ubuntu 22.04 安装 Duplicity 指南

Ubuntu 22.04 从零安装 Duplicity 的四种方案实测:apt 0.8.21、官方 PPA 3.2.2、pip 源码包与 snap,含 GPG 密钥准备、首次备份验证、setuptools 排障、升级降级与卸载清理

Duplicity备份恢复2026/10/22

Ubuntu 22.04 安装 Duplicity 指南

目标:在 Ubuntu 22.04 服务器上从零安装 Duplicity 加密增量备份工具,覆盖四种安装方案(Ubuntu 官方仓库 apt、官方 PPA、pip 源码包、snap),并完成 GPG 密钥准备、首次加密备份验证、升级/降级/多版本管理与卸载清理。文中所有命令与回显均在 Ubuntu 22.04 服务器实测照抄。组件定位与选型背景见 《Duplicity 介绍与选型指南》。

一、环境信息

  • 操作系统:Ubuntu 22.04(jammy),x86_64
  • Python:Python 3.10.12(系统自带)
  • 实测版本:
    • Ubuntu 官方仓库 apt 方案:duplicity 0.8.21(0.8.21-1build1)
    • 官方 PPA 方案:duplicity 3.2.2(3.2.2-ppa202610141802~ubuntu22.04.1)
    • pip 源码包方案:duplicity 3.2.2(官方最新稳定版,版本自报日期 October 14, 2026)
  • GnuPG:gpg (GnuPG) 2.2.27
  • 网络要求:apt/PPA 方案访问 archive.ubuntu.com 与 ppa.launchpadcontent.net;pip 方案需访问 gitlab.com 下载源码包
  • 实验目录约定:被备份数据 /srv/data,备份目标 /srv/backups

二、前置条件

2.1 系统依赖

apt 方案所需的系统库(librsync、gnupg、python3)Ubuntu 22.04 均可由 apt 一并解决;pip 方案需要额外安装编译工具链与 librsync 开发头文件。开始前先更新索引:

apt-get update -qq

实测说明:-qq 为静默模式,无输出即代表索引同步成功(若报错会直接打印错误行)。

2.2 时间确认

备份工具对时间敏感(备份集时间戳、-t 时间点恢复都按 UTC 时间命名与比对),开始前确认服务器时间与时区正确;同时确认备份目标盘(如 /srv 所在分区)剩余空间满足预估数据量。

date

实测回显:

Wed Oct 21 17:55:40 UTC 2026

三、版本选型说明

Ubuntu 22.04 各安装渠道的版本差异实测如下(apt-cache 实测回显,见 5.2 节):

渠道版本包形态适用判断
Ubuntu jammy 官方仓库0.8.21deb,含 rdiffdir追求与发行版同步更新、功能够用
官方 PPA duplicity-release-git3.2.2(2026-10-14 构建)deb,按月跟随 git 稳定线想要 deb 管理的最新稳定版
GitLab 源码 + pip3.2.2Python 包,装到 /usr/local需要 3.2.2 且不被 deb 体系覆盖
snap(stable/edge)跟随官方构建snap 包已启用 snapd 的系统

关键差异:0.8.21 与 3.2.2 相差一个大版本周期,3.x 的 --help 结构、选项默认值均有变化(如 3.x 新增 --help-backup、--help-urls、--concurrency、--config-dir 等选项)。官方明确警告:从发行版仓库版本切换到 tarball/pip 版本(或反向切换)时,必须先彻底卸载(purge)原版本,否则两者安装路径不同会产生「混乱的结果」(来源:duplicity.us 官网 Download 节 Warning,查询日期 2026-10-22)。

本文建议:无特殊约束选 PPA 方案(方案 B),deb 体系管理 + 最新稳定版两全;已被管控只能用系统源的选方案 A;需要与 Python 项目共存或部署在无 root 的 venv 环境选方案 C。

四、方案 A:Ubuntu 官方仓库安装(apt)

4.1 方案说明

Ubuntu 22.04 官方仓库收录 duplicity 0.8.21,一条命令完成安装,自动解决 librsync、gnupg、Python 依赖。适合内网源同步、版本稳定优先的环境。

4.2 安装步骤

apt-get install -y duplicity

实测回显(输出节选,实测末尾):

Processing triggers for ca-certificates (20260816ubuntu0.22.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
Setting up duplicity (0.8.21-1build1) ...

4.3 验证安装

duplicity --version

实测回显:

duplicity 0.8.21

查看安装布局与依赖清单:

dpkg -L duplicity | grep -E 'bin/|man1'
dpkg -s duplicity | grep -E '^(Package|Version|Depends|Installed-Size)'

实测回显:

/usr/bin/duplicity
/usr/bin/rdiffdir
/usr/share/man/man1
/usr/share/man/man1/duplicity.1.gz
/usr/share/man/man1/rdiffdir.1.gz
Package: duplicity
Installed-Size: 1288
Version: 0.8.21-1build1
Depends: libc6 (>= 2.4), librsync2 (>= 1.0.0), python3 (<< 3.11), python3 (>= 3.10~), python3-fasteners, python3-future, python3.10:any, python3:any (>= 3.7~), python3-lockfile, gnupg | gnupg1

💡 说明:apt 版自带 rdiffdir 伴生工具(目录级差量工具)与 man 手册;依赖项中 librsync2 提供增量算法、gnupg 提供加密能力。

GnuPG 环境随依赖自动就绪:

gpg --version | head -3

实测回显:

gpg (GnuPG) 2.2.27
libgcrypt 1.9.4
Copyright (C) 2021 Free Software Foundation, Inc.

五、方案 B:官方 PPA 安装(duplicity-release-git)

5.1 方案说明

Duplicity 官方团队在 Launchpad 维护了两个 PPA:duplicity-release-git(稳定线,每次官方 release 构建)与 duplicity-develop(开发线)。PPA 版以 deb 形态提供 3.2.2 最新稳定版,是「版本新 + 包管理」两全的选择(PPA 地址来源:duplicity.us 官网 Download 节,查询日期 2026-10-22)。

5.2 添加 PPA 与版本确认

add-apt-repository -y ppa:duplicity-team/duplicity-release-git

实测回显(输出节选,实测末尾):

More info: https://launchpad.net/~duplicity-team/+archive/ubuntu/duplicity-release-git
Adding repository.
Adding deb entry to /etc/apt/sources.list.d/duplicity-team-ubuntu-duplicity-release-git-jammy.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/duplicity-team-ubuntu-duplicity-release-git-jammy.list
Adding key to /etc/apt/trusted.gpg.d/duplicity-team-ubuntu-duplicity-release-git.gpg with fingerprint 4BC056F4C31D7D82488C3AA9EA0A88258CB19A4A

刷新索引并确认候选版本:

apt-get update -qq
apt-cache policy duplicity

实测回显:

duplicity:
  Installed: (none)
  Candidate: 3.2.2-ppa202610141802~ubuntu22.04.1
  Version table:
     3.2.2-ppa202610141802~ubuntu22.04.1 500
        500 https://ppa.launchpadcontent.net/duplicity-team/duplicity-release-git/ubuntu jammy/main amd64 Packages
     0.8.21-1build1 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages

💡 说明:PPA 优先级同为 500 时,apt 按 version string 排序,3.2.2 优于 0.8.21 成为候选版本,说明 PPA 生效。

5.3 安装

apt-get install -y duplicity

首次安装时的实测报错(Launchpad CDN 瞬时 503):

E: Failed to fetch https://ppa.launchpadcontent.net/duplicity-team/duplicity-release-git/ubuntu/pool/main/d/duplicity/duplicity_3.2.2-ppa202610141802%7eubuntu22.04.1_amd64.deb  503  Service Unavailable [IP: 185.125.189.188 443]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

⚠️ 排障:launchpadcontent CDN 偶发 503 属瞬时故障,用 --fix-missing 重试即可续传:

apt-get install -y --fix-missing duplicity

实测回显(输出节选,实测末尾):

Setting up libxext6:amd64 (2:1.3.4-1build1) ...
Setting up xauth (1:1.1-1build2) ...
Processing triggers for libc-bin (2.35-0ubuntu3.15) ...

5.4 验证安装

duplicity --version

实测回显:

duplicity 3.2.2 October 14, 2026

PPA 版依赖与体量:

dpkg -s duplicity | grep -E '^(Version|Depends|Installed-Size)'

实测回显:

Version: 3.2.2-ppa202610141802~ubuntu22.04.1
Depends: python3 (<< 3.11), python3 (>= 3.10~), python3:any (>= 3.1~), libc6 (>= 2.4), librsync2 (>= 1.0.0), gnupg, lftp, python3-fasteners, python3-pexpect
Installed-Size: 2492

💡 说明:3.x 的 PPA 包依赖 lftp(提供 ftp/fish 类后端传输)与 python3-pexpect(ssh pexpect 后端),比 0.8.21 的依赖列表多了这两项、少了 python3-future。

六、方案 C:pip 安装官方最新源码包

6.1 方案说明

GitLab rel.3.2.2 tag 提供源码包,pip 安装到 /usr/local,不与 deb 体系冲突(但仍建议先卸载系统版,见官网 Warning)。该方案也适用于 venv 隔离部署。

6.2 安装编译依赖

pip 构建需编译 C 扩展(_librsync),先装工具链与头文件:

apt-get install -y python3-pip python3-dev build-essential librsync-dev libssl-dev libffi-dev gettext

实测回显(输出节选,实测末尾):

0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

再装下载与 GPG 工具(Ubuntu 22.04 最小安装不带 wget):

apt-get install -y wget curl gnupg

实测回显(输出节选):

Setting up wget (1.21.2-2ubuntu1.5) ...

6.3 下载官方源码包

cd /root/dl
wget https://gitlab.com/duplicity/duplicity/-/archive/rel.3.2.2/duplicity-rel.3.2.2.tar.gz
tar xzf duplicity-rel.3.2.2.tar.gz

实测回显(输出节选,实测首尾):

--2026-10-21 17:55:15--  https://gitlab.com/duplicity/duplicity/-/archive/rel.3.2.2/duplicity-rel.3.2.2.tar.gz
Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9
Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/octet-stream]
Saving to: 'duplicity-rel.3.2.2.tar.gz'
...(中间为下载进度行)
2026-10-21 17:55:17 (1.11 MB/s) - 'duplicity-rel.3.2.2.tar.gz' saved [1626141]

确认包体并解压:

ls -la duplicity-rel.3.2.2.tar.gz

实测回显:

-rw-r--r-- 1 root root 1626141 Oct 21 17:55 duplicity-rel.3.2.2.tar.gz

6.4 pip 安装与排障实录

直接安装会因系统 setuptools 过旧而失败:

pip3 install ./duplicity-rel.3.2.2

实测报错(输出节选):

  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  │ Traceback (most recent call last):
  │   File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
  │     main()
  │   ...(省略中间帧)
  │   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2487, in require
  │     items = working_set.resolve(reqs, env, installer, extras=self.extras)
  │   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2487, in resolve
  │     raise VersionConflict(dist, req).with_context(dependent_req)
  │ pkg_resources.VersionConflict: (setuptools 59.6.0 (/usr/lib/python3/dist-packages), Requirement.parse('setuptools>=69.0'))

⚠️ 排障:报错末行即根因——Duplicity 3.2.2 的构建要求 setuptools>=69.0,而 Ubuntu 22.04 系统 pip 自带 setuptools 59.6.0。先升级 pip 与 setuptools 再装:

pip3 install -U pip setuptools

实测回显(输出节选):

Successfully installed pip-25.2 setuptools-80.9.0

重新安装:

pip3 install ./duplicity-rel.3.2.2

实测回显(输出节选,实测末尾):

Successfully installed Babel-2.18.0 Jinja2-3.1.6 ... boto3-1.43.116 ... cryptography-43.0.3 duplicity-3.2.2 fasteners-0.20 ... paramiko-5.1.0 ... python-swiftclient-4.11.0 ...

(依赖较多,共 100+ 个包,节选关键项)

6.5 验证安装

which duplicity
duplicity --version
pip3 show duplicity | grep -E 'Version|Location'
python3 --version

实测回显:

/usr/local/bin/duplicity
duplicity 3.2.2 October 14, 2026
Version: 3.2.2
Location: /usr/local/lib/python3.10/dist-packages
Python 3.10.12

💡 说明:pip 版把可执行入口装到 /usr/local/bin/duplicity,包体在 /usr/local/lib/python3.10/dist-packages/duplicity/(内含编译好的 _librsync C 扩展)。与 apt 版不同,3.2.2 的 pip 安装不提供 rdiffdir 命令(ls /usr/local/bin 无 rdiffdir,实测确认);0.8.x 的 apt 包则带 /usr/bin/rdiffdir。

七、方案 D:snap 安装(需 systemd 的真机)

官方构建了 stable 与 edge 两个 snap 通道(来源:duplicity.us 官网 Download 节,查询日期 2026-10-22):

sudo snap install duplicity --classic          # stable 稳定通道
sudo snap install duplicity --classic --edge   # edge 最新构建

⚠️ 注意:snap 依赖 snapd 服务(需要 systemd 的 Linux 真机环境),安装与刷新由 snapd 自动管理,适合已标准化使用 snap 的桌面/服务器;server 场景下 deb(方案 A/B)与 pip(方案 C)的可控性通常更好。

八、多方案对比与选择建议

维度A:apt 官方仓库B:官方 PPAC:pip 源码包D:snap
版本0.8.213.2.2(10-14 构建)3.2.2跟随官方构建
安装位置/usr/bin/usr/bin/usr/local/bin/snap/bin
是否需联网是(archive.ubuntu.com)是(launchpad)是(gitlab.com + PyPI)是(snapcraft.io)
包管理器aptaptpipsnap
附带 rdiffdir有无(3.x 起移除)无无
升级方式apt upgradeapt upgrade(随 PPA)pip install -U / 重装snap refresh
适合人群求稳、内网源版本新 + deb 管理venv/隔离需求snap 标准化环境

选择建议:可联网生产服务器首选方案 B(版本新且归 apt 管);严格内网用方案 A 接受 0.8.21;有 Python 环境隔离要求或需要精确复现官方源码版本用方案 C;snap 适合桌面 Ubuntu。

九、GPG 密钥准备与首次备份验证

无论哪种方案,加密备份都需要一把 GPG 密钥(或至少一个强口令)。以下在方案 A 的 0.8.21 环境实测,方案 B/C 完全一致。

9.1 生成加密密钥

演示用测试密钥,--quick-gen-key 批量模式生成 RSA2048 加密钥,口令 q1w2e3r4(生产环境请用 gpg --full-generate-key 交互生成 RSA4096 并妥善保管口令):

gpg --batch --pinentry-mode loopback --passphrase 'q1w2e3r4' \
  --quick-gen-key "Backup Demo <root@backup.local>" rsa2048 encr never

实测回显(输出节选,实测末尾):

gpg: key 2786982B41DDD4A7 marked as ultimately trusted
gpg: directory '/root/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/root/.gnupg/openpgp-revocs.d/3712F37EFEC688C984FAC7A72786982B41DDD4A7.rev'
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u

查看密钥指纹(后续 --encrypt-key 参数会用到):

gpg --list-keys

实测回显:

/root/.gnupg/pubring.kbx
------------------------
pub   rsa2048 2026-10-21 [CE]
      3712F37EFEC688C984FAC7A72786982B41DDD4A7
uid           [ultimate] Backup Demo <root@backup.local>

9.2 首次全量备份验证

准备测试数据并执行首次加密全量备份到本地 file 后端:

mkdir -p /srv/data/docs /srv/data/photos /srv/backups
echo "hello duplicity v1" > /srv/data/docs/readme.txt
dd if=/dev/urandom of=/srv/data/photos/img1.bin bs=1K count=256 2>/dev/null
PASSPHRASE='q1w2e3r4' duplicity full /srv/data file:///srv/backups

实测回显(输出节选,实测末尾统计段):

Local and Remote metadata are synchronized, no sync needed.
Last full backup date: none
--------------[ Backup Statistics ]--------------
StartTime 1792604537.79 (Wed Oct 21 17:42:17 2026)
EndTime 1792604537.94 (Wed Oct 21 17:42:17 2026)
ElapsedTime 0.15 (0.15 seconds)
SourceFiles 6
SourceFileSize 536595 (524 KB)
NewFiles 6
NewFileSize 536595 (524 KB)
DeletedFiles 0
ChangedFiles 0
ChangedFileSize 0 (0 bytes)
ChangedDeltaSize 0 (0 bytes)
DeltaEntries 6
RawDeltaSize 524307 (512 KB)
TotalDestinationSizeChange 526869 (515 KB)
Errors 0
-------------------------------------------------

查看备份产物(加密卷三件套):

ls -la /srv/backups

实测回显:

total 536
drwxr-xr-x 2 root root   4096 Oct 21 17:42 .
drwxr-xr-x 4 root root   4096 Oct 21 17:42 ..
-rw-r--r-- 1 root root   6624 Oct 21 17:42 duplicity-full-signatures.20261021T174217Z.sigtar.gpg
-rw-r--r-- 1 root root    255 Oct 21 17:42 duplicity-full.20261021T174217Z.manifest.gpg
-rw-r--r-- 1 root root 526869 Oct 21 17:42 duplicity-full.20261021T174217Z.vol1.difftar.gpg

💡 说明:产物以 duplicity-full.<UTC时间戳> 命名,.gpg 后缀代表已加密;manifest 是清单、sigtar 是签名档、difftar 是数据卷。备份命令、增量备份与恢复的完整实测见 《Duplicity 常用 CLI 命令详解》;环境变量与命令选项体系见 《Duplicity 配置参数详解》。

十、升级、降级与多版本管理

10.1 apt/PPA 版升级与锁版本

apt-get update && apt-get upgrade duplicity   # 跟随源升级
apt-mark hold duplicity                        # 锁定版本不随系统升级
apt-mark unhold duplicity                      # 解锁

PPA 用户提供两个通道:duplicity-release-git(稳定)与 duplicity-develop(开发线),切换前先 purge 当前版本。

10.2 pip 版多版本

pip 体系可用版本号精确安装与回退:

pip3 install duplicity==3.2.1   # 回退到 PyPI 上的上一稳定版
pip3 install -U duplicity       # 升级到 PyPI 最新

需要隔离时用 venv:python3 -m venv /opt/duplicity-venv && /opt/duplicity-venv/bin/pip install duplicity,可与其他版本完全共存。

10.3 版本切换的强制要求

官网 Warning 明确(来源:duplicity.us,查询日期 2026-10-22):在发行版仓库版本与 tarball/pip 版本之间切换时,务必先 remove/purge 发行版版本,否则两套安装路径会导致「混乱的结果」。实操顺序:apt-get remove --purge -y duplicity → 确认 which duplicity 无残留 → 再装目标版本。

十一、常见问题(FAQ)

Q1:apt 安装 PPA 包时报 E: Failed to fetch ... 503 Service Unavailable? Launchpad CDN(launchpadcontent.net)瞬时故障,非配置问题。重试 apt-get install -y --fix-missing duplicity 即可续传(本文 5.3 节实测复现并解决)。若持续 503,可在另一时段重试或改走方案 C。

Q2:pip 安装报 pkg_resources.VersionConflict: (setuptools 59.6.0 ..., Requirement.parse('setuptools>=69.0'))? Ubuntu 22.04 系统 pip 自带的 setuptools 59.6.0 不满足 Duplicity 3.2.2 构建要求(≥69.0)。执行 pip3 install -U pip setuptools 后重装(本文 6.4 节实测复现并解决)。

Q3:装了 pip 版又装了 apt 版,命令行为诡异? 两套版本安装路径不同(/usr/bin 与 /usr/local/bin),PATH 命中的哪个取决于顺序。按官网 Warning 与 10.3 节处理:purge 一方,which duplicity 确认唯一。

Q4:wget: command not found? Ubuntu 22.04 最小安装不带 wget/curl,apt-get install -y wget curl gnupg 即可(本文 6.2 节实测)。

Q5:备份时提示 gpg: decryption failed: Bad session key? PASSPHRASE 与加密时用的口令不一致。核对备份目标首次备份时的口令;已实测该错误的标准回显为:

GPGError: GPG Failed, see log below:
===== Begin GnuPG log =====
gpg: AES256.CFB encrypted data
gpg: encrypted with 1 passphrase
gpg: decryption failed: Bad session key
===== End GnuPG log =====

Q6:需要 snap 版但机器没有 snapd? snap 依赖 systemd + snapd(第七节前置),改用方案 A/B/C 均可覆盖同一版本诉求。

十二、卸载与清理

apt/PPA 版卸载实测:

apt-get remove --purge -y duplicity

实测回显(输出节选):

(Reading database ... 10343 files and directories currently installed.)
Removing duplicity (3.2.2-ppa202610141802~ubuntu22.04.1) ...

确认卸载干净:

duplicity --version
dpkg -l duplicity

实测回显:

bash: duplicity: command not found
dpkg-query: no packages found matching duplicity

pip 版卸载实测:

pip3 uninstall -y duplicity

实测回显(输出节选):

Successfully uninstalled duplicity-3.2.2

遗留数据清理(按需):备份产物目录 /srv/backups、本地元数据缓存 ~/.cache/duplicity、GPG 密钥 ~/.gnupg,确认不再需要恢复后可整目录删除。

十三、参考链接