Re: question about piping and standard output



On 2006-05-31, Ben wrote:
Hi,

As part of a backup scheme, I use the dump program to create weekly
level 0 dumps to a disk. These dump files end up being huge, larger
than 2 gb, so I use split to split them down to 2 gb, so the command
goes something like:

dump -0 -a -u -f - /dev/sda1 | split -b2000m - foo.dump

It creates several 2 gb files such as foo.dumpaa, foo.dumpab, ...
resulting from the split command.

The question is, how can I also include tar and gzip in this command
line to tar and gzip the split'd files?

You've just split a big file, why would you want to use tar? Tar is
for combining multiple files in a single archive. It doesn't do any
compression.

I'm not familiar enough with how shell variables, pipes, and redirects
work to make this combination happen as I want. I could make a script
to plow through the files after the dump is done. It seems more
'elegant' to do it on one line -- because linux is all about elegance.

Crunching a two-line job into a single line is not elegant; it's
foolish. If you want a one-line command, put the lines into a file,
make it executable, and put it in a directory in your PATH.

I would like for the files to have the .tgz or .tar.gz extension
(i.e., foo.dumpaa -> foo.dumpaa.tgz).

No, you don't.

Why don't you compress the file before splitting it? Untested:

dump -0 -a -u -f - /dev/sda1 | gzip -c | split -b2000m - foo.dump

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.



Relevant Pages