flzta commited on
Commit
d363dec
·
verified ·
1 Parent(s): a5a12a2

Update sync_data.sh

Browse files
Files changed (1) hide show
  1. sync_data.sh +14 -5
sync_data.sh CHANGED
@@ -63,7 +63,7 @@ try:
63
 
64
  if not backup_files:
65
  print('No backup files found on HuggingFace Dataset')
66
- sys.exit()
67
 
68
  latest_backup = sorted(backup_files)[-1]
69
 
@@ -76,17 +76,26 @@ try:
76
  )
77
 
78
  if filepath and os.path.exists(filepath):
 
 
 
 
 
 
 
 
 
79
  with tarfile.open(filepath, 'r:gz') as tar:
80
  tar.extractall('/opt/cloudreve/data')
81
- print(f'Successfully restored backup from {latest_backup}')
82
 
83
  except Exception as e:
84
- print(f'Error downloading backup from HuggingFace Dataset: {str(e)}')
85
  "
86
  }
87
 
88
- # 首次启动时下载最新备份
89
- echo "Downloading latest backup from HuggingFace Dataset..."
90
  download_latest_backup
91
 
92
  # 同步函数
 
63
 
64
  if not backup_files:
65
  print('No backup files found on HuggingFace Dataset')
66
+ return
67
 
68
  latest_backup = sorted(backup_files)[-1]
69
 
 
76
  )
77
 
78
  if filepath and os.path.exists(filepath):
79
+ print(f'Found latest backup: {latest_backup}, attempting to restore...')
80
+ # 删除现有的数据目录
81
+ if [ -d /opt/cloudreve/data ]; then
82
+ echo "Deleting existing data directory: /opt/cloudreve/data"
83
+ rm -rf /opt/cloudreve/data
84
+ fi
85
+ # 创建数据目录(如果被删除)
86
+ mkdir -p /opt/cloudreve/data
87
+
88
  with tarfile.open(filepath, 'r:gz') as tar:
89
  tar.extractall('/opt/cloudreve/data')
90
+ echo f'Successfully restored backup from {latest_backup}'
91
 
92
  except Exception as e:
93
+ echo f'Error downloading backup from HuggingFace Dataset: {e}'
94
  "
95
  }
96
 
97
+ # 首次启动时下载最新备份和后续每次启动时都尝试恢复
98
+ echo "Attempting to download and restore latest backup from HuggingFace Dataset..."
99
  download_latest_backup
100
 
101
  # 同步函数