Bash备份脚本进度条

时间:2015-03-26 14:56:58

标签: bash shell tar

我正在创建一个bash脚本,用于备份用户指定的目录。在程序运行的那一刻,用户将看到屏幕上的所有文件都被压缩和复制,有一段时间只需用简单的进度条替换用户看到的内容吗?

#!/bin/bash

ROOT="/Users/Rory/Documents"
ROOT_EXCLUDE="--exclude=/dev --exclude=/proc --exclude=/sys --exclude=/temp --exclude=/run --exlucde=/mnt --exlcude=/media --exlude"
DESTIN="/USer/Rory/Documents"

if [ "$USER" != "root" ]; then
    echo "You are not the root user"
    echo "To use backup please use: sudo backup"
    exit
fi

clear

BANNER1="************************************************"
BANNER2="********* Backup Menu **************************"
BANNER3 ="************************************************"

echo $BANNER1
echo $BANNER2
echo $BANNER3
echo $BANNER3


OPTIONS="BACKUP DESTINATION EXIT"
LIST="1)BACKUP 2)SET DESTINATION 3)EXIT"

select opt in $OPTIONS; do
if [ "$opt" = "EXIT" ]; then
    echo "GOODBYE!"
    clear
    exit

elif [ "$opt" = "BACKUP" ]; then
    echo "BACKING UP FILES..."
    tar cvpfz $DESTIN/backup.`date +%d%m%y_%k%M`.tgz $ROOT $ROOT_EXCLUDE_DIRS
    echo "BACKUP COMPLETE"
    exit

elif [ "$opt" = "DESTINATION"]; then
    echo "DESTINATION IS  $DESTIN/backup.`date +%d%m%y_%k%M`.tgz "
    echo "TO CHANGE ENTER THE NEW DESTINATION..."
    echo "TO LEAVE IT AS IS JUST PRESS ENTER..."
    read NEW_DESTIN

    #IF GREATER THEN 0 ASSIGN NEW DESTINATION
    if [ ${#NEW_DESTIN} -gt 0 ]; then
        DESTIN = "$NEW_DESTIN"
    fi
    clear
    echo $BANNER1
    echo $BANNER2
    echo $BANNER3
    echo $LIST

else
    clear
    echo "BAD INPUT!"
    echo "ENTER 1 OR 2..."
    echo $LIST
fi
done

1 个答案:

答案 0 :(得分:1)

如果使用rsync复制文件,则可以使用--progress参数获取进度条。

rsync --progress ...