Files
order-bak/README.md
tech 3d40a44d91 docs: add README
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 16:59:46 +08:00

86 lines
1.6 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.
# order-bak
订单备份 CLI 工具。从 Azure Table 扫描订单数据,按时间范围备份到 CSV并支持从生产表中删除已备份记录。
## 安装
```bash
uv tool install .
```
## 配置
创建 `~/.config/order-bak/config.toml`
```toml
[azure]
connection_string = "DefaultEndpointsProtocol=..."
[scan]
page_size = 500 # 每页行数
delay_ms = 200 # 页间延迟 (ms)
scan_dir = "./scan"
[delete]
batch_size = 100 # 每批删除行数
delay_ms = 300 # 批间延迟 (ms)
```
`[azure]` 为必填项,其余有默认值。
## 使用
### 1. 扫描全表
```bash
order-bak scan
```
全量扫描 `order` 表,结果保存到 `scan/scan-<date>.csv`
### 2. 按日期备份
```bash
order-bak backup --start 2025-01-01 --end 2025-06-30
```
从最新的 scan CSV 中筛选 `state == Recived``OrderTime``[start, end)` 范围内的订单,按日期生成独立 CSV 到 `backups/` 目录。
可选指定 scan 文件:`--scan scan/scan-2025-01-01.csv`
### 3. 删除已备份记录
```bash
order-bak delete --csv backups/2025-01-01.csv
```
读取 CSV 中的记录,按分区分批从 Azure Table 中删除。执行前需确认。
## 目录结构
```
scan/
└── scan-2025-06-01.csv # 全表扫描结果
backups/
├── 2025-01-01.csv # 按日期的备份
├── 2025-01-02.csv
└── ...
```
## 开发
```bash
# 安装依赖
uv sync --group dev
# 单元测试
uv run pytest tests/ -v -m "not integration"
# 集成测试(需要 Azure Storage Emulator
uv run pytest tests/test_integration.py -v
# 初始化测试数据
uv run python scripts/seed_test_data.py
```