plugin-barman-cloud icon indicating copy to clipboard operation
plugin-barman-cloud copied to clipboard

Unable to restore db backup on local machine

Open beingvishalt opened this issue 9 months ago • 5 comments

I am using CNPG 1.26 with Barman Plugin 0.11.0 on ak8s.

I taken the backup of one of DB cluster on azure blob storage.

I am able to restore db backup on same ak8s cluster .

Is there any way to restore that backup on local machine by downloading that backupfiles from blob storage.

And if possible which file required only backup.info and base folder files that is zip file or wal files also required?

@dosu please help

beingvishalt avatar Feb 14 '26 08:02 beingvishalt

Yes, you can restore a Barman Cloud backup on a local machine using the Barman CLI tools directly. Here's what you need:

Required Files:

Local Restoration Steps:

  1. Install Barman CLI tools and ensure you have Azure credentials configured

  2. List available backups:

    barman-cloud-backup-list --cloud-provider azure-blob-storage \
      https://<storage-account>.blob.core.windows.net/<container> <server-name>
    
  3. Restore the base backup:

    barman-cloud-restore --cloud-provider azure-blob-storage \
      https://<storage-account>.blob.core.windows.net/<container> \
      <server-name> <backup-id> /path/to/pgdata
    
  4. Configure WAL recovery — create recovery.signal and add to postgresql.conf:

    restore_command = 'barman-cloud-wal-restore --cloud-provider azure-blob-storage https://<storage-account>.blob.core.windows.net/<container> <server-name> %f %p'
    recovery_target_action = promote
    
  5. Start PostgreSQL — it will replay WALs and promote automatically

You can also use the CNPG PostgreSQL container image which has the Barman tools pre-installed:

docker run --rm -it -v $(pwd)/credentials:/var/lib/postgresql/.azure/credentials \
  ghcr.io/cloudnative-pg/postgresql:18.0 bash

Note: Local restoration outside Kubernetes is not officially supported but is technically possible using these standard Barman tools.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about plugin-barman-cloud with Dosu Add Dosu to your team

dosubot[bot] avatar Feb 14 '26 08:02 dosubot[bot]

I don’t have credentials or access to direct blob storage . I will get the downloaded all files base as well as wal files. So can we restore it on local

@dosu

beingvishalt avatar Feb 14 '26 08:02 beingvishalt

Yes, you can restore locally from downloaded files, but you'll need to do it manually using standard PostgreSQL recovery — not through the Barman Cloud tools (which expect object storage access).

Manual Restore Process:

  1. Extract the base backup tarball to a local directory (this will be your PGDATA):

    mkdir /path/to/pgdata
    tar -xvf base/<backup-tarball>.tar -C /path/to/pgdata
    
  2. Create a WAL archive directory and copy all your downloaded WAL files there:

    mkdir /path/to/wal_archive
    cp /downloaded/wals/* /path/to/wal_archive/
    
  3. Configure PostgreSQL for recovery — create a recovery.signal file in PGDATA and add to postgresql.conf:

    restore_command = 'cp /path/to/wal_archive/%f %p'
    recovery_target_action = promote
    
  4. Fix permissions (PostgreSQL requires specific ownership):

    chown -R postgres:postgres /path/to/pgdata
    chmod 700 /path/to/pgdata
    
  5. Start PostgreSQL:

    pg_ctl -D /path/to/pgdata start
    

PostgreSQL will replay the WAL files and then promote itself to a primary.

Important: Make sure you have all necessary WAL files — PostgreSQL recovery will fail if any required WAL segment is missing. The backup needs WALs from BeginWal to EndWal at minimum for a consistent restore.

This is a standard PostgreSQL restore procedure and works independently of CloudNativePG/Barman.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about plugin-barman-cloud Share Dosu with your team

dosubot[bot] avatar Feb 14 '26 09:02 dosubot[bot]

@dosu, I downloaded manually wals and base backup zip file. Extracted it and done some changes in postgres.config and custom.config as i am using windows not linux os. My backup restored successfully. I can connect to that server using superuser and app user as well with respective password.

But when i edit pg_hba.config And done some changes such as host all all 127.0.0.1/32 trust then i am able to connect to server even without password. How ? If i can connect to db server even without password just by small line change in phg_hba.config then it is not secure.

beingvishalt avatar Feb 27 '26 15:02 beingvishalt

Great to hear your restore worked!

The behavior you're seeing is expected and by design in PostgreSQL — it's not a security flaw, but rather how PostgreSQL's authentication system works.

Why this happens:

pg_hba.conf is PostgreSQL's Host-Based Authentication file. When you set trust as the authentication method:

host all all 127.0.0.1/32 trust

You're explicitly telling PostgreSQL: "Trust anyone connecting from 127.0.0.1 — don't require a password." This is intentional behavior.

Why it's still secure in practice:

  1. File system access = full control — If someone can edit pg_hba.conf, they already have OS-level access to your server. At that point, they could also access the data files directly, so password authentication wouldn't stop them anyway.

  2. In Kubernetes/production, pg_hba.conf is managed by the operator and users don't have direct file system access to the pods.

  3. The real security boundary is protecting access to the server/container itself, not the config files inside it.

For your local setup, if you want password authentication, use:

host all all 127.0.0.1/32 scram-sha-256

or

host all all 127.0.0.1/32 md5

This is standard PostgreSQL behavior — CloudNativePG/Barman doesn't change this. The security model assumes whoever controls the config files controls the database.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about plugin-barman-cloud with Dosu Add Dosu to your team

dosubot[bot] avatar Feb 27 '26 15:02 dosubot[bot]