flzta commited on
Commit
7dfdeb6
·
verified ·
1 Parent(s): 91bbba4

Update sync_data.sh

Browse files
Files changed (1) hide show
  1. sync_data.sh +9 -4
sync_data.sh CHANGED
@@ -50,9 +50,14 @@ with requests.get(f'$FULL_WEBDAV_URL/{latest_backup}', auth=('$WEBDAV_USERNAME',
50
  f.write(chunk)
51
  print(f'成功下载备份文件到 /tmp/{latest_backup}')
52
  if os.path.exists(f'/tmp/{latest_backup}'):
53
- # 如果目录已存在,先删除它
54
  if os.path.exists('$CLOUDREVE_DIR'):
55
- shutil.rmtree('$CLOUDREVE_DIR')
 
 
 
 
 
56
  os.makedirs('$CLOUDREVE_DIR', exist_ok=True)
57
 
58
  # 解压备份文件
@@ -113,11 +118,11 @@ else:
113
  " 2>&1
114
 
115
  rm -f "/tmp/${backup_file}"
116
- else
117
  echo "Data directory does not exist yet, waiting for next sync..."
118
  fi
119
 
120
- SYNC_INTERVAL=${SYNC_INTERVAL:-600}
121
  echo "Next sync in ${SYNC_INTERVAL} seconds..."
122
  sleep $SYNC_INTERVAL
123
  done
 
50
  f.write(chunk)
51
  print(f'成功下载备份文件到 /tmp/{latest_backup}')
52
  if os.path.exists(f'/tmp/{latest_backup}'):
53
+ # 如果目录已存在,先尝试删除 Cloudreve 目录内的文件,而不是整个目录
54
  if os.path.exists('$CLOUDREVE_DIR'):
55
+ for item in os.listdir('$CLOUDREVE_DIR'):
56
+ item_path = os.path.join('$CLOUDREVE_DIR', item)
57
+ if os.path.isfile(item_path):
58
+ os.remove(item_path)
59
+ elif os.path.isdir(item_path):
60
+ shutil.rmtree(item_path, ignore_errors=True)
61
  os.makedirs('$CLOUDREVE_DIR', exist_ok=True)
62
 
63
  # 解压备份文件
 
118
  " 2>&1
119
 
120
  rm -f "/tmp/${backup_file}"
121
+ else:
122
  echo "Data directory does not exist yet, waiting for next sync..."
123
  fi
124
 
125
+ SYNC_INTERVAL=${SYNC_INTERVAL:-60} # 同步间隔改为 60 秒
126
  echo "Next sync in ${SYNC_INTERVAL} seconds..."
127
  sleep $SYNC_INTERVAL
128
  done