I have written a script to synchronize (recreating from scratch) a production database with a development database, and I wanted insight into potential security flaws/issues, the script is posted below. The server has remote access disabled for security purposes, and ssh authentication is managed using publickey authentication.
#!/bin/bash
#this is pretty seriously sketchy script...
current_time=`date +%s`
dump_file_name=/tmp/temporary_dump_$current_time.dump
echo SSHing and dumping to $dump_file_name
ssh -t remoteuser@remote.server.amazonaws.com << EOT
pg_dump -U postgres -Fc dbName > $dump_file_name
PASSWORD #password in plain text
exit
EOT
echo SCPing the file locally to: `pwd`$dump_file_name
scp remoteuser@remote.server.amazonaws.com:$dump_file_name $dump_file_name
echo Cleaning up the remote file
ssh -t remoteuser@remote.server.amazonaws.com << EOT
rm $dump_file_name
exit
EOT
ssh -t development@development-testing << EOT
pg_restore --clean --dbname=dbName -Fc --username=postgres -W $dump_file_name
PASSWORD #password in plain text
exit
EOT
echo Cleaning up the local file
rm $dump_file_name
exit 0