0

I'm trying to create the first copy of my database. I'm using PostgreSQL and Ubuntu 16+ with Django technology.

I found this documentation to create a copy:

I'm trying to export the entire database to a file so that I can add it to another server. I tried this:

pg_dump app_prod > test_copy
pg_dump --host=localhost --username=app --dbname=app_prod --file=testdb.sql

after selecting ls my directory can see the database. But by running eg WinSCP it is not visible.

How can I take these files, copy them to my Windows system and upload to another Ubuntu server?

I think that it is enough to make them visible in WinSCP. How can I do this?

EDIT:

drwxr-xr-x 3 postgres postgres    4096 Oct  4 08:06 9.5
-rw-rw-r-- 1 postgres postgres 3578964 Jan 18 10:46 test_copy
-rw-rw-r-- 1 postgres postgres       0 Jan 18 10:54 testdb.sql
6
  • 1
    Is your WinSCP on your desktop computer, and you are wanting to copy the file from your remote database server to your local computer? If so, I wonder if the permissions/ownership on the testdb.sql file are incorrect. Try writing ls -l and paste the response of that in your question.
    – halfer
    Commented Jan 18, 2020 at 11:38
  • Exactly. I have WinSCP on the local computer (windows).I also have two ubuntu projects. I want to do this process with the database copy file I created. My_current_location_Ubuntu--->Windows--->My_ubuntu_destination_location(another server) I added the command result ls -l above Commented Jan 18, 2020 at 11:49
  • 1
    When you use WinSCP to connect to your server from your Windows machine, can you see the file testdb.sql in the same directory? Commented Jan 18, 2020 at 11:58
  • I run WinSCP on my windows. My application is on Ubuntu and I connect to it through WinSCP. But all of it is only on Windows. I am using SFTP username and password to connect to ubuntu. I cannot see anything through WinSCP in the folder except the directory named "9.5". The file named testdb.sql is also not visible like the second copy of the database. Commented Jan 18, 2020 at 12:14
  • 1
    How do you run pg_dump? Are you using an SSH terminal client like PuTTY? What do you get if you type pwd in the console? Does the output match with the path you see in WinSCP file panel? Commented Jan 18, 2020 at 12:24

1 Answer 1

1

It seems like this was resolved in the comments: you were looking at the wrong folder in the WinSCP folder explorer.

There are a few items worth noting to bolster the good advice already given:

Your ls -l output indicates that the SQL file is zero bytes in size, so something has gone wrong there. If you manage to transfer it to your local machine, you will find it is empty.

Also, try not to store database dumps in /var/lib/postgresql - this is where your PostgreSQL database keeps live database files on the server, and you don't want to risk changing or deleting anything here. Use /home/maddie instead (change the username as appropriate).

1
  • 1
    Instead of redirecting the output, you can use "-f" and specify a path name, possibly an absolute path name, independent from your current working directory. And you can use be custom format, which will compress the backup, possibly speeding up your data transfer. Commented Jan 19, 2020 at 5:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.