flzta commited on
Commit
c3fa68f
·
verified ·
1 Parent(s): 60e5a7e

Update sync_data.sh

Browse files
Files changed (1) hide show
  1. sync_data.sh +10 -10
sync_data.sh CHANGED
@@ -3,7 +3,7 @@
3
  # 检查环境变量
4
  if [[ -z "$WEBDAV_URL" ]] || [[ -z "$WEBDAV_USERNAME" ]] || [[ -z "$WEBDAV_PASSWORD" ]]; then
5
  echo "Starting without backup functionality - missing WEBDAV_URL, WEBDAV_USERNAME, or WEBDAV_PASSWORD"
6
- exec /opt/cloudreve/cloudreve -c /opt/cloudreve/config.ini
7
  exit 0
8
  fi
9
 
@@ -14,9 +14,9 @@ if [ -n "$WEBDAV_BACKUP_PATH" ]; then
14
  FULL_WEBDAV_URL="${WEBDAV_URL}/${WEBDAV_BACKUP_PATH}"
15
  fi
16
 
17
- # 定义 Cloudreve 主程序目录
18
- CLOUDREVE_DIR="/opt/cloudreve"
19
- BACKUP_PREFIX="cloudreve_backup"
20
 
21
  # 激活虚拟环境
22
  source /opt/venv/bin/activate
@@ -50,7 +50,7 @@ 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
- # 如果目录已存在,先尝试删除 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)
@@ -86,7 +86,7 @@ sync_data() {
86
  backup_file="${BACKUP_PREFIX}_${timestamp}.tar.gz"
87
 
88
  # 压缩数据目录
89
- tar -czf "/tmp/${backup_file}" -C "$CLOUDREVE_DIR" cloudreve cloudreve.db config.ini
90
 
91
  # 上传新备份到WebDAV
92
  curl -u "$WEBDAV_USERNAME:$WEBDAV_PASSWORD" -T "/tmp/${backup_file}" "$FULL_WEBDAV_URL/${backup_file}"
@@ -127,12 +127,12 @@ else:
127
  done
128
  }
129
 
130
- # 在這裡設定 Cloudreve 執行檔的執行權限
131
- chmod +x /opt/cloudreve/cloudreve
132
 
133
  # 启动同步进程
134
  sync_data &
135
 
136
- # 启动 Cloudreve
137
  sleep 30
138
- exec /opt/cloudreve/cloudreve -c /opt/cloudreve/config.ini
 
3
  # 检查环境变量
4
  if [[ -z "$WEBDAV_URL" ]] || [[ -z "$WEBDAV_USERNAME" ]] || [[ -z "$WEBDAV_PASSWORD" ]]; then
5
  echo "Starting without backup functionality - missing WEBDAV_URL, WEBDAV_USERNAME, or WEBDAV_PASSWORD"
6
+ exec /opt/app/app -c /opt/app/config.ini
7
  exit 0
8
  fi
9
 
 
14
  FULL_WEBDAV_URL="${WEBDAV_URL}/${WEBDAV_BACKUP_PATH}"
15
  fi
16
 
17
+ # 定义 app 主程序目录
18
+ CLOUDREVE_DIR="/opt/app"
19
+ BACKUP_PREFIX="app_backup"
20
 
21
  # 激活虚拟环境
22
  source /opt/venv/bin/activate
 
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
  for item in os.listdir('$CLOUDREVE_DIR'):
56
  item_path = os.path.join('$CLOUDREVE_DIR', item)
 
86
  backup_file="${BACKUP_PREFIX}_${timestamp}.tar.gz"
87
 
88
  # 压缩数据目录
89
+ tar -czf "/tmp/${backup_file}" -C "$CLOUDREVE_DIR" app app.db config.ini
90
 
91
  # 上传新备份到WebDAV
92
  curl -u "$WEBDAV_USERNAME:$WEBDAV_PASSWORD" -T "/tmp/${backup_file}" "$FULL_WEBDAV_URL/${backup_file}"
 
127
  done
128
  }
129
 
130
+ # 在這裡設定 app 執行檔的執行權限
131
+ chmod +x /opt/app/app
132
 
133
  # 启动同步进程
134
  sync_data &
135
 
136
+ # 启动 app
137
  sleep 30
138
+ exec /opt/app/app -c /opt/app/config.ini