elmama
​A selection of topics on IT and its application to finance. 
​Send me your comments, questions ​or suggestions by clicking
h​ere


Some tips on using UNIX named pipes to backup your database 


If you run Oracle in a UNIX environment and use EXPORT for backing up your database, using the named pipe facility available in your operating system could provide you with significant advantages and flexibility in terms of your storage requirements.

What is a named pipe?

Before talking in detail about using named pipes it's worth reminding ourselves exactly what they are. In simple terms a named pipe is a form of inter-process communication, specifically it's a mechanism that allows two unrelated processes to "speak" to each other. As the simple diagram below shows, process 1 can stuff data into the named pipe where it will stay until process 2 decides to fetch the data.




   Process 1 ------------>    NAMED PIPE      -------------> Process 2
   writes data                                                                         reads data 



When the pipe is full up (the amount of data which fills it up is system dependant but is typically something like 512 bytes) the process writing to it is blocked until another process starts to read the pipe. In effect our data is placed in a temporary holding area where it can be processed further by other utilities. Typically this extra processing may involve some kind of compression to minimize the space taken up by the data.


Using named pipes

Using a named pipe in practice is very easy as once it's created it can be used almost anywhere you'd use a normal file, but as always it's best to see some real examples. In the first of these I'm assuming that the database it too large to fit on your hard disk uncompressed, but will do so if compressed. In the second example I'm assuming that even the compressed data is too large for hard drive storage and that it's required to place the data into secondary storage e.g. magnetic tape.

Example 1.  Compressing the output of an Export

1) Create a named pipe

$ mknod -p /tmp/tmpfile

2) Use the named pipe instead of the regular filename in your export command and run it in the background

$ exp myuser/mypass full=Y file=/tmp/tmpfile &

3) Read the pipe, compress its output and write to a file

$ compress < /tmp/filename > mydb.z

To read the file back in it's just:-

$ mknod -p /tmp/tmpfile
$ uncompress < mydb.z >/tmp/tmpfile &
$ imp myuser/mypass full=Y file=/tmp/tmpfile



Example 2. Re-direct the output of an export to secondary storage


1) Create a named pipe

$ mknod -p /tmp/tmpfile

2) Use the named pipe instead of the regular filename in your export command and run it in the background

$ exp myuser/mypass full=Y file=/tmp/tmpfile &

3) Copy the file to secondary storage

$ dd if=/tmp/tmpfile of=/dev/magtape


To read the file back from magtape it's just:-

$ mknod -p /tmp/tmpfile
$ dd if=/dev/magtape of=/tmp/tmpfile &
$ imp myuser/mypass full=Y file=/tmp/tmpfile