Spaces:
Sleeping
Sleeping
Delete sync.py
Browse files
sync.py
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
import os, time, threading, shutil
|
| 2 |
-
from huggingface_hub import HfApi, snapshot_download
|
| 3 |
-
|
| 4 |
-
HERMES_CONFIG = {"/root/.hermes": "hermes_settings"}
|
| 5 |
-
|
| 6 |
-
IGNORE_LIST = ["*.db-shm", "*.db-wal", "models_dev_cache.json", "checkpoints/*", "*.pyc", "__pycache__", "hermes-agent/venv", "hermes-agent/.git", "logs/*", "cache/*", "*.pid", "*.lock","tmp/*","*.tmp", "__pycache__/*", "*.log.lock", "node_modules/*", "pkg/*", ".cache/*", ".npm/*","backup/*"]
|
| 7 |
-
|
| 8 |
-
DATASET_ID, HF_TOKEN = os.getenv("DATASET_ID"), os.getenv("HF_TOKEN")
|
| 9 |
-
api = HfApi()
|
| 10 |
-
|
| 11 |
-
def upload_all():
|
| 12 |
-
if not DATASET_ID or not HF_TOKEN: return
|
| 13 |
-
# 备份Hermes数据
|
| 14 |
-
print(f"🚀 正在备份Hermes数据...")
|
| 15 |
-
for local_path, repo_path in HERMES_CONFIG.items():
|
| 16 |
-
if os.path.exists(local_path):
|
| 17 |
-
try:
|
| 18 |
-
api.upload_folder(folder_path=local_path, path_in_repo=repo_path,
|
| 19 |
-
repo_id=DATASET_ID, repo_type="dataset", token=HF_TOKEN,
|
| 20 |
-
delete_patterns="*", ignore_patterns=IGNORE_LIST)
|
| 21 |
-
print(f"✅ {repo_path} 备份成功")
|
| 22 |
-
except Exception as e: print(f"❌ Hermes备份翻车: {e}")
|
| 23 |
-
|
| 24 |
-
def download_all():
|
| 25 |
-
if not DATASET_ID or not HF_TOKEN: return
|
| 26 |
-
# 恢复Hermes数据
|
| 27 |
-
print("📥 正在恢复Hermes数据...")
|
| 28 |
-
for local_path, repo_path in HERMES_CONFIG.items():
|
| 29 |
-
try:
|
| 30 |
-
temp_dir = f"/tmp/hf_{repo_path}"
|
| 31 |
-
os.makedirs(local_path, exist_ok=True)
|
| 32 |
-
snapshot_download(repo_id=DATASET_ID, repo_type="dataset", local_dir=temp_dir,
|
| 33 |
-
allow_patterns=f"{repo_path}/*", token=HF_TOKEN, local_dir_use_symlinks=False)
|
| 34 |
-
source_dir = os.path.join(temp_dir, repo_path)
|
| 35 |
-
if os.path.exists(source_dir):
|
| 36 |
-
for item in os.listdir(source_dir):
|
| 37 |
-
s, d = os.path.join(source_dir, item), os.path.join(local_path, item)
|
| 38 |
-
if os.path.isdir(s):
|
| 39 |
-
if os.path.exists(d): shutil.rmtree(d)
|
| 40 |
-
shutil.copytree(s, d)
|
| 41 |
-
else: shutil.copy2(s, d)
|
| 42 |
-
shutil.rmtree(temp_dir, ignore_errors=True)
|
| 43 |
-
print(f"✅ {local_path} 恢复成功")
|
| 44 |
-
except Exception as e: print(f"ℹ️ {repo_path} 恢复跳过")
|
| 45 |
-
|
| 46 |
-
if __name__ == "__main__":
|
| 47 |
-
threading.Thread(target=lambda: [time.sleep(600) or upload_all() for _ in iter(int, 1)], daemon=True).start()
|
| 48 |
-
while True: time.sleep(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|