Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5be45c3
feat(ansible): add pgBackRest tasks and configurations
jchancojr Oct 29, 2025
32ffede
fix(setup-pgbackrest.yml): update nix install path
jchancojr Oct 29, 2025
16c6474
fix(setup-pgbackrest.yml): fix file module
jchancojr Oct 29, 2025
9bb0eb8
fix(setup-pgbackrest.yml): errant indentation fix
jchancojr Oct 29, 2025
e9b3216
Merge remote-tracking branch 'origin/PSQL-773' into PSQL-773
hunleyd Oct 30, 2025
56e3d22
fix(setup-pgbackrest): adjust as per Sam
hunleyd Oct 30, 2025
6b71d69
style(setup-pgbackrest.yml): ansible-lint
jchancojr Oct 30, 2025
7345b6a
refactor(setup-pgbackrest.yml): refactor as per Sam
jchancojr Oct 30, 2025
b191228
fix(setup-pgbackrest): Sanitize pgbackrest wrapper script arguments
hunleyd Nov 12, 2025
365fa48
Merge branch 'develop' into PSQL-773
hunleyd Nov 12, 2025
32c047e
Merge branch 'develop' into PSQL-773
jchancojr Nov 14, 2025
b223518
feat(setup-pgbackrest.yml): add pgbackrest to sudoers
jchancojr Nov 14, 2025
fb412ba
Update ansible/files/pgbackrest_config/pgbackrest.conf
jchancojr Nov 14, 2025
7a50d3b
Update ansible/playbook.yml
jchancojr Nov 14, 2025
865da58
Apply suggestions from code review
jchancojr Nov 14, 2025
6d74ce5
fix(setup-pgbackrest.yml): allow postgres user to run pgbackrest cmds
jchancojr Nov 14, 2025
dc709b7
fix(setup-pgbackrest.yml): add /usr/bin/bash to sudoers task
jchancojr Nov 14, 2025
f7b9c60
Update ansible/tasks/setup-pgbackrest.yml
hunleyd Nov 14, 2025
1d62a99
Update ansible/tasks/setup-pgbackrest.yml
hunleyd Nov 14, 2025
7d4e051
Merge branch 'develop' into PSQL-773
hunleyd Nov 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ansible/files/pgbackrest_config/computed_globals.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[global]
# process-max = 1

[archive-get]
# process-max = 1

[archive-push]
# process-max = 1
18 changes: 18 additions & 0 deletions ansible/files/pgbackrest_config/pgbackrest.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[global]
archive-async = n
archive-copy = y
backup-standby = prefer
compress-type = zst
delta = y
expire-auto = n
link-all = y
log-level-console = info
log-level-file = detail
log-subprocess = y
resume = n
start-fast = y

[supabase]
pg1-path = /var/lib/postgresql/data
pg1-socket-path = /run/postgresql
pg1-user = supabase_admin
14 changes: 14 additions & 0 deletions ansible/files/pgbackrest_config/repo1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[supabase]
repo1-block = y
repo1-bundle = y
# repo1-path = <foo>
repo1-retention-diff = 1
repo1-retention-full = 28
repo1-retention-full-type = time
repo1-retention-history = 0
# repo1-s3-bucket= <foo>
# repo1-s3-endpoint= <foo>
repo1-s3-key-type = auto
# repo1-s3-region = <foo>
repo1-storage-upload-chunk-size = 10MiB
repo1-type = s3
2 changes: 2 additions & 0 deletions ansible/files/pgbackrest_config/repo1_async.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[supabase]
# archive-async = y
3 changes: 3 additions & 0 deletions ansible/files/pgbackrest_config/repo1_encrypted.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[supabase]
# repo-cipher-pass = {{ generated pass }}
# repo-cipher-type = aes-256-cbc
6 changes: 6 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
import_tasks: tasks/setup-wal-g.yml
when: debpkg_mode or nixpkg_mode or stage2_nix

- name: Install pgBackRest
import_tasks:
file: tasks/setup-pgbackrest.yml
when:
- debpkg_mode or nixpkg_mode or stage2_nix

- name: Install Gotrue
import_tasks: tasks/setup-gotrue.yml
tags:
Expand Down
96 changes: 96 additions & 0 deletions ansible/tasks/setup-pgbackrest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
- name: Create pgBackRest group
ansible.builtin.group:
name: pgbackrest
state: present
when:
- nixpkg_mode

- name: Create pgBackRest user
ansible.builtin.user:
comment: pgBackRest user
group: pgbackrest
groups: pgbackrest, postgres
home: /var/lib/pgbackrest
name: pgbackrest
shell: /sbin/nologin
system: true
when:
- nixpkg_mode

- name: Configure sudoers for pgBackRest
ansible.builtin.lineinfile:
create: yes
line: "{{ item }}"
mode: '0440'
path: '/etc/sudoers.d/pgbackrest'
validate: 'visudo -cf %s'
loop:
- 'postgres ALL=(pgbackrest) NOPASSWD: /var/lib/pgbackrest/.nix-profile/bin/pgbackrest'
- 'postgres ALL=(pgbackrest) NOPASSWD: /usr/bin/pgbackrest'
- 'postgres ALL=(pgbackrest) NOPASSWD: /usr/bin/bash'
- 'postgres ALL=(pgbackrest) NOPASSWD: /usr/bin/nix'
- 'pgbackrest ALL=(pgbackrest) NOPASSWD: /usr/bin/bash'
- 'pgbackrest ALL=(pgbackrest) NOPASSWD: /usr/bin/nix'

- name: Install pgBackRest
ansible.builtin.shell: |
sudo -u pgbackrest bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#pg-backrest"
become: true
become_user: pgbackrest
changed_when: true
when:
- stage2_nix

- name: Create needed directories for pgBackRest
ansible.legacy.file:
group: postgres
mode: '0770'
owner: pgbackrest
path: "{{ backrest_dir }}"
state: directory
loop:
- /etc/pgbackrest/conf.d
- /var/lib/pgbackrest
- /var/spool/pgbackrest
- /var/log/pgbackrest
loop_control:
loop_var: backrest_dir
when:
- nixpkg_mode

- name: Symlink pgbackrest.conf
ansible.legacy.file:
force: true
path: /etc/pgbackrest/pgbackrest.conf
src: /etc/pgbackrest.conf
state: link

- name: Move pgBackRest files to /etc/pgbackrest
ansible.legacy.copy:
group: postgres
dest: "/etc/pgbackrest/{{ conf_item['path'] }}/{{ conf_item['name'] }}"
mode: '0644'
owner: pgbackrest
src: "files/pgbackrest_config/{{ conf_item['name'] }}"
loop:
- {name: computed_globals.conf, path: conf.d}
- {name: pgbackrest.conf, path: ''}
- {name: repo1_async.conf, path: conf.d}
- {name: repo1_encrypted.conf, path: conf.d}
- {name: repo1.conf, path: conf.d}
loop_control:
loop_var: conf_item
when:
- stage2_nix

- name: Create pgBackRest wrapper script
ansible.builtin.copy:
content: |
#!/bin/bash
_raw_args="$@"
_sanitized_args=$(echo $_raw_args | sed -e 's/--cmd=[^ ]*//g; s/--repo-host-cmd=[^ ]*//g; s/--config=[^ ]*//g' )
exec sudo -u pgbackrest /var/lib/pgbackrest/.nix-profile/bin/pgbackrest "$_sanitized_args"
dest: '/usr/bin/pgbackrest'
group: 'root'
mode: '0755'
owner: 'root'
Loading