2

I'm logged into remote using ssh

ubuntu@ubuntu:~$

now I switch to postgres account using sudo su - postgres command and it send me to postgres@ubuntu:~$

now here I'm able to take dump using pg_dump command.

e.g. postgres@ubuntu:~$ pg_dump db_name > mydbdump.sql

so far looks good. but from here I want to copy this dump file to my local machine or even to my origin/default ubuntu user on remote(ubuntu@ubuntu:~$). so that from there I can scp.

how do I copy these dump sql files from postgres acccount to ubuntu on remote?

2
  • After you've created a dump run pwd to determine current directory. It will return something like /var/lib/postgresql. Then return back to your ubuntu user: exit. And copy dump to your user's home directory: cp /var/lib/postgresql/mydbdump.sql ~/mydbdump.sql. After that you'll be able to copy it to your local machine using scp Commented Aug 18, 2016 at 7:37
  • You need to find out, which directory your dump is written to (pwd). Then you just copy it with your normal ubuntu user to your home and use scp: sudo cp /path/to/mydbdump.sql /home/ubuntu/. Now you can use scp: scp [email protected]:/home/ubuntu/mydbdump.sql . and you are done. Futhermore this question rather belongs to serverfault.com or superuser.com Commented Aug 18, 2016 at 7:37

1 Answer 1

3

If you are using ubuntu, default directory would be /var/lib/postgresql

so you can directly scp from remote to local.

On your local machine run this command

user@user:~$ scp [email protected]:/var/lib/postgresql/mydbdump.sql /path/to/local/dir
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.