From 74de7e519a9d5b7b9306902901e79ec43c4eeb69 Mon Sep 17 00:00:00 2001 From: KAAAsS Date: Sun, 13 Feb 2022 20:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.conf.example | 5 ++++- webdav_backup.sh | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/backup.conf.example b/backup.conf.example index cf3b53a..b0bb2bf 100644 --- a/backup.conf.example +++ b/backup.conf.example @@ -1,5 +1,8 @@ # WebDav 服务器 -server="https://localhost" +server="https://localhost/" + +# WebDav 服务器路径 +server-path="" # 用户 user="" diff --git a/webdav_backup.sh b/webdav_backup.sh index 6106e7e..b887680 100755 --- a/webdav_backup.sh +++ b/webdav_backup.sh @@ -14,7 +14,8 @@ show_help() { echo echo "选项:" __opt "-x, --prefix " "备份文件前缀" - __opt "-s, --server " "WebDav 服务器地址" + __opt "-s, --server " "WebDav 服务器地址,以 \"/\" 结束" + __opt "-P, --server-path " "WebDav 备份路径,以 \"/\" 结束" __opt "-u, --user " "WebDav 用户名" __opt "-p, --pass " "WebDav 密码" __opt "-k, --keeps n" "保留最近几个备份文件。默认为0,不删除备份文件" @@ -35,6 +36,7 @@ verbose=false tmpfs="/tmp" prefix="backup" server="http://your-site/dav" +server_path= user="guest" pass="" backup_path=- @@ -104,7 +106,7 @@ upload() { echo -n "上传备份文件: 第 $retry_count 次重试... " fi - __try curl -sS --user "$user:$pass" -T $1 "$server" -f $curl_extra_args + __try curl -sS --user "$user:$pass" -T $1 "$server$server_path" -f $curl_extra_args if __catch e; then __color $RED '错误\n' @@ -121,7 +123,7 @@ upload() { } get_file_list() { - flist_html=$(curl -sS --user "$user:$pass" -X PROPFIND "$server" -f --header 'Depth: 1' $curl_extra_args) + flist_html=$(curl -sS --user "$user:$pass" -X PROPFIND "$server$server_path" -f --header 'Depth: 1' $curl_extra_args) echo $flist_html | grep -Po '.+?\/\K(.+?)(?=<\/D:href>)' -o | grep $prefix | sort } @@ -136,7 +138,7 @@ delete_file() { echo -n "删除备份 $file: 第 $retry_count 次重试... " fi - __try curl -sS --user "$user:$pass" -X DELETE "$server$file" -f $curl_extra_args + __try curl -sS --user "$user:$pass" -X DELETE "$server$server_path$file" -f $curl_extra_args if __catch e; then __color $RED '错误\n' @@ -251,8 +253,8 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then exit 1 fi -OPTIONS=c:vhVx:s:u:p:k:I -LONGOPTS=config,verbose,help,version,prefix:,server:,user:,pass:,keeps:,ignore-cert +OPTIONS=c:vhVx:s:P:u:p:k:I +LONGOPTS=config,verbose,help,version,prefix:,server:,server-path:,user:,pass:,keeps:,ignore-cert ! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") if [[ ${PIPESTATUS[0]} -ne 0 ]]; then @@ -291,6 +293,10 @@ while true; do server="$2" shift 2 ;; + -P|--server-path) + server_path="$2" + shift 2 + ;; -u|--user) user="$2" shift 2