Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Thursday, September 27, 2007

Infinitive possibilities with UNIX pipes



The UNIX pipes are brilliant :)

I have a "Not enough space" message on my Linux production boxes sometimes and I need to archive or dump databases on-line frequently. So, I've created one archiver host (simple Linux with huge RAID HDDs) for all of my machines.

With commands like these the backup process doesn't consume the local storage, the archive file is created remotely:
(use it on the to_be_archived machine!)

$ tar -c ./ | ssh root@backupmachine "cat | gzip > archive.tar.gz"

or
$ tar -cz ./ | ssh root@backupmachine "cat > archive.tar.gz"

It's better than scp, because it stores the ACLs too.

You can use it for database backup:
$ /usr/local/postgresql/bin/pg_dump -t table -U user db | ssh user@backupmachine "cat | gzip > archive.gz"

or
$ /usr/local/postgresql/bin/pg_dump -t table -U user db | gzip | ssh user@backupmachine "cat > archive.gz"


With a script, like this you can on-line dump your Oracle database tables:
*temporal pipe file is created

#!/bin/bash
export ORACLE_SID=
user=dbuser
echo "rm -f pipe
/usr/sbin/mknod pipe p
ssh user@backupmachine "gzip > oraclebackup.gz" < pipe &
exp userid=${user} parfile=backup.par
" > oraclebackup.sh

echo "file=pipe
log=${usr}_arch_.log
compress=N
tables=(
TABLE1,
TABLE2,
TABLE3,
TABLE4
)
buffer=3000000" > backup.par
sh oraclebackup.sh

rm oraclebackup.sh
rm backup.par


It's a simplier example, to archive specific (with find) files remotely:

#!/bin/bash

mknod pipe p
ssh user@backupmachine "gzip > pipe.tar.gz" < pipe &
find -name *bash* | xargs tar cvf pipe

rm pipe


Feel free to comment if you have better methods (because it's sure these are not the bests)