3

此脚本是 linux live-cd 安装程序的一部分。

rsync -aq / /TARGET/ exclude-from=exclude.list &>> errors.log

我想向 gui 报告进度。gui (gtkdialog) 响应任何数字 0-100 (echo 1; echo 2; etc...)

在这种情况下,rsync -n(试运行)需要很长时间。

我想跑...

filesystem_size=`(get directory size) / exclude=exclude.list`
rsync -aq / /TARGET/ exclude-from=exclude.list &
while [ rsync is running ]; do
    (check size) /TARGET/
    compare to $filesystem_size
    echo $number (based on the difference of sizes)
done

请帮助获取具有多个排除项的目录大小,while loop for while rsync 正在运行,echo number (0-100) 基于两种大小的差异。

回答以上任何一个都是一个很大的帮助,谢谢。

编辑:在 Olivier Dulac 的帮助下添加完成的 RSYNC 进度输出(似乎有足够多的人在寻找这个)我完成了这项工作。

size_source=`du -bs --exclude-from=/path/to/exclude.list /source/ | sed "s/[^0-9]*//g"`

size_target=`du -bs /target/ | sed "s/[^0-9]*//g"`

rsync -aq /source/ /target/ --exclude-from=/path/to/exclude.list &

while [[ `jobs | grep "rsync"` ]]; do
  size_target_new=`du -bs /TARGET/ | sed "s/[^0-9]*//g"`
  size_progress=`expr $size_target_new - $size_target`
  expr 100 \* $size_progress / $size_source
  sleep 10
done

这会将 % done 打印到命令行,仅对大传输有用。

如果 rsync 覆盖文件,它将放弃进度(显示的进度比实际完成的少)

exclude.list 在 rsync 和 du 中读取相同,但 du 始终需要完整路径,而 rsync 假定 exclude 在其源中。如果复制 rootfs "/",它们可以是同一个文件,否则您必须为 du 编写完整路径(只需将 /source/ 添加到文件中每一行的开头。)

4

1 回答 1

2

确定目标和源的总大小(不包括):

filesystem_size=$(find /SOURCE -ls | fgrep -f exclude.list  -v | awk '{ TOTAL += $6} END { print int ( TOTAL / 1024 ) }')
     # the above considers you only have, in exclude.list, a list of /path/ or /path/to/files 
     # with no spaces on those files or path. If it contains patterns, change "fgrep" with "egrep". 
     # And give us examples of those patterns so we can adjust the egrep.
     # It also consider that "find ... -ls" will print the size in the 6th column.
size_target=$(du -ks /TARGET | awk '{print $1}')
#there are other ways: 
#   if /TARGET is on different filesystem than /SOURCE, 
#   and if reasonnably sure nothing else is writing on the /TARGET filesystem : 
#     you can use "df -k /TARGET | awk '{print $n}' (n= column showing the size in k)
#     to monitor the target progress.
#     But you need to take its size before starting the rsync, 
#     and then compare it with the current size

对于循环:

while  jobs | grep 'sync' ; do ... ; done
    #It is probably wise to add in the loop a "sleep 5" or something to avoid doing too many size computations, too often.

尺寸:

echo "100 * $size_target / $filesystem_size" | bc

请告诉我这些是否适合你。如果没有,请提供尽可能多的详细信息以帮助确定您的需求。

于 2013-04-22T08:16:35.990 回答