Am writing a bash function to run rsync
, with possibility of using --dry-run
option and --exec
option. Need some criticism improvements and additional checks.
Might not make much sense for the user to specify both --dry-run
and --exec
. I would simply use --dry-run anyway.
Have started with the following setup.
Calling the following
filetr-archive -n -s bkscan -d temp
runs the command
rsync -av --progress --dry-run --log-file=temp/bkscan.log bkscan temp
which makes the file temp/bkscan.log
whose contents are
2021/07/19 23:55:15 [19947] building file list
2021/07/19 23:55:15 [19947] cd+++++++++ bkscan/
2021/07/19 23:55:15 [19947] sent 273 bytes received 56 bytes 658.00 bytes/sec
2021/07/19 23:55:15 [19947] total size is 108,837,826 speedup is 330,814.06 (DRY RUN)
But, rsync
also produces the following, which never gets saved. Is the output from rsync
displayed on the terminal useful? I could also store the information. But I wonder how I could do it.
bkscan temp
sending incremental file list
bkscan/
bkscan/BkScan.aux
bkscan/BkScan.cp
bkscan/BkScan.fn
bkscan/BkScan.ky
bkscan/BkScan.log
bkscan/BkScan.pdf
bkscan/BkScan.pg
bkscan/BkScan.texi
bkscan/BkScan.texi~
bkscan/BkScan.tp
bkscan/BkScan.vr
bkscan/BookScan.texi~
sent 273 bytes received 56 bytes 658.00 bytes/sec
total size is 108,837,826 speedup is 330,814.06 (DRY RUN)
filetr-archive ()
{
# Process command line options
shortopts="nel:s:d:"
longopts="dry-run,exec,log:,source:,destin:"
opts=$(getopt -o "$shortopts" -l "$longopts" \
-n "$(basename $0)" -- "$@")
if [ $? -eq 0 ]; then
eval "set -- ${opts}"
while [ $# -gt 0 ]; do
case "$1" in
-n|--dry-run)
shift 1
local -r dryrun=1
;;
-e|--exec)
shift 1
local -r exec=1
;;
-l|--log)
local logfl=$2
shift 2
;;
-s|--source)
local source=$2
shift 2
;;
-d|--destin)
local destin=$2
shift 2
;;
--)
shift; break ;;
esac
done
else
shorthelp=1 # getopt returned (and reported) an error.
fi
if (( filetr_dryrun == 1 )); then
echo "rsync -av --progress --log-file=$logfl --dry-run"
echo " $source $destin"
rsync -av --progress --log-file=$logfl --dry-run $source $destin
elif (( filetr_exec == 1 )); then
# use rsync archive option -a (equivalent to -rlptgoD)
echo "rsync -av --progress --log-file=$logfl $source $destin"
# rsync -av --progress --log-file=$logfl $source $destin
else
echo "rsync -av --progress --log-file=$logfl $source $destin"
fi