Files
012-kaopeilian/backend/scripts/rollback_example.py
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

84 lines
3.2 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.
#!/usr/bin/env python3
"""
考培练系统 - 数据库回滚工具使用示例
演示如何使用回滚工具进行常见的数据恢复操作
"""
import asyncio
import sys
from pathlib import Path
# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from scripts.kaopeilian_rollback import KaopeilianRollbackTool
async def demo_rollback_tools():
"""演示回滚工具的使用"""
print("🔧 考培练系统 - 数据库回滚工具演示")
print("=" * 60)
tool = KaopeilianRollbackTool()
try:
await tool.connect()
print("\n1⃣ 查看最近24小时的数据变更")
print("-" * 40)
await tool.list_recent_changes(24)
print("\n2⃣ 演示用户回滚(模拟)")
print("-" * 40)
print("命令示例:")
print("python scripts/kaopeilian_rollback.py --rollback-user 123 --operation-type delete")
print("python scripts/kaopeilian_rollback.py --rollback-user 123 --operation-type delete --execute")
print("\n3⃣ 演示课程回滚(模拟)")
print("-" * 40)
print("命令示例:")
print("python scripts/kaopeilian_rollback.py --rollback-course 456 --operation-type delete")
print("python scripts/kaopeilian_rollback.py --rollback-course 456 --operation-type delete --execute")
print("\n4⃣ 演示考试回滚(模拟)")
print("-" * 40)
print("命令示例:")
print("python scripts/kaopeilian_rollback.py --rollback-exam 789")
print("python scripts/kaopeilian_rollback.py --rollback-exam 789 --execute")
print("\n5⃣ 演示时间点回滚")
print("-" * 40)
print("命令示例:")
print("python scripts/simple_rollback.py --time '2024-12-20 10:30:00'")
print("python scripts/simple_rollback.py --time '2024-12-20 10:30:00' --execute")
print("\n6⃣ 查看Binlog文件")
print("-" * 40)
print("命令示例:")
print("python scripts/simple_rollback.py --list")
print("python scripts/binlog_rollback_tool.py --list-binlogs")
print("\n📋 回滚工具总结")
print("-" * 40)
print("✅ 专用工具kaopeilian_rollback.py - 业务场景回滚")
print("✅ 简化工具simple_rollback.py - 时间点回滚")
print("✅ 完整工具binlog_rollback_tool.py - 复杂Binlog回滚")
print("✅ 配置优化mysql-rollback.cnf - MySQL回滚优化")
print("✅ 文档指南database_rollback_guide.md - 完整操作指南")
print("\n⚠️ 安全提醒")
print("-" * 40)
print("• 回滚操作不可逆,务必谨慎执行")
print("• 生产环境回滚前必须在测试环境验证")
print("• 重要操作需要多人确认")
print("• 保留回滚操作日志和备份文件")
except Exception as e:
print(f"❌ 演示过程中出现错误: {e}")
finally:
await tool.close()
if __name__ == "__main__":
asyncio.run(demo_rollback_tools())