> ## Content Index
> Fetch the complete content index at: https://sgpublic.xyz/llms.txt
> Use this file to discover other available public pages before exploring further.

# 在无状态环境中实现自动化备份：基于 Duplicati 的实践
- URL: https://sgpublic.xyz/p/2026/04/6aac9cb1810a480001533616/
- Published: 2026-04-21T10:17:21.000Z
- Updated: 2026-09-18T04:35:55.000Z
- Author: Haven Madray
- Tags: 基础设施, #wp-post

最近在使用某公共算力平台，这个平台除了指定的持久化目录外，其余数据在重启后全部丢失，而且这个持久化目录还是通过对象存储实现的，这导致里面的文件权限无法保持，比如强制 0755，因此直接把用户目录持久化的方案是不可行的，会造成奇奇怪怪的问题。

综上所有信息，我选择使用 Duplicati 完成自动化备份，并在需要的时候恢复文件。

### 安装

前往 [duplicati/duplicati - Release](https://github.com/duplicati/duplicati/releases/latest?ref=sgpublic.xyz) 下载适用于系统的 gui 安装包。例如我这里的是 x86-64 的 Ubuntu 环境，于是下载 `duplicati-2.3.0.0_stable_2026-04-14-linux-x64-gui.deb`，上传到 `~/Download` 目录中，使用以下命令安装：

```shell
apt install ~/Download/duplicati-2.3.0.0_stable_2026-04-14-linux-x64-gui.deb

```

### 启动

使用以下命令启动（请自行处理会话保持）：

```shell
duplicati-server --webservice-allowed-hostnames=* --webservice-interface=any

```

启动后输出示例如下：

```shell
root@nb-87a1c6d704fc10459e-68f6576cd4-j9nhd:~$ duplicati-server
No database encryption key was found. The database will be stored unencrypted. Supply an encryption key via the environment variable SETTINGS_ENCRYPTION_KEY or disable database encryption with the option --disable-db-encryption
Server has started and is listening on localhost, port 8200
Use the following link to sign in: http://localhost:8200/signin.html?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXAiOiJT...

```

日志中输出了一个链接，复制链接中 `token=` 后面这一长串形如 `eyJhb...` 的字符串，然后在平台上开放 8200 端口，访问 `http://<你的ip>:8200/signin.html`，在打开的页面中输入刚刚复制的 `token` 即可进入主页。

![输入 Token](https://sgpublic.xyz/content/images/2026/09/ee581e91-cd4e-4be6-8826-2bc64e823854.png)

进入主页后会提示创建密码，请牢记此密码。

![设置密码](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_17-52-51.png)

进入系统后可在此处将语言调整为简体中文。

![设置语言](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_17-54-23.png)

### 创建备份

回到主页，点击创建一个备份。

![开始创建](https://sgpublic.xyz/content/images/2026/09/3768e6ff-29ef-4ca4-88be-c7c30018bfb6.png)

#### 常规设置

这部分设置按需填写，若追求效率不关心隐私，加密方式可选择 `None`。

![常规设置](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_17-57-53.png)

#### 目标设置

这部分设置的是将你备份的文件保存到哪里，这里选择备份存储方式是“文件系统”。

![选择文件系统](https://sgpublic.xyz/content/images/2026/09/22a13b9d-b4cf-47be-ba16-86ab3b888022.png)

然后选择你在算力平台上设置的持久化路径，例如我这里设置的是挂载到 `/vol1`，于是我选择 `/vol1/backup` 作为保存目录。

![d1dc396f-63e6-4320-8a0f-7192ce7592d4](https://sgpublic.xyz/content/images/2026/09/d1dc396f-63e6-4320-8a0f-7192ce7592d4.png)

#### 源数据

这部分设置的是你要备份哪些文件。这里建议仅选择必须备份的文件，可以很容易从网络上下载的文件建议从备份文件中排除。

例如我这里仅备份了源码目录、配置目录，排除了 `.pixi`（pixi 虚拟环境目录）、`.venv`（python 虚拟环境目录）、`node_modules`（node 依赖缓存目录）。

![源数据](https://sgpublic.xyz/content/images/2026/09/140f6887-34ff-45fd-80ef-6ed547e76d63.png)

#### 调度计划

这部分设置的是何时运行自动备份。我这里设置的是每天凌晨两点自动备份。

![PixPin_2026-04-21_18-07-24](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_18-07-24.png)

#### 选项

这部分配置的是备份策略，例如保留多少天或多少个版本的备份。我这里选择保留近两周的文件，可按需设置。

![PixPin_2026-04-21_18-09-31](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_18-09-31.png)

#### 创建备份

点击提交即可创建备份任务，可回到主页，找到刚刚创建的备份任务，点击“开始”即可手动创建备份。

![PixPin_2026-04-21_18-10-38](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_18-10-38.png)

### 恢复备份

当你的文件因意外或重启容器丢失，可以前往“恢复”页面恢复你的文件。

![PixPin_2026-04-21_18-12-27](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_18-12-27.png)

找到你创建的备份任务，或选择“Direct restore from backup files”并定位到你备份任务保存到位置，然后就可以选择需要恢复的文件。

![PixPin_2026-04-21_18-14-48](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_18-14-48.png)

恢复时，推荐选择将文件恢复到原始位置，当文件存在时覆盖文件，并且勾选恢复文件源数据和恢复原始读写权限。

![PixPin_2026-04-21_18-15-52](https://sgpublic.xyz/content/images/2026/09/PixPin_2026-04-21_18-15-52.png)

点击提交即可恢复文件。