if the backup storage is local do not use webdav

This commit is contained in:
goldsquid
2026-06-06 11:36:58 +07:00
parent eccae5039f
commit 1aef140a9a
3 changed files with 56 additions and 11 deletions

View File

@@ -38,3 +38,36 @@ get_persistent_volume_keys() {
fi
done < <(get_volume_keys "$compose_file")
}
# Returns 0 when a backup HTTP/WebDAV URL refers to this machine.
is_local_backup_url() {
local url=$1
[[ -z "$url" ]] && return 1
local host="${url#*://}"
host="${host%%/*}"
host="${host%%:*}"
[[ -z "$host" ]] && return 1
case "$host" in
localhost|127.0.0.1|::1|0.0.0.0) return 0 ;;
esac
local env_file
env_file="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.env"
if [[ -f "$env_file" ]]; then
local domain ip
domain=$(grep -E '^DOMAIN=' "$env_file" | head -n 1 | cut -d= -f2- | tr -d '"' | tr -d "'")
ip=$(grep -E '^IP=' "$env_file" | head -n 1 | cut -d= -f2- | tr -d '"' | tr -d "'")
[[ -n "$domain" && "$host" == "$domain" ]] && return 0
[[ -n "$ip" && "$host" == "$ip" ]] && return 0
fi
local local_fqdn local_short
local_fqdn=$(hostname -f 2>/dev/null || true)
local_short=$(hostname 2>/dev/null || true)
[[ -n "$local_fqdn" && "$host" == "$local_fqdn" ]] && return 0
[[ -n "$local_short" && "$host" == "$local_short" ]] && return 0
return 1
}