Supabase Postgres DB With Wasabi
    • 20 Jun 2024
    • 3 Minutes to read
    • PDF

    Supabase Postgres DB With Wasabi

    • PDF

    Article summary

    How do I backup Supabase Postgres DB and upload it to Wasabi?

    Wasabi is validated for use with Supabase to backup and restore Postgres DB. 

    This article assumes that you have already installed the PostgreSQL (psql) tool. For more information on installation, review PostgreSQL Downloads.

    Creating a Supabase Organization and Project

    To create an account:

    1. Navigate to Supabase to create an account. Create the organization and project. Fill in the name, type of organization, select the pricing plan, and click on Create organization.

      Supabase's pricing plan allows databases up to 500 MB in size with two Core shared CPUs and 1GB RAM. Choose a pricing plan based on your database size and CPU requirements. 

    2. Once the organization is created, a window opens to Create a new project. Create a password for the database and select the region according to the use case. You may select any region and this does not have to match the region containing your bucket. 

      Graphical user interface, application Description automatically generated

    Creating an Account Access Token in Supabase 

    1. Once the Supabase project is created and activated, click Access Tokens on the Supabase account dashboard to generate the Access Token. 

      The region indicated in the project dashboard is the AWS region where your Supabase project is hosted.

      Supabase simplifies the process of handling user authentication by providing a seamless login experience using access tokens. 

    2. Generate an Access token to configure and link with Supabase CLI. Copy the newly created access token to a secure place.  

      Graphical user interface, application Description automatically generated

    Configuring the Supabase CLI 

    The Supabase CLI provides tools to develop your project locally, deploy to the Supabase Platform, handle database migrations, and generate types directly from your database schema. 

    For more detail on installing Supabase CLI, review Installing the Supabase CLI.

    1. Once Supabase CLI is installed, link the Supabase CLI with the existing project using an access token.  
    2. Execute the following command in the terminal. 

      — supabase login --token <Account Token> 

       

    3. Verify that the account is linked using the Supabase CLI.   

      — supabase projects list 

    4. Initialize the Supabase environment using the command below. 

      — supabase init 

    5. Link the project to the Supabase CLI. By running the following command and choosing the project, you can link the Supabase project with the Supabase CLI. When prompted, enter the password for the database. 

      — supabase link

      Waterfall chart Description automatically generated

    6. Create the tables and add data to the tables based on your use case.

    In the example below, we added dummy data by creating a new table and uploaded it from a CSV file. 

    Table Description automatically generated

    Creating a Snapshot of Postgres DB 

    1. Once the project is linked with Supabase CLI, execute the following command to dump the database.  

      — pg_dumpall -h [database-host] -U [database-user] -f /tmp/customersdumpten.sql 

    2. Replace the database host from the database configuration in Project settings. Replace the database-user in the command. When prompted, enter the password. 

      Graphical user interface, text, application Description automatically generated

    Uploading the Database Snapshot to Wasabi 

    1. Create a bucket in the Wasabi account. For more information, review Creating a Bucket.
    2. Create access keys and secret keys for the Wasabi account. For more information, review Creating a Wasabi API Access Key Set.

      Database snapshots can be uploaded to the Wasabi bucket through the Wasabi Console, Wasabi Explorer, or any third-party S3-compatible tool. For larger databases, Wasabi recommends uploading through AWS CLI. 

    3. Configure the AWS CLI with the Wasabi access keys and secret keys. For more information, review How do I use AWS CLI with Wasabi?
    4. You may configure the Wasabi credential with the profile name or proceed with the default. 
    5. Once the AWS CLI is set up, upload the database snapshot to the Wasabi bucket by running the following command and substituting your Wasabi bucket name. 
      The following example discusses the use of Wasabi's eu-central-1 storage region. To use other Wasabi storage regions, use the appropriate Wasabi service URL, as described in What are the service URLs for Wasabi's different storage regions?

      — aws s3 cp /tmp/customersdumpten.sql s3://[wasabi-bucketname] --endpoint-url=https://s3.eu-central-1.wasabisys.com --profile wasabi 

    Restoring the Database Dump to Supabase Project 

    Before restoring the dump file, be sure that any extensions or wrappers that were enabled in the previous project are enabled in the same way in the new Supabase project.  

    Sample extensions page:

    Graphical user interface, application, Teams Description automatically generated

    — psql -h [database-host] -d postgres -U [database-user] -f /tmp/customersdumpten.sql 

    1. Replace the database host and database-user with the actual string from project settings. Enter the password for the new project database. 

    2. Click Tables on the Supabase project dashboard to confirm that the database was successfully restored.  

      A screenshot of a computer Description automatically generated

    For more questions, submit a request.