Search code examples
linuxbashshellprogress-barbackup

How to implement a progress-bar in a backup script


I have a script which i can do a backup of entire system, but i can't see at what progress it is. I found many answers with progress-bar scripts but i don't know how to implement them into my backup script.

My backup script:

#!/bin/bash

Backup_system="Backup_$(date +%Y-%m-%d).tar.gz"

# Record start time by epoch second
start=$(date '+%s')

# List of excludes in a bash array, for easier reading.
excludes=(--exclude=/$Backup_system)
excludes+=(--exclude=/proc)
excludes+=(--exclude=/lost+found)
excludes+=(--exclude=/sys)
excludes+=(--exclude=/mnt)
excludes+=(--exclude=/media)
excludes+=(--exclude=/dev)

if ! tar -czf "$Backup_system" "${excludes[@]}" /; then
  status="tar failed"
elif ! mv "$Backup_system" ~/Backups ; then
  status="mv failed"
else
  status="success: size=$(stat -c%s ~/Backups/$Backup_system) duration=$((`date '+%s'` - $start))"
fi

# Log to system log; handle this using syslog(8).
logger -t Backup_system "$status"

Solution

  • You can use pv, to make a progress bar for every file, as explained here: https://superuser.com/questions/168749/is-there-a-way-to-see-any-tar-progress-per-file