ThongCoder commited on
Commit
e98a793
·
verified ·
1 Parent(s): c3761c9

Delete autobackup.py

Browse files
Files changed (1) hide show
  1. autobackup.py +0 -51
autobackup.py DELETED
@@ -1,51 +0,0 @@
1
- import os, subprocess, time, threading
2
-
3
- def run_backup():
4
- repo_id = os.environ.get("BACKUP_REPO")
5
- hf_token = os.environ.get("HF_TOKEN")
6
- repo_type = "space" if "/" in repo_id else "dataset" # auto-detect
7
-
8
- if not repo_id or not hf_token:
9
- print("❌ BACKUP_REPO or HF_TOKEN missing, skipping backup")
10
- return
11
-
12
- env = os.environ.copy()
13
- env["HF_HOME"] = "/tmp/hf_cache"
14
- env["XDG_CACHE_HOME"] = "/tmp/xdg_cache"
15
- env["TMPDIR"] = "/tmp"
16
-
17
- os.makedirs(env["HF_HOME"], exist_ok=True)
18
- os.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)
19
- os.makedirs(env["TMPDIR"], exist_ok=True)
20
-
21
- local_path = "/workspace"
22
-
23
- cmd = [
24
- "hf", "upload",
25
- repo_id,
26
- local_path,
27
- "--repo-type", repo_type,
28
- "--token", hf_token,
29
- ]
30
-
31
- process = subprocess.Popen(
32
- cmd,
33
- stdout=subprocess.PIPE,
34
- stderr=subprocess.STDOUT,
35
- env=env,
36
- text=True,
37
- cwd="/tmp",
38
- )
39
-
40
- for line in iter(process.stdout.readline, ''):
41
- print("🔄", line.strip())
42
-
43
- def schedule_backups():
44
- while True:
45
- print("⏳ Running auto-backup...")
46
- run_backup()
47
- print("✅ Backup finished, sleeping 45m...")
48
- time.sleep(45 * 60)
49
-
50
- # Run in background
51
- threading.Thread(target=schedule_backups, daemon=True).start()