74 lines
2.0 KiB
Bash
Executable File
74 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Shared helpers for compose volume operations.
|
|
# Ephemeral volumes (init-container config) are excluded from backup/restore/size.
|
|
|
|
is_ephemeral_volume_key() {
|
|
local key=$1
|
|
local compose_file=$2
|
|
|
|
# op-node rollup config volumes
|
|
[[ "$key" == *_node_config ]] && return 0
|
|
|
|
if [[ -n "$compose_file" && -f "$compose_file" ]]; then
|
|
local ephemeral
|
|
ephemeral=$(yaml2json "$compose_file" 2>/dev/null | jq -r '.["x-ephemeral-volumes"] // [] | .[]' 2>/dev/null)
|
|
while IFS= read -r vol; do
|
|
[[ -z "$vol" ]] && continue
|
|
[[ "$key" == "$vol" ]] && return 0
|
|
done <<< "$ephemeral"
|
|
fi
|
|
|
|
return 1
|
|
}
|
|
|
|
get_volume_keys() {
|
|
local compose_file=$1
|
|
yaml2json "$compose_file" 2>/dev/null | jq -r '.volumes | keys[]' 2>/dev/null
|
|
}
|
|
|
|
get_persistent_volume_keys() {
|
|
local compose_file=$1
|
|
local key
|
|
|
|
while IFS= read -r key; do
|
|
[[ -z "$key" ]] && continue
|
|
if ! is_ephemeral_volume_key "$key" "$compose_file"; then
|
|
echo "$key"
|
|
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
|
|
}
|