Spaces:
Paused
Paused
initial deploy
Browse files- Dockerfile +21 -21
Dockerfile
CHANGED
|
@@ -24,38 +24,38 @@ ENV PORT=7860 \
|
|
| 24 |
HOME=/root
|
| 25 |
|
| 26 |
# 6. Python 同步引擎 (sync.py)
|
| 27 |
-
RUN echo
|
| 28 |
from huggingface_hub import HfApi, hf_hub_download\n\
|
| 29 |
from datetime import datetime, timedelta\n\
|
| 30 |
api = HfApi()\n\
|
| 31 |
-
repo_id = os.getenv("HF_DATASET")\n\
|
| 32 |
-
token = os.getenv("HF_TOKEN")\n\
|
| 33 |
def restore():\n\
|
| 34 |
try:\n\
|
| 35 |
-
files = api.list_repo_files(repo_id=repo_id, repo_type="dataset", token=token)\n\
|
| 36 |
now = datetime.now()\n\
|
| 37 |
for i in range(5):\n\
|
| 38 |
-
day = (now - timedelta(days=i)).strftime("%Y-%m-%d")\n\
|
| 39 |
-
name = f"backup_{day}.tar.gz"\n\
|
| 40 |
if name in files:\n\
|
| 41 |
-
path = hf_hub_download(repo_id=repo_id, filename=name, repo_type="dataset", token=token)\n\
|
| 42 |
-
with tarfile.open(path, "r:gz") as tar: tar.extractall(path="/root/.openclaw/")\n\
|
| 43 |
-
print(f"Success: Restored from {name}")\n\
|
| 44 |
return True\n\
|
| 45 |
-
except Exception as e: print(f"Restore Error: {e}")\n\
|
| 46 |
def backup():\n\
|
| 47 |
try:\n\
|
| 48 |
-
day = datetime.now().strftime("%Y-%m-%d")\n\
|
| 49 |
-
name = f"backup_{day}.tar.gz"\n\
|
| 50 |
-
with tarfile.open(name, "w:gz") as tar:\n\
|
| 51 |
-
if os.path.exists("/root/.openclaw/sessions"): tar.add("/root/.openclaw/sessions", arcname="sessions")\n\
|
| 52 |
-
tar.add("/root/.openclaw/openclaw.json", arcname="openclaw.json")\n\
|
| 53 |
-
api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type="dataset", token=token)\n\
|
| 54 |
-
print(f"Backup {name} Success.")\n\
|
| 55 |
-
except Exception as e: print(f"Backup Error: {e}")\n\
|
| 56 |
-
if __name__ == "__main__":\n\
|
| 57 |
-
if len(sys.argv) > 1 and sys.argv[1] == "backup": backup()\n\
|
| 58 |
-
else: restore()
|
| 59 |
|
| 60 |
# 7. 启动控制逻辑
|
| 61 |
RUN echo "#!/bin/bash\n\
|
|
|
|
| 24 |
HOME=/root
|
| 25 |
|
| 26 |
# 6. Python 同步引擎 (sync.py)
|
| 27 |
+
RUN echo "import os, sys, tarfile\n\
|
| 28 |
from huggingface_hub import HfApi, hf_hub_download\n\
|
| 29 |
from datetime import datetime, timedelta\n\
|
| 30 |
api = HfApi()\n\
|
| 31 |
+
repo_id = os.getenv(\"HF_DATASET\")\n\
|
| 32 |
+
token = os.getenv(\"HF_TOKEN\")\n\
|
| 33 |
def restore():\n\
|
| 34 |
try:\n\
|
| 35 |
+
files = api.list_repo_files(repo_id=repo_id, repo_type=\"dataset\", token=token)\n\
|
| 36 |
now = datetime.now()\n\
|
| 37 |
for i in range(5):\n\
|
| 38 |
+
day = (now - timedelta(days=i)).strftime(\"%Y-%m-%d\")\n\
|
| 39 |
+
name = f\"backup_{day}.tar.gz\"\n\
|
| 40 |
if name in files:\n\
|
| 41 |
+
path = hf_hub_download(repo_id=repo_id, filename=name, repo_type=\"dataset\", token=token)\n\
|
| 42 |
+
with tarfile.open(path, \"r:gz\") as tar: tar.extractall(path=\"/root/.openclaw/\")\n\
|
| 43 |
+
print(f\"Success: Restored from {name}\")\n\
|
| 44 |
return True\n\
|
| 45 |
+
except Exception as e: print(f\"Restore Error: {e}\")\n\
|
| 46 |
def backup():\n\
|
| 47 |
try:\n\
|
| 48 |
+
day = datetime.now().strftime(\"%Y-%m-%d\")\n\
|
| 49 |
+
name = f\"backup_{day}.tar.gz\"\n\
|
| 50 |
+
with tarfile.open(name, \"w:gz\") as tar:\n\
|
| 51 |
+
if os.path.exists(\"/root/.openclaw/sessions\"): tar.add(\"/root/.openclaw/sessions\", arcname=\"sessions\")\n\
|
| 52 |
+
tar.add(\"/root/.openclaw/openclaw.json\", arcname=\"openclaw.json\")\n\
|
| 53 |
+
api.upload_file(path_or_fileobj=name, path_in_repo=name, repo_id=repo_id, repo_type=\"dataset\", token=token)\n\
|
| 54 |
+
print(f\"Backup {name} Success.\")\n\
|
| 55 |
+
except Exception as e: print(f\"Backup Error: {e}\")\n\
|
| 56 |
+
if __name__ == \"__main__\":\n\
|
| 57 |
+
if len(sys.argv) > 1 and sys.argv[1] == \"backup\": backup()\n\
|
| 58 |
+
else: restore()" > /usr/local/bin/sync.py
|
| 59 |
|
| 60 |
# 7. 启动控制逻辑
|
| 61 |
RUN echo "#!/bin/bash\n\
|