I'm trying to create a Bash script that does backup of my important files in home folder once, every week. I haven't gotten to the crontab part yet but I've been trying to make this progress bar work. I want to know how long I have to wait for till it's done. I don't want to just put echo "Process ongoing, please wait". Please help

Bash code:

TODAY=$(date +%d-%m-%Y)
echo $TODAY
type pv > $file
if grep -q "pv" $file; then
    echo "exists"
    echo "Installing pv for progress bar"
    sudo apt install pv
#SIZE='du -sk /home/user/{Desktop,Documents,Downloads} | cut -f 1'
sudo tar -pczf /media/backups/backup${TODAY}.tar.gz /home/user/Desktop /home/user/Documents /home/user/Downloads | pv -s 40978228k > /dev/null

I got that 40978228k by calculating what I got from $SIZE in Python. Summed these numbers up, num1 + num 2 + num3 because ${SIZE}k didn't work. It kept saying pv: -s: integer argument expected

1 Answer 1


EDIT: Full code, working!


TODAY=$(date +%d-%m-%Y)
type pv > $f
if grep -q "pv" $f; then
    echo "PV exists"
    echo "Installing PV..."
    sudo apt install pv
echo "Your username is: $(whoami)"
echo "1) Backup your home directory"
echo "2) Extract your backup"
read -p "Choose the option: " choice
if [ -z $choice ]; then
    echo "Choose the option"
elif [ $choice -eq 1 ]; then
    echo "Backup directory: /media/backup/"
    sleep 1
    echo "Backup Process Activated"
    sudo tar -cf - /home/$(whoami) -P | pv -s $(du -sb /home/$(whoami) | awk '{print $1}') | gzip > /media/extracted/$f2
elif [ $choice -eq 2 ]; then
    echo "Extracting your backupped home directory from /media/backup/"
    echo "Extracted directories go to /media/extracted/"
    sleep 1
    echo "Extraction Process Activated"
    pv /media/extracted/$f2 | sudo tar -xzf - -C /media/extracted/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy