Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use pv (pipeviewer) along with tar to do tape backups in order to see the progress and eta like so:

du -s /home/myuser
115630916   /home/myuser
tar -cf - /home/myuser/ | pv -s 115630916 > /dev/nst0

Which works fine, it writes to tape successfully. But once I try and test the tar archive:

mt -f /dev/nst0 rewind
tar -tvf /dev/nst0

I get the following errors:

tar: /dev/nst0: Cannot read: Cannot allocate memory
tar: At beginning of tape, quitting now
tar: Error is not recoverable: exiting

I've googled around and there have been suggestions that I use --blocking-factor=128 when creating my backup and restoring. I still get the same error.

It's also worth noting that if I just use tar, everything works 100%, including the restore, so perhaps pv is breaking it?

share|improve this question
up vote 3 down vote accepted

Solved it, pv was creating a different block / buffer size ...

From the pv man page:

The default buffer size is the block size of the input file’s filesystem multiplied by 32 (512kb max), or 400kb if the block size cannot be determined.

From the tar man page:

block size of Nx512 bytes (default N=20)

So give the correct buffer size to pv as (20 x 512 = 10240)

tar -cf - /home/myuser/ | pv -B 10240 -s 142524k > /dev/nst0

Now if you test the archive with tar -tvf /dev/nst0, it should work.

share|improve this answer

I had a very similar error, but I wasn't using pv or anything else in a pipe between tar and the tape device.

The blocking factor bit is the key, though. I'd read that for best results, you should use a larger block size than the default, so i had used blocking factor 512 on the tar command line:

tar -b 512 -cf /dev/tape files

Unfortunately, tar doesn't automatically figure out the blocking factor, and you need to specify it on the restore too.

tar -b 512 -xpf /dev/tape
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.