Using pgBackRest with NGX Storage S3 for PostgreSQL Backups
pgBackRest is a powerful backup and restore tool for PostgreSQL that supports NGX Storage S3 integration. This guide provides a comprehensive walkthrough for setting up and using pgBackRest with NGX Storage S3 service as the backup destination. With its support for full, differential, and incremental backups, along with features like compression, encryption, and parallel processing, pgBackRest ensures secure and efficient data protection.
This guide assumes PostgreSQL is already installed and configured on your system. It focuses on configuring pgBackRest to utilize NGX Storage S3 for storing backups.
Step 1: Install pgBackRest
For RHEL / CentOS / Rocky :
# sudo yum install pgbackrest
For Ubuntu / Debian / Pardus :
# sudo apt-get install pgbackrest
Step 2: Configure NGX Storage S3 Bucket
1. Under Shares->S3 menu, click Add S3 User button. Below example we add “pgbackrest” user. Do not forget to copy the secret key !
2. Create a new bucket and assign user to access it.
Step 3: Configure pgBackRest
# mkdir -m 770 /var/log/pgbackrest # chown postgres:postgres /var/log/pgbackrest # mkdir /etc/pgbackrest # touch /etc/pgbackrest/pgbackrest.conf
Create the configuration file at /etc/pgbackrest/pgbackrest.conf with the following content:
[global] repo1-retention-full=3 repo1-type=s3 repo1-path=/s3-path repo1-retention-full-type=count repo1-s3-region=us-east-1 repo1-s3-endpoint=192.168.1.203 repo1-s3-bucket=pgsql repo1-s3-key=pgbackrest repo1-s3-key-secret=secret_key_generated_by_ngx_storage repo1-storage-port=9000 repo-s3-verify-ssl=n repo1-s3-uri-style=path # Force a checkpoint to start backup immediately. start-fast=y # Use delta restore. delta=y # Enable ZSTD compression compress-type=zst compress-level=6 log-level-console=info [mydb] pg1-path=/var/lib/postgresql/14/main
Step 4: Configure PostgreSQL
Edit the postgresql.conf file:
archive_mode = on archive_command = 'pgbackrest --stanza=mydb archive-push %p' restore_command = 'pgbackrest --stanza=mydb archive-get %f %p'
Step 5: Initialize and Backup
Create the stanza for your database:
# sudo -u postgres pgbackrest --stanza=mydb stanza-create
Verify the configuration:
# sudo -u postgres pgbackrest --stanza=mydb --log-level-console=info check
Run a full backup:
# sudo -u postgres pgbackrest --stanza=mydb --type=full backup
Run a differential backup:
# sudo -u postgres pgbackrest --stanza=mydb --type=diff backup
Run an incremental backup:
# sudo -u postgres pgbackrest --stanza=mydb --type=incr backup
Step 6: Restore Backup
Stop the PostgreSQL service:
# sudo systemctl stop postgresql
Restore the backup:
# sudo -u postgres pgbackrest --stanza=mydb --delta restore
Start the PostgreSQL service:
# sudo systemctl start postgresql
Reference Links
COPYRIGHT
© 2025 NGX Teknoloji A.Ş. (NGX Storage). All rights reserved. Printed in the Turkey. Specifications subject to change without notice. No part of this document covered by copyright may be reproduced in any form or by any means-graphic, electronic, or mechanical, including photocopying, recording, taping, or storage in an electronic retrieval system-without prior written permission of NGX Storage. Software derived from copyrighted NGX Storage material is subject to the following license and disclaimer:
THIS SOFTWARE IS PROVIDED BY NGX Storage “AS IS” AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL NGX Storage BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NGX Storage reserves the right to change any products described herein at any time, and without notice. NGX Storage assumes no responsibility or liability arising from the use of products described herein, except as expressly agreed to in writing by NGX Storage. The use or purchase of this product does not convey a license under any patent rights, trademark rights, or any other intellectual property rights of NGX Storage.
TRADEMARK
NGX Storage and the NGX Storage logo are trademarks of NGX TEKNOLOJI A.Ş. Other company and product names may be trademarks of their respective owners.