Surely, there must be a better way to do this...
Some small research time later I discovered netcat, or nc for short. nc lets you create a pipe over a network. As its man page states, it's a TCP/IP swiss army knife.
This is how I ended up automating most of the process.
On my local machine:
nc -l -p 1979 | bunzip2 | psql database_name
On the remote machine:
pg_dump database_name | bzip2 | nc my_local_ip 1979
Voila! The database dumped its data, piped it through bzip2 then over the network, to my waiting nc process which received the data, then piped it through bunzip2 and then into psql.
Cool. Another demonstration showing that Unix is such a great environment.
7 comments:
How about this:
ssh -C remote-machine pg_dump database_name | psql database_name
You might want to check out 'socat' as a 'nc' replacement. Its functionality is a superset of 'nc'.
ssh -C remote-machine pg_dump database_name | psql database_name
This is cool, but I don't know of anyway to get ssh to compress its traffic. I'm transferring 2GB over a rather slow connection, so bzip2 saves me hours!
"-C" does compress the traffic.. not as much as bzip2.. but good enough...
Ah cool. It pays to read man pages :)
-C Requests compression of all data (including stdin, stdout, stderr, and data for forwarded X11 and TCP connections). The compression algorithm is the same used by gzip(1).
mmmm echo drop database;| bzip2 | nc my_local_ip 1979
:)
Hahaha! A simple and irrefutable argument to use ssh instead of nc.
Post a Comment