Fresh start - excluded large ROM JSON files
This commit is contained in:
36
scripts/session-archive-weekly.py
Normal file
36
scripts/session-archive-weekly.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Session Archive Weekly
|
||||
Archives old session files from openclaw data directory.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
# Paths
|
||||
DATA_DIR = Path(os.environ.get("OPENCLAW_DATA", os.path.expanduser("~/.openclaw")))
|
||||
ARCHIVE_DIR = DATA_DIR / "workspace" / "memory" / "archive"
|
||||
|
||||
def archive_old_sessions():
|
||||
"""Archive session files older than 7 days."""
|
||||
ARCHIVE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
cutoff = datetime.now() - timedelta(days=7)
|
||||
archived_count = 0
|
||||
|
||||
# Archive old session logs if they exist
|
||||
session_dir = DATA_DIR / "sessions"
|
||||
if session_dir.exists():
|
||||
for f in session_dir.glob("**/*.json"):
|
||||
if datetime.fromtimestamp(f.stat().st_mtime) < cutoff:
|
||||
dest = ARCHIVE_DIR / f.name
|
||||
if not dest.exists():
|
||||
shutil.copy2(f, dest)
|
||||
archived_count += 1
|
||||
|
||||
print(f"Archived {archived_count} old session files")
|
||||
return archived_count
|
||||
|
||||
if __name__ == "__main__":
|
||||
count = archive_old_sessions()
|
||||
print(f"[OK] Weekly archive complete - {count} files archived")
|
||||
Reference in New Issue
Block a user