chore: docs 结构整改 + compose 双目录对齐(合并重建提交)
本提交为 .git 对象库损坏后的重建提交,内容等价于原先三个本地提交 (5e2fd4c2 / 57a53c98 / 5d7e1873)的累积结果,未做任何额外改动。 一、docs 结构整改(整改 #14) 根因:重构时新结构为 untracked 文件,执行 git stash(未带 -u)未纳入, 随后 git reset 拉回 HEAD 旧 tracked 树,导致旧树复活、新旧两棵目录 树并存于 docs/,共 791 文件、双分类体系冲突。 修复动作: - b2 同名异主题文件改名迁移保全 9 个 - C 类 39 个孤立文件按主题正确归类 - A/B1 类 222 个重复文件删除(新结构已有内容副本) - 9 个旧独有空目录删除 - 270 处内部引用按 verified 映射改写 - 整改记录 #14 登记于 04-运维文档/部署运维 结果:docs 791 → 569 文件,顶层仅规范 8 类 + 治理文件,单树恢复。 残留:约 20 处指向从未存在文件的陈旧死链,归入独立文档卫生任务。 二、compose 双目录对齐(消除踩坑 A) - docker-compose.yml:nginx 前端挂载全部由根目录 frontend-*/dist 改为 src/frontend-*/dist(h5 / agent / admin / terminal) - docker-compose.dev.yml:dev 服务 build context 与卷同步改 src/ - 效果:本地 docker compose up 不再把根目录 stale dist 挂回, 与线上一致,分叉隐患消除(已 docker compose config 校验通过) 防复发铁律: - 重构须提交;仓库修复须 git stash -u 或先 commit - 新结构须 git add 并提交,避免再次 untracked 复活 - H5 改动只动 src/frontend-h5/,禁改根目录遗留 frontend-*/
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
快速 base64 上传脚本 — 大分块版本(已废弃)
|
||||
将本地文件通过 JumpServer PTY base64 通道上传到远程服务器
|
||||
使用 8000 字符/块(远大于 jms_ops.py 的 500 字符),大幅减少命令数
|
||||
|
||||
⚠️ 此脚本已废弃,请使用 jumpserver-V2 的 v2_ops.py upload 命令(psftp 通道)
|
||||
"""
|
||||
import sys
|
||||
import base64
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
# 添加 jms_ops.py 所在目录
|
||||
SKILL_DIR = Path(r"C:\Users\simon\.workbuddy\skills\jumpserver-ops\scripts")
|
||||
sys.path.insert(0, str(SKILL_DIR))
|
||||
|
||||
# 导入 jms_ops 中的核心函数
|
||||
from jms_ops import get_connection_tokens, PlinkSession
|
||||
|
||||
|
||||
def fast_upload(local_path: str, remote_path: str, chunk_size: int = 8000):
|
||||
"""大分块 base64 上传"""
|
||||
local_file = Path(local_path)
|
||||
if not local_file.exists():
|
||||
print(f"ERROR: file not found: {local_path}")
|
||||
return False
|
||||
|
||||
local_data = local_file.read_bytes()
|
||||
local_md5 = hashlib.md5(local_data).hexdigest()
|
||||
b64_data = base64.b64encode(local_data).decode("ascii")
|
||||
|
||||
# 分块
|
||||
chunks = [b64_data[i:i+chunk_size] for i in range(0, len(b64_data), chunk_size)]
|
||||
total_chunks = len(chunks)
|
||||
|
||||
print(f"File: {local_file.name}")
|
||||
print(f"Size: {len(local_data)} bytes")
|
||||
print(f"Base64: {len(b64_data)} chars")
|
||||
print(f"Chunks: {total_chunks} x {chunk_size} chars")
|
||||
print(f"MD5: {local_md5}")
|
||||
print(f"Target: {remote_path}")
|
||||
print()
|
||||
|
||||
# 获取 token + 启动会话
|
||||
tokens = get_connection_tokens(1)
|
||||
if not tokens:
|
||||
print("ERROR: failed to get connection tokens")
|
||||
return False
|
||||
|
||||
token_id, token_secret = tokens[0]
|
||||
session = PlinkSession(f"JMS-{token_id}", token_secret)
|
||||
if not session.connect():
|
||||
print("ERROR: failed to connect session")
|
||||
return False
|
||||
|
||||
try:
|
||||
# 1. 清空目标文件
|
||||
print("Clearing target file...")
|
||||
session.run_command(f"> {remote_path}", timeout=5)
|
||||
|
||||
# 2. 逐块追加
|
||||
for i, chunk in enumerate(chunks):
|
||||
# 用 printf 避免 echo 的换行符问题
|
||||
cmd = f"printf '%s' '{chunk}' >> {remote_path}.b64"
|
||||
r = session.run_command(cmd, timeout=10)
|
||||
if not r["success"]:
|
||||
print(f" FAIL chunk {i+1}/{total_chunks}")
|
||||
return False
|
||||
|
||||
# 进度报告
|
||||
if (i+1) % 20 == 0 or (i+1) == total_chunks:
|
||||
pct = (i+1) * 100 // total_chunks
|
||||
print(f" [{pct:3d}%] chunk {i+1}/{total_chunks}")
|
||||
|
||||
# 3. base64 解码
|
||||
print(f"\nDecoding base64 -> {remote_path}...")
|
||||
r = session.run_command(f"base64 -d {remote_path}.b64 > {remote_path}", timeout=30)
|
||||
if not r["success"]:
|
||||
print(f" WARN decode result: {r}")
|
||||
|
||||
# 4. 验证大小
|
||||
print("Verifying size...")
|
||||
r = session.run_command(f"wc -c < {remote_path}", timeout=5)
|
||||
if r["success"]:
|
||||
remote_size_str = r["output"].strip()
|
||||
remote_size = int(remote_size_str) if remote_size_str.isdigit() else -1
|
||||
if remote_size == len(local_data):
|
||||
print(f" OK size match: {remote_size} bytes")
|
||||
else:
|
||||
print(f" SIZE MISMATCH: local={len(local_data)}, remote={remote_size}")
|
||||
return False
|
||||
else:
|
||||
print(f" WARN cannot verify size: {r}")
|
||||
return True # 仍然认为成功
|
||||
|
||||
# 5. MD5 验证
|
||||
print("Verifying MD5...")
|
||||
r = session.run_command(f"md5sum {remote_path}", timeout=10)
|
||||
if r["success"]:
|
||||
remote_md5 = r["output"].split()[0]
|
||||
if remote_md5 == local_md5:
|
||||
print(f" OK MD5 match: {remote_md5}")
|
||||
else:
|
||||
print(f" MD5 MISMATCH: local={local_md5}, remote={remote_md5}")
|
||||
# 大小匹配但 MD5 不匹配,可能是 PTY 换行符问题
|
||||
print(" (size matches, trying gzip test instead)")
|
||||
r2 = session.run_command(f"gzip -t {remote_path} 2>&1 && echo GZIP_OK || echo GZIP_FAIL", timeout=10)
|
||||
if r2["success"] and "GZIP_OK" in r2["output"]:
|
||||
print(" OK gzip integrity test passed")
|
||||
# 清理临时文件
|
||||
session.run_command(f"rm -f {remote_path}.b64", timeout=5)
|
||||
return True
|
||||
else:
|
||||
print(f" GZIP FAIL: {r2}")
|
||||
return False
|
||||
else:
|
||||
print(f" WARN cannot verify MD5")
|
||||
|
||||
# 6. 清理临时文件
|
||||
session.run_command(f"rm -f {remote_path}.b64", timeout=5)
|
||||
print("\nUpload complete!")
|
||||
return True
|
||||
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description="Fast base64 upload via JumpServer PTY")
|
||||
parser.add_argument("local", help="Local file path")
|
||||
parser.add_argument("remote", help="Remote file path")
|
||||
parser.add_argument("--chunk-size", type=int, default=8000, help="Chunk size in chars (default: 8000)")
|
||||
args = parser.parse_args()
|
||||
|
||||
success = fast_upload(args.local, args.remote, args.chunk_size)
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user