fix: Add Path-only URI processing
This commit is contained in:
parent
dfd9830ff8
commit
5310d5ae0f
@ -27,6 +27,8 @@ process_source() {
|
|||||||
|
|
||||||
uri="$1"
|
uri="$1"
|
||||||
scheme="${uri%%:*}"
|
scheme="${uri%%:*}"
|
||||||
|
# Process Path-only URI
|
||||||
|
if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi
|
||||||
|
|
||||||
echo -e "Processing source $uri ..."
|
echo -e "Processing source $uri ..."
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ process_source() {
|
|||||||
mysql) handler='backup_mysql';;
|
mysql) handler='backup_mysql';;
|
||||||
postgres) handler='backup_postgres';;
|
postgres) handler='backup_postgres';;
|
||||||
sqlite) handler='backup_sqlite';;
|
sqlite) handler='backup_sqlite';;
|
||||||
*) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;;
|
*) echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2; exit 1;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Run handler function
|
# Run handler function
|
||||||
@ -54,6 +56,8 @@ process_target() {
|
|||||||
|
|
||||||
uri="$1"
|
uri="$1"
|
||||||
scheme="${uri%%:*}"
|
scheme="${uri%%:*}"
|
||||||
|
# Process Path-only URI
|
||||||
|
if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi
|
||||||
|
|
||||||
echo -e "Processing target $uri ..."
|
echo -e "Processing target $uri ..."
|
||||||
|
|
||||||
@ -118,6 +122,11 @@ backup_files() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$src_path" == "$dst_path" ]]; then
|
||||||
|
echo "Error: Source and destination paths is the same: $src_path; $dst_path" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Exit if tar is not installed
|
# Exit if tar is not installed
|
||||||
is_installed tar
|
is_installed tar
|
||||||
|
|
||||||
|
@ -29,9 +29,13 @@ validate_sources() {
|
|||||||
|
|
||||||
for uri in "${array[@]}"; do
|
for uri in "${array[@]}"; do
|
||||||
scheme="${uri%%:*}"
|
scheme="${uri%%:*}"
|
||||||
|
|
||||||
|
# Process Path-only URI
|
||||||
|
if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi
|
||||||
|
|
||||||
case "$scheme" in
|
case "$scheme" in
|
||||||
file|mysql|postgres|sqlite) : ;; # do nothing, this is OK
|
file|mysql|postgres|sqlite) : ;; # do nothing, this is OK
|
||||||
*) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;;
|
*) echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -50,18 +54,22 @@ validate_targets() {
|
|||||||
|
|
||||||
for uri in "${array[@]}"; do
|
for uri in "${array[@]}"; do
|
||||||
scheme="${uri%%:*}"
|
scheme="${uri%%:*}"
|
||||||
|
|
||||||
|
# Process Path-only URI
|
||||||
|
if [[ "$scheme" == "$uri" ]]; then scheme="file"; fi
|
||||||
|
|
||||||
case "$scheme" in
|
case "$scheme" in
|
||||||
file|ftp|sftp|rsync|s3|swift|sj|dav|davs)
|
file|ftp|sftp|rsync|s3|swift|sj|dav|davs)
|
||||||
if [[ "$scheme" == file ]]; then
|
if [[ "$scheme" == file ]]; then
|
||||||
file_targets+=("$uri")
|
file_targets+=("$uri")
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;;
|
*) echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2; exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "${#file_targets[@]}" -eq 0 ]; then
|
if [ "${#file_targets[@]}" -eq 0 ]; then
|
||||||
echo "Error: 'file' scheme is not set in targets." \
|
echo -e "Error: $__user_script: 'file' scheme is not set in targets."\
|
||||||
"You must provide one or more targets with 'file' scheme." >&2
|
"You must provide one or more targets with 'file' scheme." >&2
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
@ -73,8 +81,8 @@ validate_targets() {
|
|||||||
if [ -d "$path" ]; then
|
if [ -d "$path" ]; then
|
||||||
__main_target_path="$path"
|
__main_target_path="$path"
|
||||||
else
|
else
|
||||||
echo "Error: Path '$path' from URI '$__main_target'" \
|
echo "Error: $__user_script: Path '$path' from URI '$__main_target'" \
|
||||||
"is not directory or does not exists" >&2
|
"does not exists or not a directory" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -93,7 +101,7 @@ source_script() {
|
|||||||
|
|
||||||
# Dry run script, check syntax. See set(1p)
|
# Dry run script, check syntax. See set(1p)
|
||||||
if ! bash -n "$script"; then
|
if ! bash -n "$script"; then
|
||||||
echo Error: Please check your syntax >&2; exit 1
|
echo Error: $__user_script: Please check your syntax >&2; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Source script
|
# Source script
|
||||||
@ -103,13 +111,13 @@ source_script() {
|
|||||||
if [[ "$sources" ]]; then
|
if [[ "$sources" ]]; then
|
||||||
validate_sources "${sources[@]}"
|
validate_sources "${sources[@]}"
|
||||||
else
|
else
|
||||||
echo Error: sources array is not set >&2; exit 1
|
echo Error: $__user_script: sources array is not set >&2; exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$targets" ]]; then
|
if [[ "$targets" ]]; then
|
||||||
validate_targets "${targets[@]}"
|
validate_targets "${targets[@]}"
|
||||||
else
|
else
|
||||||
echo Error: targets array is not set >&2; exit 1
|
echo Error: $__user_script: targets array is not set >&2; exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user