Hello all.
I'm working on a scripting project and it would be very helpful if I could make tar, zip, and rar treat named pipes just like regular files when creating an archive. That is, it would be nice if these programs would, upon encountering a named pipe, read all of the input from it and place that input into an entry in the resulting archive named the same way as the named pipe.
What I need is similar to what
tar h,
zip without the
-y option, and
rar without the
-ol option do for symlinks, only I need to do that for named pipes.
So, for instance, this sequence of instructions:
Code:
mkdir ~/bashtest
cd ~/bashtest
mkdir arcdir
echo "This is a file" > arcdir/file1
echo "This is a symlinked file" > sfile
ln -s sfile arcdir/file2
mkfifo arcdir/file3
echo "This is a fifo" > arcdir/file3 &
tar c?hf archive.tar arcdir
mkdir ~/untarred
cd ~/untarred
tar xf ~/bashtest/archive.tar
ls -l arcdir
cat arcdir/file1 arcdir/file2 arcdir/file3
Would produce this as output:
Code:
total 12
-rw-r--r-- 1 user user 15 Oct 20 22:57 file1
-rw-r--r-- 1 user user 25 Oct 20 22:57 file2
-rw-r--r-- 1 user user 15 Oct 20 22:57 file3
This is a file
This is a symlinked file
This is a fifo
Instead of this:
Code:
total 12
-rw-r--r-- 1 user user 15 Oct 20 22:57 file1
-rw-r--r-- 1 user user 25 Oct 20 22:57 file2
prw-r--r-- 1 user user 9 Oct 20 22:57 file3
This is a file
This is a symlinked file
This is a fifo
I've thoroughly combed
man tar,
man zip, and
man rar and googled for information on this, but I've found no solution so far.
If you want the long version of the story, I'm writing a script which will reside on a web server to which I and a few others admins have SSH access. This script, when invoked, will backup a directory structure and a mysql database and output the resulting .tar.gz, tar.bz2, .zip, or .rar data directly to stdout. That way, on our respective boxen, we will be able to make a backup with something like:
Code:
ssh admin@server.com ~/backup.sh > mybackup.tar.gz
(Or its equivalent on Win or Mac).
I'm working with limited disk space on the server, so I didn't want to duplicate the existing files and dump the MySQL data into a temporary file so that I could
tar zcf - the directory. So, I had the bright idea to create a temporary directory containing a symlink to the directory to be backed up and a named pipe to which I would dump the output of mysqldump.
I was thinking something like this would work:
Code:
cd ~
mkdir ~/tempdir
ln -s ~/public_html tempdir/files
mkfifo tempdir/mysql_dump.sql
mysqldump ... > tempdir/mysql_dump.sql &
tar zcvh?f - tempdir
rm -rf tempdir
(Of course, it will need to be a bit more involved than that, what with supporting multiple archive/compression formats and such.)
But, I've found no way to make these archivers do what I need them to do for this to work.
I tried using a symlink to a named pipe with
tar h, but tar was too smart to be tricked so easily.
Any and all help would be greatly appreciated. Thanks very much for your time.