Tar backup with progress bar
Sorry, but this isn't possible. From the file bar
itself:
Synopsis:
'bar' works just like 'cat', but shows a progress bar in ASCII art on stderr.
The script's main function is meant to be usable in any Bourne shell to be
suitable for install scripts without the need for any additional tool.
The problem is that, in order to display the progress bar, bar
has to know the file's size first.
For extracting an archieve, that's no problem: If backup.tar
is 100 MiB
big and 50 MiB
have been processed so far, we're at 50 %
.
However, for creating an archieve, bar
reads from stdin
, which is infinite for all practical purposes. As the documentation says:
Infinite streams are not nice: the bar is only displayed at 0% and at 100%. [...]
The only way to display progress bars for backup purposes I can think of (besides compiling a custom version of tar with bar) is:
Calculate the accumulated size of the files
/media/data
.Create
backup.tar
and append the files from/media/data
one by one.After each file, calculate the current percentage and display it.
gzip
backup.tar
(you can usetar
for this).
Example:
TOTAL=$(du -b /media/data | grep -oP "^\d+")
CURRENT=0
echo "Archiving:"
IFS="
"
for FILE in $(find /media/data -type f); do
tar rf backup.tar $FILE
CURRENT=$(($CURRENT+$(du -b $FILE | grep -oP "^\d+")))
echo -en "\r"$((100*($CURRENT-1)/$TOTAL+1))"%"
done
echo
echo "Compressing:"
bar backup.tar | gzip > backup.tar.gz
rm backup.tar
Caution:
- This will probably slow down your backup progress.
- File names may not contain newline characters.
Related videos on Youtube
Jens
Updated on September 18, 2022Comments
-
Jens almost 2 years
I would like to add a progress bar to my tar backup command. I found out that the bar shell script should be able to do this, but I am unable to figure out the correct command.
sudo tar pzcf - /media/data | bar > /media/backups/backup.tar.gz
With the above command I was able to display some information, but no progress bar yet.