Surreal-Sync -- Data Migration and Synchronization
Surreal-Sync is a CLI tool for migrating data from various database sources to
SurrealDB with full and incremental synchronization via Change Data Capture (CDC).
Supported Sources
| Source | Full Sync | Incremental CDC | Method |
|---|
| MongoDB | Yes | Yes | Change streams |
| MySQL |
Yes | Yes | Trigger-based CDC + sequence checkpoints |
| PostgreSQL (triggers) | Yes | Yes | Trigger-based CDC + sequence checkpoints |
| PostgreSQL (wal2json) | Yes | Yes | Logical replication with wal2json plugin |
| Neo4j | Yes | Yes | Timestamp-based tracking |
| JSONL Files | Yes | N/A | Batch import from JSON Lines |
| Apache Kafka | Yes | Yes | Consumer subscriptions with deduplication |
Quick Start
CODEBLOCK0
CLI Pattern
CODEBLOCK1
Key Features
- - Automatic schema inference and SurrealDB table creation
- Record ID mapping from source primary keys
- Relationship extraction and graph edge creation
- Configurable batch sizes and parallelism
- Resumable sync with checkpoint tracking
- Deduplication for Kafka consumers
Full Documentation
See the main skill's rule file for complete guidance:
Surreal-Sync —— 数据迁移与同步
Surreal-Sync 是一款命令行工具,用于将数据从多种数据库源迁移至 SurrealDB,支持通过变更数据捕获(CDC)实现全量同步与增量同步。
支持的源
| 源 | 全量同步 | 增量CDC | 方法 |
|---|
| MongoDB | 是 | 是 | 变更流 |
| MySQL |
是 | 是 | 基于触发器的CDC + 序列检查点 |
| PostgreSQL(触发器) | 是 | 是 | 基于触发器的CDC + 序列检查点 |
| PostgreSQL(wal2json) | 是 | 是 | 基于wal2json插件的逻辑复制 |
| Neo4j | 是 | 是 | 基于时间戳的追踪 |
| JSONL文件 | 是 | 不适用 | 从JSON Lines批量导入 |
| Apache Kafka | 是 | 是 | 带去重的消费者订阅 |
快速开始
bash
安装 surreal-sync(Rust 二进制文件)
cargo install surreal-sync
从 PostgreSQL 全量同步(基于触发器)
surreal-sync from postgres trigger-full \
--connection-string postgresql://user:pass@localhost/mydb \
--surreal-endpoint http://localhost:8000 \
--surreal-username root \
--surreal-password root \
--to-namespace prod \
--to-database main
从 PostgreSQL 增量CDC(wal2json)
surreal-sync from postgres wal2json \
--connection-string postgresql://user:pass@localhost/mydb \
--surreal-endpoint http://localhost:8000 \
--surreal-username root \
--surreal-password root \
--to-namespace prod \
--to-database main
从 MongoDB 全量同步
surreal-sync from mongo full \
--connection-string mongodb://localhost:27017/mydb \
--surreal-endpoint http://localhost:8000 \
--surreal-username root \
--surreal-password root \
--to-namespace prod \
--to-database main
从 JSONL 批量导入
surreal-sync from jsonl import \
--file data.jsonl \
--surreal-endpoint http://localhost:8000 \
--surreal-username root \
--surreal-password root \
--to-namespace prod \
--to-database main
从 Kafka 消费
surreal-sync from kafka consume \
--bootstrap-servers localhost:9092 \
--topic my-events \
--surreal-endpoint http://localhost:8000 \
--surreal-username root \
--surreal-password root \
--to-namespace prod \
--to-database main
CLI 模式
surreal-sync from <源> <命令> \
--connection-string [连接字符串] \
--surreal-endpoint [SURREAL 端点] \
--surreal-username [SURREAL 用户名] \
--surreal-password [SURREAL 密码] \
--to-namespace <命名空间> \
--to-database <数据库>
主要特性
- - 自动模式推断与 SurrealDB 表创建
- 基于源主键的记录ID映射
- 关系提取与图边创建
- 可配置的批量大小与并行度
- 带检查点追踪的可恢复同步
- Kafka 消费者的去重功能
完整文档
请参阅主技能的规则文件以获取完整指导: