fix: Add Path-only URI processing

This commit is contained in:
ge 2022-05-17 00:25:40 +03:00
parent dfd9830ff8
commit 5310d5ae0f
2 changed files with 26 additions and 9 deletions

View File

@ -27,6 +27,8 @@ process_source() {
uri="$1"
scheme="${uri%%:*}"
# Process Path-only URI
if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi
echo -e "Processing source $uri ..."
@ -35,7 +37,7 @@ process_source() {
mysql) handler='backup_mysql';;
postgres) handler='backup_postgres';;
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
# Run handler function
@ -54,6 +56,8 @@ process_target() {
uri="$1"
scheme="${uri%%:*}"
# Process Path-only URI
if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi
echo -e "Processing target $uri ..."
@ -118,6 +122,11 @@ backup_files() {
exit 1
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
is_installed tar

View File

@ -29,9 +29,13 @@ validate_sources() {
for uri in "${array[@]}"; do
scheme="${uri%%:*}"
# Process Path-only URI
if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi
case "$scheme" in
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
done
}
@ -50,18 +54,22 @@ validate_targets() {
for uri in "${array[@]}"; do
scheme="${uri%%:*}"
# Process Path-only URI
if [[ "$scheme" == "$uri" ]]; then scheme="file"; fi
case "$scheme" in
file|ftp|sftp|rsync|s3|swift|sj|dav|davs)
if [[ "$scheme" == file ]]; then
file_targets+=("$uri")
fi
;;
*) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;;
*) echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2; exit 1;;
esac
done
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
exit 1
else
@ -73,8 +81,8 @@ validate_targets() {
if [ -d "$path" ]; then
__main_target_path="$path"
else
echo "Error: Path '$path' from URI '$__main_target'" \
"is not directory or does not exists" >&2
echo "Error: $__user_script: Path '$path' from URI '$__main_target'" \
"does not exists or not a directory" >&2
exit 1
fi
fi
@ -93,7 +101,7 @@ source_script() {
# Dry run script, check syntax. See set(1p)
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
# Source script
@ -103,13 +111,13 @@ source_script() {
if [[ "$sources" ]]; then
validate_sources "${sources[@]}"
else
echo Error: sources array is not set >&2; exit 1
echo Error: $__user_script: sources array is not set >&2; exit 1
fi
if [[ "$targets" ]]; then
validate_targets "${targets[@]}"
else
echo Error: targets array is not set >&2; exit 1
echo Error: $__user_script: targets array is not set >&2; exit 1
fi
}