nbugs commited on
Commit
2ebc237
·
verified ·
1 Parent(s): 5d5cd66

Update sync_data.sh

Browse files
Files changed (1) hide show
  1. sync_data.sh +13 -13
sync_data.sh CHANGED
@@ -72,36 +72,36 @@ except Exception as e:
72
  done
73
  }
74
 
75
- # 恢复函数
76
  restore_latest() {
77
  echo "Attempting to restore latest backup..."
78
  python3 -c "
 
 
 
79
  try:
80
- from huggingface_hub import HfApi
81
- import os
82
-
83
  api = HfApi()
84
  files = api.list_repo_files('${DATASET_ID}', repo_type='dataset')
85
  backup_files = [f for f in files if f.startswith('backup_') and f.endswith('.tar.gz')]
86
-
87
  if backup_files:
88
- latest = sorted(backup_files)[-1]
89
  api.hf_hub_download(
90
- repo_id='${DATASET_ID}',
91
- filename=latest,
92
- repo_type='dataset',
93
- local_dir='/tmp'
94
  )
95
  os.system(f'tar -xzf /tmp/{latest} -C /app')
96
- os.remove(f'/tmp/{latest}')
97
- print(f'Restored from {latest}')
98
  else:
99
- print('No backup found')
100
  except Exception as e:
101
  print(f'Restore failed: {str(e)}')
102
  "
103
  }
104
 
 
105
  # 主程序
106
  (
107
  # 安装huggingface_hub库
 
72
  done
73
  }
74
 
 
75
  restore_latest() {
76
  echo "Attempting to restore latest backup..."
77
  python3 -c "
78
+ from huggingface_hub import HfApi
79
+ import os
80
+
81
  try:
 
 
 
82
  api = HfApi()
83
  files = api.list_repo_files('${DATASET_ID}', repo_type='dataset')
84
  backup_files = [f for f in files if f.startswith('backup_') and f.endswith('.tar.gz')]
85
+
86
  if backup_files:
87
+ latest = sorted(backup_files)[-1]
88
  api.hf_hub_download(
89
+ repo_id='${DATASET_ID}',
90
+ filename=latest,
91
+ repo_type='dataset',
92
+ local_dir='/tmp'
93
  )
94
  os.system(f'tar -xzf /tmp/{latest} -C /app')
95
+ os.remove(f'/tmp/{latest}')
96
+ print(f'Restored from {latest}')
97
  else:
98
+ print('No backup found')
99
  except Exception as e:
100
  print(f'Restore failed: {str(e)}')
101
  "
102
  }
103
 
104
+
105
  # 主程序
106
  (
107
  # 安装huggingface_hub库