<p>What is the most efficient, secure way to pipe the contents of a postgresSQL database into a compressed tarfile, then copy to another machine?</p>

<p>This would be used for localhosting development, or backing up to a remote server, using *nix based machines at both ends.</p>

This page
has a complete backup script for a webserver, including the pg_dump output.
Here is the syntax it uses:
```
```
BACKUP="/backup/$NOW"
PFILE="$(hostname).$(date +'%T').pg.sql.gz"
PGSQLUSER="vivek"
PGDUMP="/usr/bin/pg_dump"

$PGDUMP -x -D -U${PGSQLUSER} | $GZIP -c > ${BACKUP}/${PFILE}
```
```
After you have gzipped it, you can transfer it to the other server with
scp
,
rsync
or
nfs
depending on your network and services.