tech c4290b830e refactor: read config from file, randomize users and dates in seed script
Replace hardcoded connection string with config file loading via
load_config(). Users now randomly chosen from user001-user1000, dates
randomly sampled between 2026-01-01 and UTC now.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 00:04:32 +08:00
2026-04-21 16:59:46 +08:00

order-bak

订单备份 CLI 工具。从 Azure Table 扫描订单数据,按时间范围备份到 CSV并支持从生产表中删除已备份记录。

安装

uv tool install .

配置

创建 ~/.config/order-bak/config.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. 扫描全表

order-bak scan

全量扫描 order 表,结果保存到 scan/scan-<date>.csv

2. 按日期备份

order-bak backup --start 2025-01-01 --end 2025-06-30

从最新的 scan CSV 中筛选 state == RecivedOrderTime[start, end) 范围内的订单,按日期生成独立 CSV 到 backups/ 目录。

可选指定 scan 文件:--scan scan/scan-2025-01-01.csv

3. 删除已备份记录

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
└── ...

开发

# 安装依赖
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
Description
No description provided
Readme 140 KiB
Languages
Python 97.6%
Shell 2.4%