是否可以按文件夹显示 rsync 的进度?

是否可以按文件夹显示 rsync 的进度?

我正在寻找一种方法来按文件夹显示 rsync 的进度,而不是按文件 (rsync -P) 或按总体进度 (rsync --info=progress2)。 这可能吗?

答案1

我为您制作了一个演示系统,并在测试环境中对其进行了测试。您的实际情况可能有所不同,主要区别可能是您正在复制到另一个驱动器甚至另一台计算机,至少如果复制是备份的话。

修改以下 shellscript 来修复您的实际情况应该相当容易。

#!/bin/bash

tdir="$(pwd)"
tdir="${tdir##*/}"
if [ "$tdir" != "work" ]
then
 pwd
 echo "You should change current directory to \"work\" and try again"
 exit 1
fi

if [ "$1" == "-n" ] || [ "$1" == "dry-run" ]
then
 find -mindepth 1 -maxdepth 1 -type d \
  -exec echo -e "------------------------------------------\ncopy of {}:" \; \
  -exec rsync -avn {} ../backup \;
elif [ "$1" == "do-it" ]
then
 find -mindepth 1 -maxdepth 1 -type d \
  -exec rsync -a {} ../backup \; -exec echo "copy of {} finished" \;
else
 echo "Work in a directory structure with a work directory containing a set of
directories, and a backup directory alongside the work directory,
for example:

$ find | sort
.
./backup
./work
./work/dir1
./work/dir1/file1
./work/dir1/file2
./work/dir1/file 3
./work/dir2
./work/dir2/file1
./work/dir2/file2
./work/dir3
./work/dir3/file1
./work/dir3/file2
./work/dir3/file3
./work/dir 4
./work/dir 4/file 1
./work/file1
./work/file2
./work/rsync-by-folder"
 read -p "-----------------------Press Enter to continue"
 echo "
Usage:

$0 [-h]           # Show this help output

$0 -n             # Dry run only showing what would be done
$0 dry-run        # Dry run only showing what would be done

$0 do-it          # Run the real copying process
"
fi

编辑:如果您愿意,您可以将rsync选项添加--info=progress2到“do-it”命令行。

相关内容