Configuration
Databases
PostgreSQL

PostgreSQL

GoBackup uses pg_dump utility to backup PostgreSQL database into a .sql file.

Install tool

$ sudo apt install postgresql-client

Config keys

type: postgresql

  • host - PostgreSQL server host, default: localhost
  • port - PostgreSQL server port, default: 5432
  • socket - PostgreSQL server, if use socket, for example: /var/run/postgresql/.s.PGSQL.5432, default: ``
  • database - database name
  • username - default: root
  • password
  • tables - Array of tables to backup, default: []
  • exclude_tables - Array of tables to exclude from backup, default: []
  • args - More additions arguments for pg_dump

https://github.com/gobackup/gobackup/blob/main/database/postgresql.go (opens in a new tab)

Includes or excludes tables

In some times you may wants backup without some tables, you can use --table or --exclude-table to do that.

For example we wants exclude all tables with _logs in name suffix:

args: --exclude-table="*_logs"

Or we wants just backup some tables:

args: --table="users" --table="posts"

Example

models:
  my_app:
    databases:
      my_app:
        type: postgresql
        host: localhost
        port: 5432
        database: my_app_production
        username: root
        password: root
        tables:
          - users
          - posts
        exclude_tables:
          - logs
          - logs_1
        args: --if-exists --no-owner --exclude-table="*_logs"

Restore Database

You can use psql command to restore database.

We need to download the backup file first, and extract the archive file into .sql file.

Now we may have a my_app/my_app/my_app_production.sql.

Use this command to restore database:

$ psql -U postgres -d my_app_production -f my_app/my_app/my_app_production.sql