TOTP Vault DocsDeployment & Recovery
TOTP VAULT · OPERATIONS GUIDE · v1.2.0

AGE 与自动备份

第六章 AGE 与自动备份

说明

在 Windows 生成 AGE 密钥、完成第一次加密备份并配置宝塔计划任务。

#31. Windows 下载 AGE 到 D:\SoftWare\Age

Windows PowerShell

🪟 执行位置:你自己的 Windows 电脑 PowerShell

下方命令块可以直接复制;带“检查/预期”的内容用于核对结果,不要当作命令输入。

打开 PowerShell:

New-Item -ItemType Directory -Force -Path "D:\SoftWare\Age"
cd "D:\SoftWare\Age"

下载官方 Windows x64 AGE v1.3.1:

Invoke-WebRequest `
  -Uri "https://github.com/FiloSottile/age/releases/download/v1.3.1/age-v1.3.1-windows-amd64.zip" `
  -OutFile "D:\SoftWare\Age\age-v1.3.1-windows-amd64.zip"

SHA256:

Get-FileHash "D:\SoftWare\Age\age-v1.3.1-windows-amd64.zip" -Algorithm SHA256

Windows amd64 v1.3.1 参考 SHA256:

c56e8ce22f7e80cb85ad946cc82d198767b056366201d3e1a2b93d865be38154

解压:

Expand-Archive `
  -Path "D:\SoftWare\Age\age-v1.3.1-windows-amd64.zip" `
  -DestinationPath "D:\SoftWare\Age\Extracted" `
  -Force

查找:

Get-ChildItem "D:\SoftWare\Age\Extracted" -Recurse -Filter "age-keygen.exe"

假设路径:

D:\SoftWare\Age\Extracted\age\age-keygen.exe

进入:

cd "D:\SoftWare\Age\Extracted\age"

检查:

.\age.exe --version
.\age-keygen.exe --version

#32. Windows 生成 AGE 密钥

Windows PowerShell

🪟 执行位置:你自己的 Windows 电脑 PowerShell

下方命令块可以直接复制;带“检查/预期”的内容用于核对结果,不要当作命令输入。

创建私钥目录:

New-Item -ItemType Directory -Force -Path "D:\SoftWare\Age\PrivateKey"

生成:

.\age-keygen.exe -o "D:\SoftWare\Age\PrivateKey\totp-vault-age-private-key.txt"

终端会显示:

Public key: age1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

网站只填写:

age1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

私钥文件:

D:\SoftWare\Age\PrivateKey\totp-vault-age-private-key.txt

里面的:

AGE-SECRET-KEY-1...

绝对不要:

上传服务器
上传 OneDrive
发聊天软件
提交 Git
填入网站

至少保留两份离线副本。


#33. 网站保存 AGE Public Key

浏览器 / Microsoft Entra

🌐 执行位置:浏览器 / Microsoft Entra / 网站后台

下方命令块可以直接复制;带“检查/预期”的内容用于核对结果,不要当作命令输入。

后台 → 备份 → AGE 加密与保留策略。

填写:

AGE Public Key:age1...
每日备份保留:30
月度备份保留:12

保存后应:

AGE ENCRYPTION: Public key ready

#34. 第一次完整备份

浏览器 / Microsoft Entra

🌐 执行位置:浏览器 / Microsoft Entra / 网站后台

下方命令块可以直接复制;带“检查/预期”的内容用于核对结果,不要当作命令输入。

备份前最后检查:

/www/server/php/82/bin/php -r '
echo "proc_open: " . (function_exists("proc_open") ? "AVAILABLE" : "DISABLED") . PHP_EOL;
'

必须:

proc_open: AVAILABLE

AGE:

sudo -u www /usr/bin/age --version

.env

cd /www/wwwroot/2fa.example.com
grep '^AGE_BINARY=' .env

应:

AGE_BINARY="/usr/bin/age"

或等效 /usr/bin/age

后台点击:

立即备份

成功后 OneDrive:

TOTP-Vault-Backup
└── Backups
    └── totp-vault-YYYYMMDD-HHMMSS.tar.gz.age

OneDrive 不应出现:

database.sqlite
vault.key
.tar.gz 明文

#35. 宝塔计划任务

宝塔面板

🧰 执行位置:宝塔面板(部分步骤配合 SSH)

下方命令块可以直接复制;带“检查/预期”的内容用于核对结果,不要当作命令输入。

#35.1 每日完整备份

任务类型:Shell 脚本
任务名称:TOTP Vault 每日完整备份
周期:每天
时间:03:30

脚本:

cd /www/wwwroot/2fa.example.com
PHP_BINARY=/www/server/php/82/bin/php bash scripts/backup.sh

#35.2 延迟备份检查

任务类型:Shell 脚本
任务名称:TOTP Vault 延迟备份检查
周期:N 分钟
分钟:5

脚本:

cd /www/wwwroot/2fa.example.com
PHP_BINARY=/www/server/php/82/bin/php bash scripts/backup-due.sh

分别手动执行一次。

每日成功:

Backup uploaded and verified.
File: totp-vault-...
SHA256: ...

延迟任务无待办时:

No deferred backup is due.

这是正常结果。


#36. 最终在线健康检查

服务器 SSH / 终端

🖥️ 执行位置:服务器 SSH / 终端

下方命令块可以直接复制;带“检查/预期”的内容用于核对结果,不要当作命令输入。

cd /www/wwwroot/2fa.example.com
sudo -u www /www/server/php/82/bin/php artisan totp:health --online

最终目标:

OneDrive configuration PASS
OneDrive connection PASS
Recent backup PASS
BT cron heartbeat PASS
proc_open PASS
age binary PASS

生产检查:

cd /www/wwwroot/2fa.example.com
PHP_BINARY=/www/server/php/82/bin/php \
  bash scripts/check-production.sh https://2fa.example.com

目标:

Production Ready

#37. 敏感地址测试

服务器 SSH / 终端

🖥️ 执行位置:服务器 SSH / 终端

下方命令块可以直接复制;带“检查/预期”的内容用于核对结果,不要当作命令输入。

浏览器或 curl:

curl -I https://2fa.example.com/.env
curl -I https://2fa.example.com/composer.json
curl -I https://2fa.example.com/.git/config
curl -I https://2fa.example.com/storage/logs/php-error.log
curl -I https://2fa.example.com/database/database.sqlite

必须 403/404,不允许返回文件内容。