Skip to content
hard-drive

GitHub Action

Postgres Restore from SQL Backup

v6 Latest version

Postgres Restore from SQL Backup

hard-drive

Postgres Restore from SQL Backup

Restore from a Postgres Backup

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Postgres Restore from SQL Backup

uses: tj-actions/pg-restore@v6

Learn more about this action in tj-actions/pg-restore

Choose a version

Codacy Badge CI Update release version. Public workflows that use this action.

Restore a postgres service container using a sql backup file with psql.

Note

  • This only supports sql backups.

Prerequisite

Create a backup using

$ cd [project_root]
$ mkdir backups
$ pg_dump -O -f backups/backup.sql $DATABASE_URL

See: https://github.com/tj-actions/pg-dump

Usage

Using the default PostgreSQL installed on the runner

...
    steps:
      # Checkout the repository
      - uses: actions/checkout@v4

      # Run pg-restore
      - name: Postgres Backup Restore
        uses: tj-actions/pg-restore@v6
        with:
          database_url: "postgres://test_user:test_password@localhost:5432/test_db"
          backup_file: "backups/backup.sql"

Using a different PostgreSQL version

...
    steps:
      # Checkout the repository
      - uses: actions/checkout@v2

      # Run pg-restore
      - name: Postgres Backup Restore
        uses: tj-actions/pg-restore@v6
        with:
          database_url: "postgres://test_user:test_password@localhost:5432/test_db"
          backup_file: "backups/backup.sql"
          postgresql_version: "15"  # Note: Only the major version is required e.g. 12, 14, 15

Inputs

INPUT TYPE REQUIRED DEFAULT DESCRIPTION
backup_file string true Backup file name
database_url string true Database URL
options string false Extra options to pass directly
to psql
postgresql_version string false Version of PostgreSQL. e.g 15

If you feel generous and want to show some extra appreciation:

Buy me a coffee

Credits

This package was created with Cookiecutter.

Report Bugs

Report bugs at https://github.com/tj-actions/pg-restore/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your workflow that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.