borgmatic

PostgreSQL

πŸ”

New in version 1.4.0 To backup PostgreSQL with borgmatic, use the postgresql_databases: hook. For instance:

postgresql_databases:
    - name: users

Full configuration

# List of one or more PostgreSQL databases to dump before creating a
# backup, run once per configuration file. The database dumps are
# added to your source directories at runtime and streamed directly
# to Borg. Requires pg_dump/pg_dumpall/pg_restore commands. See
# https://www.postgresql.org/docs/current/app-pgdump.html and
# https://www.postgresql.org/docs/current/libpq-ssl.html for
# details.
postgresql_databases:
    # Database name (required if using this hook). Or "all" to
    # dump all databases on the host. (Also set the "format"
    # to dump each database to a separate file instead of one
    # combined file.) Note that using this database hook
    # implicitly enables read_special (see above) to support
    # dump and restore streaming.
    - name: users

      # Label to identify the database dump in the backup.
      label: my_backup_label

      # Container name/id to connect to. When specified the
      # hostname is ignored. Requires docker/podman CLI.
      container: debian_stable

      # Container name/id to restore to. Defaults to the
      # "container" option.
      restore_container: restore_container

      # Database hostname to connect to. Defaults to connecting
      # via local Unix socket.
      hostname: database.example.org

      # Database hostname to restore to. Defaults to the
      # "hostname" option.
      restore_hostname: database.example.org

      # Port to connect to. Defaults to 5432.
      port: 5433

      # Port to restore to. Defaults to the "port" option.
      restore_port: 5433

      # Username with which to connect to the database. Defaults
      # to the username of the current user. You probably want
      # to specify the "postgres" superuser here when the
      # database name is "all". Supports the "{credential ...}"
      # syntax.
      username: dbuser

      # Username with which to restore the database. Defaults to
      # the "username" option. Supports the "{credential ...}"
      # syntax.
      restore_username: dbuser

      # Password with which to connect to the database. Omitting
      # a password will only work if PostgreSQL is configured to
      # trust the configured username without a password or you
      # create a ~/.pgpass file. Supports the "{credential ...}"
      # syntax.
      password: trustsome1

      # Password with which to connect to the restore database.
      # Defaults to the "password" option. Supports the
      # "{credential ...}" syntax.
      restore_password: trustsome1

      # Do not output commands to set ownership of objects to
      # match the original database. By default, pg_dump and
      # pg_restore issue ALTER OWNER or SET SESSION
      # AUTHORIZATION statements to set ownership of created
      # schema elements. These statements will fail unless the
      # initial connection to the database is made by a
      # superuser.
      no_owner: true

      # Database dump output format. One of "plain", "custom",
      # "directory", or "tar". Defaults to "custom" (unlike raw
      # pg_dump) for a single database. Or, when database name
      # is "all" and format is blank, dumps all databases to a
      # single file. But if a format is specified with an "all"
      # database name, dumps each database to a separate file of
      # that format, allowing more convenient restores of
      # individual databases. See the pg_dump documentation for
      # more about formats.
      format: directory

      # Database dump compression level (integer) or method
      # ("gzip", "lz4", "zstd", or "none") and optional
      # colon-separated detail. Defaults to moderate "gzip" for
      # "custom" and "directory" formats and no compression for
      # the "plain" format. Compression is not supported for the
      # "tar" format. Be aware that Borg does its own
      # compression as well, so you may not need it in both
      # places.
      compression: none

      # SSL mode to use to connect to the database server. One
      # of "disable", "allow", "prefer", "require", "verify-ca"
      # or "verify-full". Defaults to "disable".
      ssl_mode: require

      # Path to a client certificate.
      ssl_cert: /root/.postgresql/postgresql.crt

      # Path to a private client key.
      ssl_key: /root/.postgresql/postgresql.key

      # Path to a root certificate containing a list of trusted
      # certificate authorities.
      ssl_root_cert: /root/.postgresql/root.crt

      # Path to a certificate revocation list.
      ssl_crl: /root/.postgresql/root.crl

      # Command to use instead of "pg_dump" or "pg_dumpall".
      # This can be used to run a specific pg_dump version
      # (e.g., one inside a running container). If you run it
      # from within a container, make sure to mount the path in
      # the "user_runtime_directory" option from the host into
      # the container at the same location. Defaults to
      # "pg_dump" for single database dump or "pg_dumpall" to
      # dump all databases.
      pg_dump_command: docker exec my_pg_container pg_dump

      # Command to use instead of "pg_restore". This can be used
      # to run a specific pg_restore version (e.g., one inside a
      # running container). Defaults to "pg_restore".
      pg_restore_command: docker exec my_pg_container pg_restore

      # Command to use instead of "psql". This can be used to
      # run a specific psql version (e.g., one inside a running
      # container). Defaults to "psql".
      psql_command: docker exec my_pg_container psql

      # Additional pg_dump/pg_dumpall options to pass directly
      # to the dump command, without performing any validation
      # on them. See pg_dump documentation for details.
      options: --role=someone

      # Additional psql options to pass directly to the psql
      # command that lists available databases, without
      # performing any validation on them. See psql
      # documentation for details.
      list_options: --role=someone

      # Additional pg_restore/psql options to pass directly to
      # the restore command, without performing any validation
      # on them. See pg_restore/psql documentation for details.
      restore_options: --role=someone

      # Additional psql options to pass directly to the analyze
      # command run after a restore, without performing any
      # validation on them. See psql documentation for details.
      analyze_options: --role=someone

Improve this documentation

Have an idea on how to make this documentation even better? Use our issue tracker to send your feedback!