- 제품 3단계분류.md: 성분→제품→로트 분류 체계, AI display_name 채우기 절차 - reset_operational_data.py: 마스터 보존 + 운영 데이터 초기화 - restore_backup.py: 백업 선택 복원 스크립트 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
백업 DB 복원 스크립트
|
|
- 백업 파일에서 운영 DB로 복원
|
|
|
|
실행: python3 scripts/restore_backup.py
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import glob
|
|
from datetime import datetime
|
|
|
|
DB_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'database')
|
|
DB_PATH = os.path.join(DB_DIR, 'kdrug.db')
|
|
|
|
|
|
def list_backups():
|
|
"""사용 가능한 백업 파일 목록"""
|
|
pattern = os.path.join(DB_DIR, 'kdrug_backup*.db')
|
|
backups = sorted(glob.glob(pattern), key=os.path.getmtime, reverse=True)
|
|
return backups
|
|
|
|
|
|
def restore():
|
|
backups = list_backups()
|
|
|
|
if not backups:
|
|
print("사용 가능한 백업 파일이 없습니다.")
|
|
return
|
|
|
|
print("=" * 50)
|
|
print("사용 가능한 백업 파일")
|
|
print("=" * 50)
|
|
for i, path in enumerate(backups):
|
|
size_mb = os.path.getsize(path) / (1024 * 1024)
|
|
mtime = datetime.fromtimestamp(os.path.getmtime(path)).strftime('%Y-%m-%d %H:%M:%S')
|
|
name = os.path.basename(path)
|
|
print(f" [{i + 1}] {name} ({size_mb:.1f}MB, {mtime})")
|
|
|
|
print()
|
|
choice = input(f"복원할 백업 번호를 선택하세요 (1-{len(backups)}): ").strip()
|
|
|
|
try:
|
|
idx = int(choice) - 1
|
|
if idx < 0 or idx >= len(backups):
|
|
print("잘못된 번호입니다.")
|
|
return
|
|
except ValueError:
|
|
print("숫자를 입력하세요.")
|
|
return
|
|
|
|
selected = backups[idx]
|
|
print()
|
|
print(f"선택: {os.path.basename(selected)}")
|
|
confirm = input("현재 DB를 덮어쓰고 복원합니다. 계속하시겠습니까? (yes/no): ").strip().lower()
|
|
|
|
if confirm != 'yes':
|
|
print("취소되었습니다.")
|
|
return
|
|
|
|
# 현재 DB를 복원 전 백업
|
|
pre_restore = os.path.join(DB_DIR, f"kdrug_pre_restore_{datetime.now().strftime('%Y%m%d_%H%M%S')}.db")
|
|
shutil.copy2(DB_PATH, pre_restore)
|
|
print(f" 복원 전 현재 DB 백업 → {os.path.basename(pre_restore)}")
|
|
|
|
# 복원
|
|
shutil.copy2(selected, DB_PATH)
|
|
print(f" {os.path.basename(selected)} → kdrug.db 복원 완료")
|
|
|
|
print()
|
|
print("복원 완료! 앱을 재시작하세요.")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
restore()
|