#/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 (快照識別碼、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 API: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(一致性讀取已提交)逐一匯出,且執行結果會回報警告。 | 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 |
資料備份保存包含保留與法律保留的封存清單;還原後會檢查每個已封存的雜湊並重新設定鎖定。 |