Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 am trying to get a handle on how to pipe from a command into something like gzip, cpio or tar.

The commands in question belong to the ZFS system. I am running ZFS on Ubuntu Linux 10.04.3.

The commands I working with are;

To create a snapshot;
zfs snapshot media/mypictures@20070607

To copy the snapshot to a directory;
zfs send media/mypictures@20070607 > ~/backups/20070607

Then I can also pipe into gzip
zfs send media/mypictures@20070607 | gzip > ~/backups/20070607.gz

These parts I understand.

But my first question is, what would I do to pipe into tar + gzip?

This?

zfs send media/mypictures@20070607 | tar czvf > ~/backups/20070607.tar.gz

And my other question is how would I get the data out of the tarball or gzip?

I have to use zfs recieve media/mypictures@20070607 < ~/backups/20070607

So would it just be this if I was using tar?

zfs recieve media/mypictures@20070607 | tar xzvf < ~/backups/20070607.tar.gz

Any idea?

share|improve this question
up vote 4 down vote accepted

tar expects to be given a list of filenames as command line arguments. So far as I know, it cannot be used to read an anonymous pipeline (what would it store as filename and file-metadata?)

$ echo aaa | tar cv > f.tar
tar: Cowardly refusing to create an empty archive
Try `tar --help' for more information.

If your data is a single logical item or stream, there is no need to use something like tar, which is used to group together a set of separate files.

Otherwise you will have to write the data to a file first, tar the file, then delete the file.

share|improve this answer
    
Really? I though tar was just another form of compression. So skip tar and just gzip? – ianc1215 Sep 22 '11 at 17:59
1  
Yes, just use zfs send media/mypictures@20070607 | gzip -c > ~/backups/20070607.gz – RedGrittyBrick Sep 22 '11 at 19:01
    
perfect, thanks. – ianc1215 Sep 22 '11 at 19:13
    
Tar DOES NOT expect a list of file names unless you specify the -f option (tar also accepts f without the "-"). – drevicko Feb 2 at 15:55
    
@drevicko: The context of the question is creating a tar archive. The list of files I mean is the list of files (and/or directories) to be included in the written archive. For example: cd /etc; TAPE=/tmp/rgb.tar tar c hosts passwd where the list of files is hosts passwd – RedGrittyBrick Feb 2 at 16:38

The -f option specifies a file, else the output goes to stdout. So, either drop the redirection:

zfs send media/mypictures@20070607 | tar czvf ~/backups/20070607.tar.gz

Or drop the f option:

zfs send media/mypictures@20070607 | tar czv > ~/backups/20070607.tar.gz

Similarly with untarring.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .