Update sync_data.sh
Browse files- sync_data.sh +7 -7
sync_data.sh
CHANGED
|
@@ -56,12 +56,12 @@ try:
|
|
| 56 |
api.upload_file(
|
| 57 |
path_or_fileobj='$file_path',
|
| 58 |
path_in_repo='$file_name',
|
| 59 |
-
repo_id='
|
| 60 |
repo_type='dataset'
|
| 61 |
)
|
| 62 |
print(f'Successfully uploaded $file_name')
|
| 63 |
|
| 64 |
-
manage_backups(api, '
|
| 65 |
except Exception as e:
|
| 66 |
print(f'Error uploading file: {str(e)}')
|
| 67 |
"
|
|
@@ -87,7 +87,7 @@ print(f'DATASET_ID is set: {os.environ.get(\"DATASET_ID\") is not None}')
|
|
| 87 |
api = HfApi(token='$token')
|
| 88 |
try:
|
| 89 |
print(f'Listing files in Dataset: {repo_id}')
|
| 90 |
-
files = api.list_repo_files(repo_id='
|
| 91 |
backup_files = [f for f in files if f.startswith('$BACKUP_PREFIX') and f.endswith('.tar.gz')]
|
| 92 |
|
| 93 |
if not backup_files:
|
|
@@ -99,7 +99,7 @@ try:
|
|
| 99 |
|
| 100 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 101 |
filepath = api.hf_hub_download(
|
| 102 |
-
repo_id='
|
| 103 |
filename=latest_backup,
|
| 104 |
repo_type='dataset',
|
| 105 |
local_dir=temp_dir
|
|
@@ -109,7 +109,7 @@ try:
|
|
| 109 |
print(f'Successfully downloaded backup to temporary directory: {filepath}')
|
| 110 |
print(\"Before restoring backup:\")
|
| 111 |
import subprocess
|
| 112 |
-
subprocess.run(['ls', '-l', \"$CLOUDREVE_DIR\"])
|
| 113 |
|
| 114 |
# 删除现有的 Cloudreve 目录和配置文件
|
| 115 |
import shutil
|
|
@@ -135,7 +135,7 @@ try:
|
|
| 135 |
print(f'Successfully restored backup from {latest_backup}')
|
| 136 |
|
| 137 |
print(\"After restoring backup:\")
|
| 138 |
-
subprocess.run(['ls', '-l', \"$CLOUDREVE_DIR\"])
|
| 139 |
else:
|
| 140 |
print('Error during file download.')
|
| 141 |
|
|
@@ -173,7 +173,7 @@ sync_data() {
|
|
| 173 |
upload_backup "$backup_path" "${backup_file}"
|
| 174 |
|
| 175 |
rm -f "$backup_path"
|
| 176 |
-
else
|
| 177 |
echo "Cloudreve directory does not exist yet, waiting for next sync..."
|
| 178 |
fi
|
| 179 |
|
|
|
|
| 56 |
api.upload_file(
|
| 57 |
path_or_fileobj='$file_path',
|
| 58 |
path_in_repo='$file_name',
|
| 59 |
+
repo_id=f'{repo_id}', # 使用 f-string 传递 repo_id
|
| 60 |
repo_type='dataset'
|
| 61 |
)
|
| 62 |
print(f'Successfully uploaded $file_name')
|
| 63 |
|
| 64 |
+
manage_backups(api, f'{repo_id}') # 使用 f-string 传递 repo_id
|
| 65 |
except Exception as e:
|
| 66 |
print(f'Error uploading file: {str(e)}')
|
| 67 |
"
|
|
|
|
| 87 |
api = HfApi(token='$token')
|
| 88 |
try:
|
| 89 |
print(f'Listing files in Dataset: {repo_id}')
|
| 90 |
+
files = api.list_repo_files(repo_id=f'{repo_id}', repo_type='dataset') # 使用 f-string 传递 repo_id
|
| 91 |
backup_files = [f for f in files if f.startswith('$BACKUP_PREFIX') and f.endswith('.tar.gz')]
|
| 92 |
|
| 93 |
if not backup_files:
|
|
|
|
| 99 |
|
| 100 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 101 |
filepath = api.hf_hub_download(
|
| 102 |
+
repo_id=f'{repo_id}', # 使用 f-string 传递 repo_id
|
| 103 |
filename=latest_backup,
|
| 104 |
repo_type='dataset',
|
| 105 |
local_dir=temp_dir
|
|
|
|
| 109 |
print(f'Successfully downloaded backup to temporary directory: {filepath}')
|
| 110 |
print(\"Before restoring backup:\")
|
| 111 |
import subprocess
|
| 112 |
+
subprocess.run(['ls', '-l', \"$CLOUDREVE_DIR\"], shell=True)
|
| 113 |
|
| 114 |
# 删除现有的 Cloudreve 目录和配置文件
|
| 115 |
import shutil
|
|
|
|
| 135 |
print(f'Successfully restored backup from {latest_backup}')
|
| 136 |
|
| 137 |
print(\"After restoring backup:\")
|
| 138 |
+
subprocess.run(['ls', '-l', \"$CLOUDREVE_DIR\"], shell=True)
|
| 139 |
else:
|
| 140 |
print('Error during file download.')
|
| 141 |
|
|
|
|
| 173 |
upload_backup "$backup_path" "${backup_file}"
|
| 174 |
|
| 175 |
rm -f "$backup_path"
|
| 176 |
+
else:
|
| 177 |
echo "Cloudreve directory does not exist yet, waiting for next sync..."
|
| 178 |
fi
|
| 179 |
|