feat: Add logging and output info
This commit is contained in:
@ -28,6 +28,8 @@ process_source() {
|
||||
uri="$1"
|
||||
scheme="${uri%%:*}"
|
||||
|
||||
echo -e "Processing source $uri ..."
|
||||
|
||||
case "$scheme" in
|
||||
file) handler='backup_files';;
|
||||
mysql) handler='backup_mysql';;
|
||||
@ -37,6 +39,7 @@ process_source() {
|
||||
esac
|
||||
|
||||
# Run handler function
|
||||
[ "$__verbose" ] && echo "Run handler ${handler}()"
|
||||
"$handler" "$uri"
|
||||
}
|
||||
|
||||
@ -52,6 +55,8 @@ process_target() {
|
||||
uri="$1"
|
||||
scheme="${uri%%:*}"
|
||||
|
||||
echo -e "Processing target $uri ..."
|
||||
|
||||
case "$scheme" in
|
||||
file) handler='transfer_files';;
|
||||
ftp) handler='transfer_ftp';;
|
||||
@ -66,6 +71,7 @@ process_target() {
|
||||
esac
|
||||
|
||||
# Run handler function
|
||||
[ "$__verbose" ] && echo "Run handler ${handler}()"
|
||||
"$handler" "$uri"
|
||||
}
|
||||
|
||||
@ -95,6 +101,7 @@ backup_files() {
|
||||
local uri
|
||||
local src_path
|
||||
local dst_path
|
||||
local tar_opts
|
||||
local archive
|
||||
local file_ext
|
||||
|
||||
@ -114,7 +121,9 @@ backup_files() {
|
||||
|
||||
# Overwrire __tar_options
|
||||
if [ -n "$tar_options" ]; then
|
||||
__tar_options="$tar_options"
|
||||
tar_opts="$tar_options"
|
||||
else
|
||||
tar_opts="$__tar_options"
|
||||
fi
|
||||
|
||||
# TODO выбор сжатия, можно в переменной __tar_options заменять букву z на
|
||||
@ -123,7 +132,16 @@ backup_files() {
|
||||
|
||||
archive="${dst_path}/$(gen_backup_name "$file_ext")"
|
||||
|
||||
tar "$__tar_options" "$archive" "$src_path" |& log -p
|
||||
[ "$__verbose" ] && {
|
||||
echo "Source path: $src_path"
|
||||
echo "Destination path: $dst_path"
|
||||
echo "Command: tar $tar_opts $archive $src_path"
|
||||
}
|
||||
|
||||
log "Archiving $src_path to $archive ..."
|
||||
|
||||
# Run tar
|
||||
try tar "$tar_opts" "$archive" "$src_path"
|
||||
|
||||
# Append path to 'backups' array
|
||||
backups+=("$archive")
|
||||
@ -168,9 +186,13 @@ transfer_files() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ "$__verbose" ] && echo "Destination path: $dst_path"
|
||||
|
||||
# Copy files preserving metadata
|
||||
for backup in "${backups[@]}"; do
|
||||
cp --archive "$backup" "$dst_path"
|
||||
log "Copying file $backup to $dst_path ..."
|
||||
[ "$__verbose" ] && echo "Command: cp --archive $backup $dst_path"
|
||||
try cp --archive "$backup" "$dst_path"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
Reference in New Issue
Block a user