Update sync_data.sh
Browse files- sync_data.sh +5 -4
sync_data.sh
CHANGED
|
@@ -10,7 +10,7 @@ fi
|
|
| 10 |
# 激活虚拟环境
|
| 11 |
. /opt/venv/bin/activate
|
| 12 |
|
| 13 |
-
#
|
| 14 |
manage_backups() {
|
| 15 |
python3 -c "
|
| 16 |
from huggingface_hub import HfApi
|
|
@@ -19,9 +19,10 @@ try:
|
|
| 19 |
files = api.list_repo_files(repo_id='$DATASET_ID', repo_type='dataset')
|
| 20 |
backup_files = sorted([f for f in files if f.startswith('electerm_backup_') and f.endswith('.tar.gz')])
|
| 21 |
backup_count = int('$DATASET_N') if '$DATASET_N'.isdigit() else 5
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
print(f'Error managing backups: {str(e)}')
|
| 27 |
"
|
|
|
|
| 10 |
# 激活虚拟环境
|
| 11 |
. /opt/venv/bin/activate
|
| 12 |
|
| 13 |
+
# 备份管理函数(删除旧备份并重置 Git 历史)
|
| 14 |
manage_backups() {
|
| 15 |
python3 -c "
|
| 16 |
from huggingface_hub import HfApi
|
|
|
|
| 19 |
files = api.list_repo_files(repo_id='$DATASET_ID', repo_type='dataset')
|
| 20 |
backup_files = sorted([f for f in files if f.startswith('electerm_backup_') and f.endswith('.tar.gz')])
|
| 21 |
backup_count = int('$DATASET_N') if '$DATASET_N'.isdigit() else 5
|
| 22 |
+
if len(backup_files) > backup_count:
|
| 23 |
+
for file in backup_files[:-backup_count]:
|
| 24 |
+
api.delete_file(path_in_repo=file, repo_id='$DATASET_ID', repo_type='dataset')
|
| 25 |
+
print(f'Deleted old backup: {file}')
|
| 26 |
except Exception as e:
|
| 27 |
print(f'Error managing backups: {str(e)}')
|
| 28 |
"
|