Files
easyai/scripts/backup-deployment-config.py
T
wangbo b99eb849b4
Test deployment public URL (Linux) / test-linux (push) Waiting to run
Test start.ps1 (Windows) / test-windows (push) Waiting to run
fix(deploy): 修复组件版本解析和安装升级验收流程
2026-10-18 00:18:00 +08:00

27 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Preserve deployment configuration before migrations; this is not a database backup."""
from datetime import datetime, timezone
import hashlib
import json
import os
from pathlib import Path
import shutil
import tempfile
root = Path.cwd()
os.umask(0o077)
parent = root / 'data/deployment-backups'
parent.mkdir(parents=True, exist_ok=True)
backup = Path(tempfile.mkdtemp(prefix='update-' + datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%SZ-'), dir=parent))
files = list(root.glob('.env*')) + [root / name for name in ('docker-compose.yml', 'docker-compose.override.yml', 'compose.override.yaml')]
records = []
for source in files:
if not source.is_file() or source.name.endswith('.sample'):
continue
target = backup / source.name
shutil.copyfile(source, target)
target.chmod(0o600)
records.append({'file': source.name, 'sha256': hashlib.sha256(target.read_bytes()).hexdigest()})
(backup / 'backup.json').write_text(json.dumps({'kind': 'deployment-config-only', 'files': records}, indent=2) + '\n')
print('已备份升级前配置(不含数据库):' + str(backup))