Compare commits

..

2 Commits

Author SHA1 Message Date
74de7e519a
增加服务器路径 2022-02-13 20:01:16 +08:00
a94b88889a
排除所有配置 2022-02-13 19:54:46 +08:00
3 changed files with 17 additions and 8 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
backup.conf
*.conf

View File

@ -1,5 +1,8 @@
# WebDav 服务器
server="https://localhost"
server="https://localhost/"
# WebDav 服务器路径
server-path=""
# 用户
user=""

View File

@ -14,7 +14,8 @@ show_help() {
echo
echo "选项:"
__opt "-x, --prefix <name>" "备份文件前缀"
__opt "-s, --server <url>" "WebDav 服务器地址"
__opt "-s, --server <url>" "WebDav 服务器地址,以 \"/\" 结束"
__opt "-P, --server-path <path>" "WebDav 备份路径,以 \"/\" 结束"
__opt "-u, --user <user>" "WebDav 用户名"
__opt "-p, --pass <password>" "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 '<D:href>.+?\/\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