If you're using the Postgres plugin with your Dokku server, such as on Digital Ocean, you may find yourself from time to time needing to export and import data. Just recently, I went through an issue where I needed to spin up a completely new server to fix another issue and that's where I started searching high and low for the ins and outs to get the data from my old server first and then imported onto the new droplet.
Real quick, if you need the Postgres plugin for Dokku, run this after you SSH into your server:
sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git
To create a database:
dokku postgres:create myapp_db
Link the database to your app:
dokku postgres:link myapp_db myapp
Now, if you ever need to export from that database:
dokku postgres:export myapp_db > myapp.dump
To, import data back in:
dokku postgres:import myapp_db < myapp.dump
Simple enough... but what if you need to get the data from your local machine up to the server? That's where the secure copy command comes in for linux based machines allowing you to upload the file over SSH.
In my case on a Digital Ocean server, it looks like this from local command line.
scp /<directory>/myapp.dump [email protected]<server IP>:/root/
A couple of things to note. The holding place for the directory should be replaced by the path in your machine. If you can locate the dump file in the terminal, you can get the path once in you're in that folder simply by issuing the pwd command in the terminal.
Also, do not miss putting the colon after the IP before you specify the folder structure on the server where the file will be copied.
If you need to get a dump from your server after issuing a Dokku Postgres export command, you would do it like this:
scp [email protected]<server IP>:/root/myapp.dump /local/directory/of_your_choosing