#/protect/overview
备份与恢复 (nextxch Protect):证据导出、配置、数据、还原和更换服务商
nextxch Protect 将举证、备份和恢复所需的一切集中在管理后台的“备份与恢复”下:带 Ed25519 签名清单、可用作证据的 EML 导出,带版本的配置备份,加密增量数据备份(目录、SMB 共享或带 Object Lock 的 S3),从 GoBD 归档、已删除项目或数据备份还原到邮箱,首次启动时的裸机恢复,以及用于更换服务商的带还原和实时同步的流水线部署。一切均内置于服务器中,无需附加产品,也无需外部服务。
入门顺序:首先在“备份与恢复 > 配置”下设置备份密钥(至少 12 个字符的口令或恢复密钥,仅限已登录的服务器管理员),并将其保存在服务器之外。配置备份和数据备份使用同一密钥;服务器只存储公钥部分,可以写入备份,但永远无法读取。许可证:配置备份、证据导出验证、Webmail 自助服务、首次启动时还原以及配置的流水线还原包含在所有版本中;数据备份、证据导出、还原作业、流水线还原的数据部分以及实时同步自 Business 版起提供。
1. 快速入门:密钥、目标、首次备份和校验
目标和计划在“备份与恢复 > 计划与目标”下设置(仅限服务器管理员)。nextxch-cli 使用 API 密钥或管理员登录进行身份验证。
# 1. Admin > Backup & Recovery > Configuration: set up the backup key
# (passphrase of 12+ characters or recovery key, keep it safe outside the server)
# 2. Schedules & targets: add a target (directory, SMB share \\nas\backup\nextxch or S3) and "Test"
# 3. Back up the configuration (every tier) and take it along as a file:
nextxch-cli config backup --label "before migration" -o nextxch-config.zip
# 4. Data backup (Business): full first, then incremental by schedule
nextxch-cli backup run --target nas --full
nextxch-cli backup list --target nas
# 5. Verify, with the passphrase including decryption of the sample
export NEXTXCH_BACKUP_PASSPHRASE='...'
nextxch-cli backup verify --target nas --passphrase-env NEXTXCH_BACKUP_PASSPHRASE --limit 200
2. 可用作证据的导出:ZIP、清单、签名和验证
邮件以 .eml 格式逐字节放入 ZIP。manifest.json 列出每个文件的 SHA-256、大小、归档哈希、完整性状态、保留期和诉讼保留;manifest.json.sig 是针对清单原始字节的 Ed25519 签名,由服务器机密派生,在所有集群节点上相同。GET /api/compliance/exports/public-key 无需登录即可返回公钥。解密选项仅移除静态加密(仅限 ServerAdmin 和 ComplianceAuditor,否则返回 403 DECRYPT_NOT_ALLOWED);它并非通用的 S/MIME 或 OpenPGP 解密。单个下载 GET /api/compliance/messages/{id}/raw 以 HTTP 标头 X-Nextxch-Sha256、X-Nextxch-Stored-Sha256、X-Nextxch-Integrity 和 Repr-Digest 返回哈希。导出自 Business 版起提供,验证在所有版本中提供。
nextxch-evidence-20261111-0930-1a2b3c4d.zip
messages/000001-<archiveId>.eml original message, byte for byte
messages/000002-<archiveId>.eml
SHA256SUMS.txt verifiable with sha256sum -c
manifest.json format nextxch-evidence-export/1, scope (incl. caseReference), items[]
manifest.json.sig Ed25519: algorithm, keyId, publicKey, signedSha256, signature
README.txt
# Start an export (202, status under GET /api/compliance/exports/{id}):
curl -X POST https://mail.company.com/api/compliance/exports -H "X-Api-Key: $KEY" \
-H "Content-Type: application/json" \
-d '{"scope":"mailbox","account":"anna@company.com","sinceUtc":"2026-01-01T00:00:00Z","caseReference":"Case 2026-0815"}'
# Verify offline, without access to the server (exit code 0 valid, 1 invalid/tampered, 2 usage error):
curl -s https://mail.company.com/api/compliance/exports/public-key > nextxch-evidence-key.json
nextxch-cli export verify nextxch-evidence-20261111-0930-1a2b3c4d.zip --public-key <publicKey from the file>
unzip -d export nextxch-evidence-20261111-0930-1a2b3c4d.zip && cd export && sha256sum -c SHA256SUMS.txt
3. 配置备份:内容、加密、差异比较和部分还原
一个包包含以代码形式保存的配置 (config/*.yaml)、不含机密的状态文件 (server/*)、Sieve 规则以及 secrets.enc 中的加密机密(AES-256-GCM,数据密钥用备份密钥封装;手动备份还可以额外设置自己的口令)。部分:config:<area>、dkim、passwords、tls-certificates、api-keys、sieve、server-files、licence;licence、passwords 和 api-keys 仅在明确指定时才会还原。还原默认是带预览的试运行。所有版本均提供;REST 位于 /api/v1/config/backups 下。
nextxch-cli config list # versions (reason: manual, pre-update, after-change, pre-restore, import)
nextxch-cli config diff 20261101T020000Z-a1b2c3 current # difference between two versions or to the current state
nextxch-cli config backup --label "before update" --passphrase-env BACKUP_PW -o nextxch-config.zip
nextxch-cli config import -f nextxch-config.zip # take over a package of another server
# Partial restore: preview first, then apply
nextxch-cli config restore 20261101T020000Z-a1b2c3 --sections dkim,config:domains --domain company.com --dry-run
nextxch-cli config restore 20261101T020000Z-a1b2c3 --sections dkim,config:domains --domain company.com --yes
# REST: POST /api/v1/config/backups/{id}/restore
# {"sections":["dkim","config:domains"],"domain":"company.com","prune":false,"dryRun":true}
4. 数据备份:目标、格式和目录
每次运行都会生成一个自包含的版本:按表的数据库快照(与数据库提供程序无关,因此也可以从 SQLite 迁移到 PostgreSQL)、状态文件、GoBD 归档清单以及所有引用的 blob。blob 按 SHA-256 寻址,只传输一次;增量运行只上传新的哈希。所有内容均以 NXB1 格式加密存储(分块 AES-256-GCM,绑定到对象名)。目录和 blob 索引是不含机密的可读 JSON,目录使用证据导出的 Ed25519 密钥签名。完整格式见代码仓库中的 docs/protect/backup-format.md。Business 版起提供;REST 位于 /api/admin/protect/backups 下(服务器管理员)。
<target>/ directory, SMB share or s3://bucket/nextxch-backup/
nextxch-backup.json target marker
keys/backup-key-<keyId>.json public key + sealed private key
keys/dk-<dataKeyId>.json data key of one run (ECDH wrapped)
blobs/ab/cd/<sha256>.nxb one mail or file content, immutable
versions/20261111T023000Z-a1b2c3/
catalog.json catalog.json.sig catalog (written last = version complete) + signature
blobs.ndjson.gz blob index of the version
db/<table>.ndjson.gz.nxb database snapshot, one file per table
files/<path>.nxb state files of the data directory
archive-manifest.json.gz.nxb retention, legal hold, integrity chain
# Settings via REST (PUT /api/admin/protect/backups/settings):
{"verifyEveryHours":24,"verifySampleSize":50,"alertOnFailure":true,"uploadParallelism":4}
# Back up a domain or single mailboxes:
nextxch-cli backup run --target s3-fsn1 --scope domains:company.com,company.at
nextxch-cli backup run --target s3-fsn1 --scope mailboxes:anna@company.com --no-wait
5. 还原到邮箱:来源、时间点、目标
来源:archive(GoBD 归档)、recoverable(已删除项目)和 backup(数据备份)。使用 --point(快照 id、day:yyyy-MM-dd 或 latest)或 --as-of 选择时间点。目标:original(原始文件夹)、restored(默认,文件夹 "Wiederhergestellt yyyy-MM-dd",名称可通过 --label 指定)或 account(同一租户的另一个邮箱,例如继任者邮箱)。重复项按 SHA-256、Message-ID 和 UID 跳过,来源保持不变。允许 TenantAdmin 和 ServerAdmin 执行,每个作业最多 250,000 个项目;作业自 Business 版起提供,策略和 Webmail 自助服务在所有版本中提供。
nextxch-cli restore points --account anna@company.com --source backup
nextxch-cli restore browse --account anna@company.com --source backup --point latest --folder INBOX --filter "invoice"
nextxch-cli restore preview --account anna@company.com --source archive --as-of 2026-10-31T23:59:59Z --folder "Projects/Plant"
nextxch-cli restore start --account anna@company.com --source archive --as-of 2026-10-31T23:59:59Z \
--folder "Projects/Plant" --target restored --label "Plant (restored)"
# Whole mailbox into a successor mailbox:
nextxch-cli restore start --account ben@company.com --source backup --point day:2026-11-01 \
--target account --target-account successor@company.com --passphrase-env NEXTXCH_BACKUP_PASSPHRASE
nextxch-cli restore jobs --account ben@company.com
# REST: /api/compliance/restore (sources, points, browse, preview, jobs, policy)
# Webmail: GET /api/mail/self-restore, POST /api/mail/self-restore {"ids":[...]}
6. 裸机恢复:新安装加备份即可恢复旧服务器
在全新安装上(MSI、Docker 或 Linux,最多一个租户、一个域、一个账户,且尚无管理员登录),/setup/ 会在登录框下方显示“从备份还原”:上传包、输入口令、预览、还原,可选还原数据备份,完成并重启。仅可使用首次启动时写入日志和 {DataDirectory}/first-run/setup-token.txt 的一次性设置令牌访问(标头 X-Nextxch-Setup-Token),或在设置 Setup:TrustLoopback=true 时从服务器本机访问。首次管理员登录或点击“完成”后,向导将永久关闭。旧服务器的备份密钥不会被沿用,之后必须重新设置。SQLite 全文索引不属于备份内容:重建索引后,搜索才能找到已还原的邮件。
# Headless via CLI (same API /api/setup):
export NEXTXCH_SETUP_TOKEN="$(cat /var/lib/nextxch/first-run/setup-token.txt)"
export NEXTXCH_BACKUP_PASSPHRASE='...'
nextxch-cli setup restore --config nextxch-config.zip --data s3://dr-bucket/nextxch/ --prune --dry-run
nextxch-cli setup restore --config nextxch-config.zip --data s3://dr-bucket/nextxch/ --prune --yes
# Unattended on first start (Docker Compose, Kubernetes, MSI):
environment:
NEXTXCH_RESTORE_FROM: s3://dr-bucket/nextxch/ # .zip, directory, s3://, https:// or config-backup:<id>
NEXTXCH_RESTORE_PASSPHRASE: ${BACKUP_PASSPHRASE} # without: configuration without secrets
NEXTXCH_RESTORE_DATA_FROM: s3://dr-bucket/nextxch/ # optional, location of the data backup
NEXTXCH_RESTORE_PRUNE: "true" # remove bootstrap objects
NEXTXCH_RESTORE_WITH_CREDENTIALS: "true" # passwords, API keys, licence (default true)
NEXTXCH_RESTORE_S3_ENDPOINT: https://fsn1.your-objectstorage.com
NEXTXCH_RESTORE_S3_ACCESS_KEY: ${S3_KEY}
NEXTXCH_RESTORE_S3_SECRET_KEY: ${S3_SECRET}
# Result: {DataDirectory}/pipeline-restore/first-start.json ("ok": true = variable is ignored afterwards)
# Helm: restore.from, restore.scope, restore.mapping, restore.passphrase, restore.s3.* (replicaCount: 1)
7. 带还原的流水线部署 (nextxch-cli deploy --restore)
一条命令或一个流水线步骤即可从备份重建服务器:应用配置、还原数据、运行检查(哈希抽样、健康状态、仅向 Mailpit 或本地邮箱发送测试邮件),并可选地给出 DNS/MX 更改说明;DNS 绝不会被自动更改。每次运行都是幂等的,中断后会从最后完成的步骤继续。映射文件(kind RestoreMapping,架构见 GET /api/v1/deploy/mapping-schema)可改写主机名、IP 地址和路径,决定证书的来源(backup、acme、files),并描述新主机的数据库和存储;邮件域绝不会被重命名。使用作用域为 deploy.restore 的集成密钥登录。配置部分所有版本均提供,数据部分自 Business 版起提供(全新安装首次启动时除外);数据部分涵盖范围 all。
# mapping.yaml
apiVersion: nextxch/v1
kind: RestoreMapping
hostnames:
mail.old-provider.example: mail.company.com
ips:
203.0.113.10: 198.51.100.20
paths:
"C:\\Data\\NextxchData": /var/lib/nextxch
certificates:
mode: acme # backup | acme | files
acme: {contactEmail: hostmaster@company.com}
database:
provider: Postgres # must match the new host (Storage__Provider)
connectionStringEnv: NEXTXCH_PG_CONNECTION
storage:
blobBackend: S3
s3: {endpoint: https://fsn1.your-objectstorage.com, bucket: nextxch-mail}
# Plan (dry run, shows every replacement), then restore with checks:
nextxch-cli deploy --restore ./nextxch-config.zip --scope config --map mapping.yaml --dry-run
nextxch-cli deploy --restore s3://dr-bucket/nextxch/ --map mapping.yaml --test-mail mailpit --dns-instructions --yes
# REST: POST /api/v1/deploy/restore (dryRun defaults to true)
# {"source":"s3://dr-bucket/nextxch/","scope":"all","mapping":"...","dryRun":false,"testMail":"mailpit","hashSample":20}
# Local package: POST /api/v1/deploy/restore/upload (application/zip) -> source "upload:<sha256>"
# Runs: GET /api/v1/deploy/restore/runs
8. CI 模板:GitHub Actions、GitLab CI、Azure DevOps 和 Ansible
模板位于代码仓库的 deploy/ci 下:带计划阶段并需在生产环境上审批的还原,以及每晚运行的 DR 探测,它会还原到一次性环境中,并生成包含时长 (RTO) 和数据状态 (RPO) 的报告。机密应放在已屏蔽、受保护的 CI 变量中;测试邮件发送到作业旁边的 Mailpit 容器,绝不会离开该容器。
deploy/ci/github-actions/nextxch-restore.yml plan on a throwaway instance, container with restore on first start, checks, DNS step
deploy/ci/github-actions/nextxch-dr-probe.yml nightly DR probe with RTO/RPO report
deploy/ci/gitlab/.gitlab-ci.yml restore (RESTORE_SOURCE, RESTORE_SCOPE, PLAN_ONLY ...) + DR probe (NEXTXCH_PIPELINE=dr-probe)
deploy/ci/azure-devops/azure-pipelines.yml restore with parameters, deployment job on environment production
deploy/ci/azure-devops/azure-pipelines-dr-probe.yml nightly DR probe, report in the run summary
deploy/ci/ansible/playbook-restore.yml role nextxch_restore: container (Linux) or MSI (Windows)
deploy/ci/mapping.example.yaml, mapping.schema.json example and JSON Schema of the mapping file
9. 更换服务商时的实时同步:短暂冻结代替长时间停机
完整还原后,新服务器通过增量运行跟随旧服务器:旧服务器继续写入其数据备份(例如每小时写入 S3),每次运行只接管自上次接管的版本以来发生变化的 blob、表行和状态文件。进度记录在 {DataDirectory}/pipeline-restore/live-sync.json 中;再次运行相同命令不会产生变化,或会继续中断的操作。切换时需手动冻结旧服务器(在其防火墙上阻止邮件和客户端端口,保持服务运行,使用 nextxch-cli backup run --full 进行最后一次备份),然后 --cutover --source-frozen 以完整行比对的方式接管该备份。之后重启新服务器并更改 DNS。Business 版起提供;REST:POST /api/v1/deploy/live-sync、POST /api/v1/deploy/live-sync/cutover、GET /api/v1/deploy/live-sync。
nextxch-cli deploy --restore s3://dr-bucket/nextxch/ --scope all --yes # 1. full restore (baseline)
nextxch-cli deploy --restore s3://dr-bucket/nextxch/ --live-sync --dry-run # remaining delta, changes nothing
nextxch-cli deploy --restore s3://dr-bucket/nextxch/ --live-sync --interval 5m --until-cutover # 2. follow the old server
nextxch-cli deploy --restore s3://dr-bucket/nextxch/ --cutover # 3. instructions for the freeze
# old server: block ports, then nextxch-cli backup run --full
nextxch-cli deploy --restore s3://dr-bucket/nextxch/ --cutover --source-frozen # 4. last backup, last run
设置、默认值与最佳实践
| 设置 / 位置 | 说明 | 默认值 | 生产环境最佳实践 |
|---|---|---|---|
Konfigurationssicherung: Versionen (#/protect/config) |
每次更新前自动生成版本 (AutoBeforeUpdate),更改后也自动生成版本(AutoAfterChanges,在 DebounceMinutes 后合并),另有手动版本、导入版本以及每次还原前的安全快照。 | KeepLast 30 · KeepDailyDays 90 · Debounce 10 min |
在进行较大更改之前,请创建一个带标签的手动版本,并将 .zip 保存在服务器之外。 |
Sicherungsschlüssel (Passphrase / Wiederherstellungsschlüssel) |
ECDH P-256;私钥部分仅以密封形式存在(PBKDF2-SHA256,600,000 次迭代,AES-256-GCM),并随每个包一起保存。没有密钥也没有口令时,配置备份不包含任何机密。 | nicht eingerichtet · Passphrase ab 12 Zeichen |
请打印恢复密钥,并与服务器分开保管;没有它就无法读取数据备份。 |
Datensicherung: Aufbewahrung je Ziel |
最新的 KeepLast 个版本,加上最近 KeepHourly 小时、KeepDaily 天、KeepWeekly 个 ISO 周和 KeepMonthly 个月中每个时段的最新版本 (UTC)。 | 3 / 24 / 7 / 4 / 12 |
实时同步期间请至少保留两个版本,否则无法计算增量 (BASELINE_GONE)。 |
S3 Object Lock (ObjectLockMode, ObjectLockDays) |
对象以 Governance 或 Compliance 模式及保留截止日期写入;被重复使用的 blob 会获得延长的日期(当前时间加锁定天数的 1.5 倍),从而不会有任何版本指向过早变为可删除的对象。 | Normal · 30 Tage |
为防范勒索软件,请在启用版本控制的专用存储桶上使用 Compliance 模式;锁定的对象只有在其日期过后由后续运行删除。 |
Zeitpläne (Frequency, Type, Scope) |
每小时、每天或每周,增量或完整,按目标和范围(服务器、域、邮箱)设置;时间采用服务器本地时间,不使用 cron 表达式。 | Täglich 02:30 inkr. · Sonntag 03:30 voll |
预置的计划起初没有目标:请分配目标并启用它们,否则不会运行任何备份。 |
Automatische Prüfung (VerifyEveryHours, VerifySampleSize) |
在无密钥的情况下检查存储的哈希、信封标头、密钥文件、目录签名以及目录和 blob 索引的可读性;提供口令时,还会解密抽样数据和所有表文件。 | alle 24 h · 50 Objekte |
请保持 AlertOnFailure 开启,以便失败的备份和校验运行通知到告警目标。 |
Parallele Uploads je Sicherung (UploadParallelism) |
并发上传到 S3 和目录目标的数量。 | 4 (1 bis 32) |
对于高速链路上的 S3,建议 8 到 16;对于慢速 SMB 上的 NAS,建议 2 到 4。 |
SQL Server: ALLOW_SNAPSHOT_ISOLATION |
nextxch 会在启动时尝试开启快照隔离。如果快照隔离处于关闭状态,则以 READ COMMITTED 逐表导出(一致性为 read-committed),并且该次运行会报告警告。 | an, wenn erlaubt |
概览页显示可供复制的 SQL 语句;启用快照隔离后,数据库快照具有事务一致性。 |
RecoverableItemsDays (restore-policy.json) |
已删除的约会、联系人、任务和便笺保留其内容的时长;之后仅保留一个空的墓碑记录用于同步。软删除的邮件会保留到被彻底清除为止。 | 14 Tage (nach Upgrade 30) |
请在流程文档中注明:如果没有数据备份,已删除的协作项目在此期限过后将丢失其内容。 |
Selbstbedienung im Webmail (SelfServiceEnabled, SelfServiceDays) |
用户可在“还原已删除项目”下自行找回已删除的邮件和协作项目(每次最多 500 个)。可在全服务器或按域调整;0 天表示没有单独的时间窗口。 | an · 0 Tage |
对于规则严格的域,请在该处设置时间窗口或关闭自助服务。 |
Beweisexport: Rollen, Umfang, Download |
ComplianceAuditor、TenantAdmin(仅限自己的租户)和 ServerAdmin 可以导出;范围为 search、mailbox、range 或 legalHold,最多 100,000 封邮件(上限 250,000)。下载链接有效期为 24 小时。 | includeSoftDeleted true · 24 h |
请始终填写案件编号 (caseReference):它会写入签名清单和审计日志。 |
Setup:TrustLoopback |
允许来自服务器本机(环回)的请求无需设置令牌即可访问设置向导。默认情况下,每个请求都需要 first-run/setup-token.txt 中的令牌。 | false |
仅在没有其他本地用户的主机上设置此项;否则请通过 NEXTXCH_SETUP_TOKEN 传递令牌。 |
Audit-Log & GoBD |
每个步骤都记录在审计日志中:config.backup*、data.backup.*、Compliance.EvidenceExport*、Protect.Restore*、Protect.SelfRestore、Protect.RestorePolicy、setup.* 和 config.restore;可在“备份与恢复 > 日志”下查看。任何还原都不会更改 GoBD 归档。 | aktiv |
数据备份包含带保留期和诉讼保留信息的归档清单;还原后会检查每个已归档的哈希,并重新设置锁定。 |