在这里可能会有点晚,但是将来的求职者可能会受益。
这也困扰着我,所以我想我会变得肮脏不堪,写我的第一个脚本。必须安装zenity软件包(sudo apt-get install zenity),但我确定它可能已经存在。另外,我使用wmctrl(窗口管理器控件)在完成时更改进度对话框的标题,它易于安装,但如果没有的话,不会有所作为。我只想在面板中查看完成的时间。
该脚本主要要求提供源目录和目标目录,并使用du计算目标在源中占源的百分比,并显示进度条。
注意:这仅适用于完整的目录/文件同步(我通常使用它来备份apt缓存),因此没有--exclude = / file / in / Source-directory选项。如果目标目录中没有源目录中的文件/目录,也将不起作用。我不确定它是否适用于远程源/目的地,因为从来没有我需要它或资源来对其进行测试。
PS。该脚本可能写得很差或效率很低(此处为纯脚本),但至少可以达到目的,当然,欢迎您对其进行编辑和改进以适合您的需求。PSS。另外,无法获得取消按钮来杀死rsync,因此我将其删除。
#!/bin/bash
set -e;
WELC="Running RsyncP as $USER";
function echo_progress()
{
while (($TRANSFER_SIZE > 1000));
do
DEST_SIZE=$(du -s $DEST_FOLDER | cut -d / -f 1);
((TRANSFER_SIZE=$SOURCE_SIZE-DEST_SIZE));
PROGRESS_PERC=$((DEST_SIZE*100/SOURCE_SIZE));
echo $PROGRESS_PERC;
sleep 0.1s;
done;
echo 100;
zenity --info --width=250 --title=RsyncP --text="File syncing complete!";
}
function get_input()
{
dirs=$(zenity --forms --width=500 --title="RsyncP" --text="Enter source And destination directories" --add-entry="Source: " --add-entry="Destination: " --separator=" ");
SOURCE_FOLDER=$(echo $dirs | cut -d' ' -f 1);
DEST_FOLDER=$(echo $dirs | cut -d' ' -f 2);
OPTIONS=-$(zenity --list --title="RsyncP Options" --text="Select rsync options" --separator='' --height=470 --width=470 --checklist --column "activate" --column "Option" --column "Description" FALSE v "Verbose (Terminal only)" FALSE q "Quiet, supress non-error messages (Terminal only)" FALSE P "Progress (Terminal only)" FALSE a "Archive (lrpog)" TRUE r "Recurse into directories" FALSE p "Preserve permissions" FALSE o "Preserve owner" FALSE g "Preserve group" FALSE l "Copy symlinks as symlinks");
zenity --question --no-wrap --title="RsyncP" --width=500 --text="rsync $OPTIONS $SOURCE_FOLDER $DEST_FOLDER\nDo you want to continue?";
SOURCE_SIZE=$(du -s $SOURCE_FOLDER | cut -d / -f 1);
DEST_SIZE=$(du -s $DEST_FOLDER | cut -d / -f 1);
PROGRESS_PERC=$((DEST_SIZE*100/SOURCE_SIZE));
TRANSFER_SIZE=1001;
}
if [ "$(id -u)" != "0" ]; then
zenity --question --title=RsyncP --text="$WELC, Continue?";
get_input;
rsync $OPTIONS $SOURCE_FOLDER $DEST_FOLDER &
echo_progress | zenity --progress --title=RsyncP --no-cancel --auto-close --text="Copying from \n$SOURCE_FOLDER to \n$DEST_FOLDER" ;
else
zenity --question --title=RsyncP --text="$WELC, Continue?";
get_input;
sudo rsync $OPTIONS $SOURCE_FOLDER $DEST_FOLDER &
echo_progress | zenity --progress --title=RsyncP --no-cancel --auto-close --text="Copying from \n$SOURCE_FOLDER to \n$DEST_FOLDER" ;
fi