Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been trying to track the progress of the data in a pipe, specifically in a large init script for a minecraft server. How would I go about using pv to get an accurate readout of progress?

I've tried the following command, where $WORLDBACKUPSIZE is the size of the folder to be backed up, $path is the path that it should be backed up to, and $MCPATH/${WORLDNAME[$INDEX]} is the folder that should be backed up, except that pv stops halfway through due to the size being the size of the folder and it is only counting the compressed bytes that pass through.

I want it to count the bytes that are compressed in the tar command instead, so I can use the original size as the ending mark for the progress meter. Simply put, I'm trying to tar a folder and monitor progress using pv. The total size that pv is using to tell me an estimated percentage is based of the original size, while the size that it is measuring when the tar command is running is the compressed size so the progress bar stops early with the percentage completed at the end depending on the size of the compressed folder compared to the size of the original folder.

The command

WORLDBACKUPSIZE=`du -sk $WORLDSTORAGE/${WORLDNAME[$INDEX]} | cut -f 1`

is used to measure the folder that I want to back up.

The command

tar -hcjf - $MCPATH/${WORLDNAME[$INDEX]} | pv -reps ${WORLDBACKUPSIZE}k > $path

is used to measure the progress. How would I rearrange this so that I am measuring the progress by the number of bytes that are taken into the tar command, and not the number that are put out?

share|improve this question
add comment

migrated from stackoverflow.com Nov 21 '12 at 9:50

This question came from our site for professional and enthusiast programmers.

1 Answer

You could start with a simple (but not so great, and maybe a Useless Use Of Cat):

cat "$MCPATH/${WORLDNAME[$INDEX]}" \
| pv -reps "${WORLDBACKUPSIZE}k" \
| tar -hcjf - > $path/somename

The last line could be tar -hcjf $path/somename, but I kept it close to the original, to point out that I think a filename was maybe missing, unless "path" contains a path AND a filename already.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.