0

Hi I want to automate my workflow of creating Postgres dump and downloading it. I want to do it from my local machine, for now I figured it out so far in two seperate commands:

sshpass  -p "FuckinHardPass" ssh  andi@1.2.3.4 "pg_dump -U andi andi_some_db -f /home/andi/PSQL_DUMPS/andi_some_db.sql"

sshpass -p "FuckinHardPass" scp -r andi@1.2.3.4:/home/andi/PSQL_DUMPS/andi_some_db.sql .

how can I join it in one command using pipes etc?

Thanks James Hightower for hint, using your answer I complete it in one command:

sshpass  -p "FuckinHardPass" ssh  andi@1.2.3.4 "pg_dump -U andi andi_some_db" > andi_some_db.sql
andilabs
  • 22,159
  • 14
  • 114
  • 151

1 Answers1

3

As pg_dump defaults to stdout as it's output file, and ssh displays the command's stdout on it's own stdout, you could do something like:

ssh andi@1.2.3.4 'pg_dump -U andi andi_some_db' > andi_some_db.sql

which would save the output from the command on your local disk as andi_some_db.sql

Depending on the size of your dump and the speed of your connection, you could perhaps benefit from pre-compressing your output:

ssh andi@1.2.3.4 'pg_dump -U andi andi_some_db | gzip' > andi_some_db.sql.gz

And so on.