feat: Rename handler functions, remove gen_backup_name

This commit is contained in:
ge 2022-08-21 04:47:08 +03:00
parent 0e2f95337d
commit f6dbb64fe8

View File

@ -30,21 +30,22 @@ process_source() {
# Process Path-only URI # Process Path-only URI
if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi if [[ "$scheme" == "$uri" ]]; then scheme='file'; fi
echo -e "Processing source $uri ..." echo -e "Processing source $uri ..." |
sed 's/:\/\//\[auth\]/;s/:.*@/:xxx@/;s/\[auth\]/:\/\//'
# ^^^ hide password from output ^^^
case "$scheme" in case "$scheme" in
file) handler='handler::tar';; file) handler='src_tar';;
mysql) handler='handler::mysqldump';; mysql|mariadb) handler='src_mysqldump';;
postgres) handler='handler::pg_dump';; postgres) handler='src_pg_dump';;
sqlite) handler='handler::sqlite';; sqlite) handler='src_sqlite';;
*) # shellcheck disable=SC2154 *) # shellcheck disable=SC2154
# '__user_script' is assigned in main script. # 'backup_script' is assigned in main script.
echo "Error: $__user_script: Unsupported URI scheme: $scheme" >&2 echo "Error: $backup_script: Unsupported URI scheme: $scheme" >&2
exit 1;; exit 1;;
esac esac
# Run handler function # Run handler function
[ "$__verbose" ] && echo "Run handler ${handler}()"
"$handler" "$uri" "$handler" "$uri"
} }
@ -65,20 +66,19 @@ process_target() {
echo -e "Processing target $uri ..." echo -e "Processing target $uri ..."
case "$scheme" in case "$scheme" in
file) handler='handler::cp';; file) handler='tgt_cp';;
ftp) handler='handler::ftp';; ftp) handler='tgt_ftp';;
sftp) handler='handler::sftp';; sftp) handler='tgt_sftp';;
rsync) handler='handler::rsync';; rsync) handler='tgt_rsync';;
s3) handler='handler::s3';; s3) handler='tgt_s3';;
sj) handler='handler::sj';; sj) handler='tgt_sj';;
swift) handler='handler::swift';; swift) handler='tgt_swift';;
dav) handler='handler::dav';; dav) handler='tgt_dav';;
davs) handler='handler::davs';; davs) handler='tgt_davs';;
*) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;; *) echo "Error: Unsupported URI scheme: $scheme" >&2; exit 1;;
esac esac
# Run handler function # Run handler function
[ "$__verbose" ] && echo "Run handler ${handler}()"
"$handler" "$uri" "$handler" "$uri"
} }
@ -97,25 +97,3 @@ builtin_backup() {
process_target "$target" process_target "$target"
done done
} }
# ---------------------------------------------------------- #
# * Helper functions #
# ---------------------------------------------------------- #
gen_backup_name() {
# Generate backup file name. Write resulting string to STDOUT.
#
# Usage: gen_backup_name NAME_EXT
local name
local name_ext
name_prefix="${name_prefix:-${__user_script}_}"
# shellcheck disable=SC2154
name="$(basename "$path")" # 'path' is variable parsed from URI
name_ext="$1"
name_date_fmt="${name_date_fmt:-_%Y.%m.%d}"
name_suffix="${name_suffix:--%H%M}"
date +"${name_prefix}${name}${name_date_fmt}${name_suffix}${name_ext}"
}