website-scripts/README.md

115 lines
4.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Scripts — 部署与运维脚本
多站点 Docker 项目的运维脚本集合,涵盖本地开发管理、云服务器运维、云端部署、数据库备份恢复。
## 脚本清单
| 脚本 | 用途 | 目标环境 |
|------|------|---------|
| `sites-manage-local.sh` | 本地站点启停npm run dev + Docker | 本地 |
| `sites-manage-cloud.sh` | 云服务器站点启停SSH / 服务器本地运行) | 云端 |
| `deploy-ai.sh` | 部署站点到 tlyq.aitxjp 服务器) | 云端 |
| `deploy-cc.sh` | 部署站点到 tlyq.cctgz 服务器) | 云端 |
| `backup-db.sh` | 备份数据库assets / issue / ldap | 云端 → 本地 |
| `restore-db.sh` | 恢复数据库到本地或云端 | 本地 / 云端 |
| `edit-site-cc.sh` | www.tlyq.cc 官网内容管理 | 云端 |
---
## sites-manage-local.sh — 本地站点管理
```bash
bash scripts/sites-manage-local.sh start # 启动全部
bash scripts/sites-manage-local.sh start ai # 启动 ai 全部
bash scripts/sites-manage-local.sh start ldap oa # 启动指定站点
bash scripts/sites-manage-local.sh stop oa # 停止指定站点
bash scripts/sites-manage-local.sh restart ldap # 重启指定站点
bash scripts/sites-manage-local.sh status # 查看状态
```
站点启动方式:
| 站点 | 方式 | 端口 |
|------|------|------|
| ldap | Docker | 6178Web UI、3890LDAP |
| oa | `npm run dev`(宿主机) | 6179 |
| issue | `npm run dev`(宿主机) | 6176 |
| assets | `npm run dev`(宿主机) | 6177 |
| www / cloud / token | Docker | 61736175 |
## sites-manage-cloud.sh — 云服务器站点管理
```bash
bash scripts/sites-manage-cloud.sh start ai # 启动全部
bash scripts/sites-manage-cloud.sh restart nginx # 重启 nginx
bash scripts/sites-manage-cloud.sh stop oa issue # 停指定站点
bash scripts/sites-manage-cloud.sh status # 查看状态
```
自动检测运行环境:本地 Mac 运行时通过 SSH 操作 txjp在云服务器上运行时直接操作本地 Docker。也可显式指定
```bash
OA_REMOTE=local bash scripts/sites-manage-cloud.sh status # 强制本地模式
OA_REMOTE=ssh bash scripts/sites-manage-cloud.sh status # 强制 SSH 模式
```
站点全部以 Docker 方式运行,依赖关系:`ldap → oa / issue / assets → nginx`。
## deploy-ai.sh — tlyq.ai 部署
```bash
bash scripts/deploy-ai.sh # 自动检测:增量 or 完整构建
bash scripts/deploy-ai.sh --force # 强制完整构建
bash scripts/deploy-ai.sh --restart # 仅重启容器
```
交互式选择站点17www / cloud / token / issue / assets / oa / ldap。
流程:源码打包 → 上传 → 服务器 `npm install``npm run build` → 容器重建。部署后自动验证。
LDAP 部署特殊处理:上传 Dockerfile + docker-compose.yml自动创建 .env去除端口映射`--build` 构建含 sqlite3 的镜像。
## backup-db.sh — 数据库备份
```bash
bash scripts/backup-db.sh
```
一键备份三个数据库:
| 数据库 | 服务 | 内容 |
|--------|------|------|
| assets-{时间戳}.db | assets-ai | 设备资产 |
| issue-{时间戳}.db | issue-ai | 工单、配件 |
| ldap-{时间戳}.db | lldap | **全部用户账号** |
流程WAL checkpoint → 云端打包 → 云端持久保留 → 下载到本地 → 完整性验证。
> 详细文档见 [BACKUP-RESTORE.md](../docs/BACKUP-RESTORE.md)
## restore-db.sh — 数据库恢复
```bash
# 恢复云端数据库
bash scripts/restore-db.sh cloud issue issue-20260518_1200.db
bash scripts/restore-db.sh cloud ldap ldap-20260518_1200.db
# 恢复本地数据库
bash scripts/restore-db.sh local assets assets-20260518_1200.db
```
支持服务:`assets` / `issue` / `ldap`。流程:检查 → 验证 → 确认 → 备份当前库 → 停止容器 → 替换 → 清理 WAL → 启动 → 验证。
## 备份存储路径
| 位置 | 路径 |
|------|------|
| 云端持久备份 | `/root/docker/db-backups/` |
| 本地备份 | `db-backups/` |
| 云端临时 | `/tmp/db-backup/`(完成后清理) |
## 依赖
- **本地**macOS / Linuxbashssh配置 `txjp``tgz` 别名scpdockersqlite3
- **云端**Docker ComposeNode.jsbetter-sqlite3