Spaces:
Paused
Paused
Update restore.py
Browse files19 unmodified lines20212223242526272829303132333435363738394041424344454647484950515253545556575859606162636419 unmodified linesos.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)os.makedirs(env["TMPDIR"], exist_ok=True)# Step 1: List repo filesprint("[Restore] Listing backups in repo...")result = subprocess.run(["hf", "ls-files", BACKUP_REPO, "--repo-type", "dataset"],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,text=True,env=env,)files = result.stdout.strip().splitlines()backups = [f for f in files if f.endswith(".tar.gz")]if not backups:print("[Restore] No backups found")exit(0)# Step 2: Pick latest (they’re timestamped)latest = sorted(backups)[-1]print(f"[Restore] Found latest backup: {latest}")# Step 3: Downloadtmpfile = os.path.join(tempfile.gettempdir(), "restore.tar.gz")subprocess.run(["hf", "download", BACKUP_REPO, latest, "--repo-type", "dataset", "--local-dir", "/tmp/restore", "--force"],check=True,env=env,)downloaded = os.path.join("/tmp/restore", latest)# Step 4: Extract into /home/vscodeprint("[Restore] Extracting backup...")if os.path.exists("/home/vscode"):shutil.rmtree("/home/vscode")os.makedirs("/home/vscode", exist_ok=True)subprocess.run(["tar", "-xzf", downloaded, "-C", "/"],check=True)print("[Restore] Completed")19 unmodified lines202122232425262728293019 unmodified linesos.makedirs(env["XDG_CACHE_HOME"], exist_ok=True)os.makedirs(env["TMPDIR"], exist_ok=True)subprocess.run(["hf", "download", BACKUP_REPO, "--repo-type", "dataset", "--local-dir", "/home/vscode/workspace", "--force", "--exclude", ".gitattributes", "--exclude", "*.md"],check=True,env=env,)print("[Restore] Completed")
restore.py+1-35