Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pipe Output to TAR 1

Status
Not open for further replies.

stoolpigeon

Programmer
Aug 1, 2001
309
US
Can I send the output of a program to TAR?

I've tried and been unable. (I get an error for trying to create an empty archive) I've looked around for something that would show it and have been unable to find anything. So I'm thinking maybe I just can't do it.

I have a postgreSQL database and I use pg_dump to generate a back up file. I want to use tar to put the file on tape.

If I can do that w/one command as a cron job I would like to. Otherwise I'll write a script to run pg_dump and then use tar after that is done.

What I've tried looked like this
Code:
  pg_dump -Fp -f db.tar taa | tar cf /dev/tape
The pg_dum creates the file db.tar and that's what I want tar to write to the tape.


Thanks,
Ron
 
Hi,

For a pipe to work, the output from the first command must be to standard output - for the second command to accept from standard input.

Never used it but from what I can tell, pg_dump will generate to standard output by default so you don't need the -f option to create an intermediate file. One thing though for info - if you were to create an output file - probably best not to use a '.tar' extension for the file name as the file output from pg_dump is not a tar archive but will be a postgresql script file.

So the command you are looking for is:

pg_dump -Fp taa | tar cf /dev/tape


However, if you do want to create a file in particular, then you could use 'cat' to output the file to standard output for further piping. Putting it on one line rather thn two:

pg_dump -Fp -f taa.bak taa; cat taa.bak | tar cf /dev/tape



Finally, the output file is plain text so would benefit from compression if being put on tape. I think pg_dump will compress automatically if you use a different format option rather than -Fp (check the man page) but you can also get tar to compress for you using either:

tar cfz or
tar cfZ

depending on what compression programs you have installed - again, see the man page.
 
Thanks a ton Norwich - makes so much sense when I look at it now. (I'm new to Linux which is pretty obvious I guess)

My database is very small so I wont be compressing it for right now. The size of the file is much smaller than the capacity of my tape drive.

Thank you again for your help.
 
Why not eliminate the redirection. If the archive taa.bak exists, just tar it directly without the cat. Simply, pg_dump -Fp -f taa.bak taa;tar cf /dev/tape taa.bak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top