Files
hzdyjs/用户信息同步统一身份认证/README.md
T
“wuzhen”andCursor 334bd8742e feat: 新增统一身份认证用户数据定时同步脚本
将校园系统部门、教职工、学生数据同步到认证中间库6张标准表,支持 MySQL 本地测试与 Oracle 生产目标库配置。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-24 10:01:16 +08:00

69 lines
2.3 KiB
Markdown
Raw 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.
# 统一身份认证用户数据同步
将校园管理系统用户/组织数据定时同步到认证中间库,供第三方统一身份认证平台拉取。
## 目录结构
```
用户信息同步统一身份认证/
├── 3.在认证中间库建立表.sql # 第三方原始 Oracle 建表脚本(勿修改)
├── 建表脚本_mysql.sql # MySQL 适配建表脚本(本地测试用)
├── data.conf # 研发环境配置
├── data.conf.prod # 生产环境配置(Oracle 目标库)
├── create_tables.sh # 创建中间表
├── sync_user_to_sso.sh # 主同步脚本
├── verify_sync.sh # 同步结果校验
├── sync_sql/sync_all_mysql.sql # MySQL 同步 SQL
├── sync_oracle/merge_all.sql # Oracle MERGE 模板(生产)
├── 字段映射说明.md
└── logs/ # 运行日志(自动创建)
```
## 快速开始(研发环境)
```bash
cd 用户信息同步统一身份认证
# 1. 创建中间表(仅新增6张表,不修改已有表)
chmod +x *.sh
./create_tables.sh
# 2. 执行一次全量同步
./sync_user_to_sso.sh --full --once
# 3. 校验同步结果
./verify_sync.sh
```
## 定时运行
```bash
# 守护进程模式,默认每 3600 秒(1小时)同步一次
./sync_user_to_sso.sh
# 修改同步频率:编辑 data.conf 中 CYCLE_INTERVAL(秒)
```
## 生产部署
1. 复制 `data.conf.prod` 为 `data.conf` 或指定 `--config=data.conf.prod`
2. 填写源库(校园系统 MySQL)和目标库(认证中间库 Oracle)连接信息
3. 目标库使用第三方提供的 `3.在认证中间库建立表.sql` 在 Oracle 中建表
4. 确保服务器已安装 `sqlplus`(Oracle 客户端)
5. 使用 crontab 或 systemd 定时执行:
```bash
# crontab 示例:每小时执行一次
0 * * * * /path/to/用户信息同步统一身份认证/sync_user_to_sso.sh --once >> /path/to/logs/cron.log 2>&1
```
## 配置说明
| 配置项 | 说明 |
|--------|------|
| SOURCE_DB_* | 源库(校园管理系统,只读) |
| TARGET_DB_* | 目标库(认证中间库,读写) |
| TARGET_DB_TYPE | `mysql`(测试)或 `oracle`(生产) |
| SYNC_MODE | `full` 全量 / `incremental` 增量 |
| CYCLE_INTERVAL | 循环间隔秒数,默认 3600 |