dokku / dokku-postgres

a postgres plugin for dokku
MIT License
488 stars 96 forks source link

Export all databases from service #180

Open chemicalkosek opened 5 years ago

chemicalkosek commented 5 years ago

I have deployed a Prisma Server like this: https://www.prisma.io/tutorials/deploy-prisma-to-dokku-ct15

I have named the dokku postgres service 'prismadb'. The Prisma Server is working fine. But I need to do backup of the service.

dokku postgres:export prismadb > prismadb.dump

gives me:

-- PostgreSQL database dump
--

-- Dumped from database version 11.2 (Debian 11.2-1.pgdg90+1)
-- Dumped by pg_dump version 11.2 (Debian 11.2-1.pgdg90+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;

--
-- PostgreSQL database dump complete
--

It's empty, but it should contain some data which I have added. So after doing: dokku postgres:connect prismadb prismadb=# \l

I get:

                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   
-----------+----------+----------+------------+------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 prisma    | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 prismadb  | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
(5 rows)

So after checking logs I see that Prisma during deploy is creating a 'prisma' database. The data is there, I checked. How can I export all databases from the service? Seems like the dokku postgres:export prismadb > prismadb.dump is only exporting the database which is named like the service.

josegonzalez commented 5 years ago

Currently, we only support a single database, so the existing functionality is expected.

The code for export is here, pull requests welcome!

chemicalkosek commented 5 years ago

My Docker knowledge is too thin to help you with the pull request. Could you somehow point me into direction how would I need to run pg_dumpall or maybe pg_dump against another database within dokku postgres service?

josegonzalez commented 5 years ago

There isn't any docker knowledge necessary here. I'm quite literally just running the pg_dump command in that script (its a few lines down from the link I sent).

afunnydev commented 5 years ago

Maybe we could add another argument to specify the table to use in the export. That way, it would be more clear that the db is exporting only one table. Is there any contribution guidelines? Never done this before but I could probably try a PR, looks like simple fix.

josegonzalez commented 5 years ago

Pull requests welcome. I get to them as I have time.

Friss commented 5 years ago

Looks like a good alternative would be exposing the pg_dumpall command

Though I'm not sure if pg_dumpall would fit in as a replacement for the current functionality or something in addition (and how that fits into the organization of this plugin)