Skip to content

Commit 16bd733

Browse files
author
John Rogers
committed
push!
1 parent f318544 commit 16bd733

File tree

4 files changed

+33
-67
lines changed

4 files changed

+33
-67
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ PRIMARY_DBS=your_laterbase_db_names
2525
PGADMIN_EMAIL=your_pgadmin_email@example.com
2626
# Password for the default pgAdmin user login
2727
PGADMIN_PASSWORD=your_pgadmin_password
28+
PGADMIN_ACCESS_SUBNET=192.168.65.0/24 # Subnet allowed to connect to standby (e.g., Docker network, VPN)
29+
PG_REALWORLD_SUBNET=YOUR_LAN_OR_VPN_SUBNET # e.g., 192.168.1.0/24 (Optional: Allow connections from another network)
2830

2931
# --- Backup Agent & Duplicati Configuration ---
3032

README.md

Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -65,79 +65,53 @@ graph TD
6565
**Note on Physical Replication Slot:** A physical replication slot (`laterbase_standby_slot` in this setup) is a feature on the primary PostgreSQL server. It ensures that the primary server retains the necessary transaction logs (WAL segments) required by the standby server, even if the standby disconnects temporarily. This prevents the standby from falling too far behind and needing a full resynchronization.
6666

6767
## Configuration
68-
1. **`.env` File:**
69-
* Open the `.env` file.
70-
* Set `PRIMARY_HOST` to the hostname or IP address of your main **DaVinci Resolve** PostgreSQL server.
71-
* Set `REPL_PASSWORD` to the password for the `postgres` user (or your designated replication user) on the primary DaVinci Resolve server.
72-
* **Crucially:** Set `PRIMARY_DBS` to a comma-separated list of the **actual names** of your main **DaVinci Resolve** database(s) on the primary server (e.g., `ResolveProjects`, `AnotherResolveDB`).
73-
* Set `PGADMIN_EMAIL` to the email address you want to use for the pgAdmin login.
74-
* Set `PGADMIN_PASSWORD` to the password you want for the pgAdmin login.
75-
* Adjust `PRIMARY_PORT` or `PRIMARY_USER` if they differ from the defaults (5432, postgres).
76-
* Optionally, uncomment and set `POSTGRES_USER`, `POSTGRES_DB`, or `PGDATA` under the "Standby Server Configuration" section to override the defaults used by the standby service.
77-
* **Backup Agent & Duplicati Configuration:**
78-
* Set `LOCAL_BACKUP_PATH` to the path on the host machine where the hourly `.sql.gz` backup files should be stored (default: `./backups`). This directory is mounted into both the `backup-agent` (writeable) and `duplicati` (read-only) containers as `/backups`.
79-
* Set `BACKUP_RETENTION_DAYS` to the number of days you want to keep local `.sql.gz` backups in the `LOCAL_BACKUP_PATH` directory. This cleanup is done by the `backup.sh` script (run by the scheduler). Defaults to 7 if not set.
80-
* Set `TZ` to the desired timezone for the Duplicati container (e.g., `Europe/London`, `America/New_York`, `Etc/UTC`).
81-
* Optionally, uncomment and set `DUPLICATI_WEBSERVICE_PASSWORD` to password-protect the Duplicati Web UI.
82-
* **Duplicati Job Configuration:** Cloud destination, remote retention, and schedule are configured via the Duplicati Web UI after starting the containers (see Usage section).
68+
1. **Configure `.env` File:**
69+
* Copy the `.env.example` file to `.env`.
70+
* Edit the `.env` file and fill in the required values (database connection details, pgAdmin credentials, backup settings) according to the comments within the file.
8371

8472
2. **Primary PostgreSQL Server Preparation (`PRIMARY_HOST`):**
8573

8674
* **Ensure DaVinci Resolve Database is Accessible:** Make sure your DaVinci Resolve database is configured to allow network connections if Laterbase is running on a different machine. Check the DaVinci Resolve Project Server settings if applicable.
8775
* **Primary Server Configuration Steps (macOS Example):**
88-
**VERY IMPORTANT:** Configuring the primary server involves **both** manual file editing and running an automated script. These steps **must** be completed on your **primary macOS server** (`PRIMARY_HOST`) *before* you attempt to start the main Laterbase Docker containers (`docker-compose up`). Laterbase only configures the standby replica; it does **not** automatically configure your primary server.
89-
90-
**Step 1: Manually Edit `pg_hba.conf` (Requires `sudo` on Primary Server)**
91-
* This step **must** be done manually on the primary server.
92-
* Open `Terminal.app` on the primary Mac where DaVinci Resolve's PostgreSQL is running.
93-
* **Find the `pg_hba.conf` file:** For a standard DaVinci Resolve installation on macOS, the path is usually:
94-
`/Library/Application Support/PostgreSQL/<VERSION>/data/pg_hba.conf`
95-
(Replace `<VERSION>` with your PostgreSQL version number, e.g., `13`. You can find it by running `ls "/Library/Application Support/PostgreSQL/"` in Terminal).
96-
* **Edit the file:** Use `nano` with `sudo`:
76+
**VERY IMPORTANT:** Configuring the primary server involves both manual file editing and running an automated script. These steps must be completed on your primary macOS (this is usually the machine your resolve is on) (`PRIMARY_HOST`) *before* you attempt to start the main Laterbase Docker containers (`docker-compose up`). Laterbase only configures the standby replica; it does **not** automatically configure your primary server.
77+
78+
**Step 1: Edit Primary Server's `pg_hba.conf` (Manual Step on Primary)**
79+
* On the primary Mac (where DaVinci Resolve's PostgreSQL runs), open Terminal and run the following command. Replace `<VERSION>` with your PostgreSQL version (e.g., 13):
9780
```bash
98-
sudo nano "/Library/Application Support/PostgreSQL/<VERSION>/data/pg_hba.conf"
99-
```
100-
(Again, replace `<VERSION>` with the correct number).
101-
* **Add the replication line:** Add the following line to the end of the file. **Adjust the IP address/subnet (`192.168.1.0/24`)** to match the network of your Docker host running Laterbase, allowing it to connect. Use the correct `PRIMARY_USER` if it's not `postgres`.
81+
sudo nano /Library/PostgreSQL/<VERSION>/data/pg_hba.conf
10282
```
83+
* Add the following line at the end of the file. **Important:** Replace `192.168.1.123/32` with the actual IP address of your Laterbase Docker host. Use the correct `PRIMARY_USER` if it's not `postgres`.
84+
```conf
10385
# Allow replication connections from the Laterbase Docker host
104-
host replication postgres 192.168.1.0/24 md5
86+
host replication postgres 192.168.1.123/32 md5
10587
```
106-
* **Save and Exit:** Press `Ctrl+O`, then `Enter` to save. Press `Ctrl+X` to exit `nano`.
88+
* Save the file (`Ctrl+O`, Enter) and exit (`Ctrl+X`).
10789

108-
**Step 2: Run the Preparation Script (Requires Docker & `.env` on Laterbase Host)**
109-
* This script automates granting replication privileges, creating the replication slot, and attempting a configuration reload via SQL.
110-
* Ensure your `.env` file in the Laterbase project directory is correctly configured with `PRIMARY_HOST`, `PRIMARY_PORT`, `PRIMARY_USER`, and `REPL_PASSWORD`.
111-
* From the Laterbase project directory (where `docker-compose.yml` is), run the script using `docker-compose run`:
90+
**Step 2: Prepare Primary Database (Run Script on Laterbase Host)**
91+
* This script prepares the primary database by granting permissions and creating the necessary replication slot (`laterbase_standby_slot`).
92+
* Ensure your `.env` file in the Laterbase project directory is correctly configured (especially `PRIMARY_HOST`, `PRIMARY_USER`, `REPL_PASSWORD`).
93+
* From the Laterbase project directory (where `docker-compose.yml` is), run this command:
11294
```bash
11395
docker-compose run --rm --no-deps app bash /app/prepare_primary_db.sh
11496
```
115-
* `--rm`: Removes the temporary container after execution.
116-
* `--no-deps`: Prevents starting linked services (like the standby DB itself).
117-
* `app`: The service name defined in `docker-compose.yml` that has `psql` and the script.
118-
* The script uses the `REPL_PASSWORD` from your `.env` file to connect.
119-
* Review the script's output for any errors (e.g., connection refused, authentication failed).
120-
121-
**Step 3: Manually Reload/Restart Primary PostgreSQL Server (on Primary Server)**
122-
* **Crucial:** Changes to `pg_hba.conf` (Step 1) require the primary PostgreSQL server configuration to be reloaded or the server restarted. The script (Step 2) attempts `SELECT pg_reload_conf();`, but this **may not be sufficient** for `pg_hba.conf` changes or might fail due to permissions.
123-
* You **must** ensure the configuration is reloaded on the primary server. Choose **one** of the following methods on the primary Mac:
97+
* Check the output for any errors. If this script fails, replication will not work.
12498

125-
* **Method A (Full Server Restart - Use if unsure):** If methods A or B don't work or you're unsure, a full restart of the Mac hosting the primary database will ensure the changes are applied, although it's less ideal.
126-
127-
* **Method B ** Quit and restart the **DaVinci Resolve Project Server** application. This usually restarts the underlying PostgreSQL server gracefully.
99+
**Step 3: Reload Primary Server Config (Manual Step on Primary)**
100+
* After editing `pg_hba.conf` (Step 1), the primary PostgreSQL server needs to reload its configuration.
101+
* On the primary Mac, the easiest way is usually to **quit and restart the DaVinci Resolve Project Server application**.
102+
* Alternatively, restarting the primary Mac will also work.
128103

129104
**Step 4: Verify Primary Server is Running**
130-
* After reloading/restarting, ensure your primary PostgreSQL server (and the DaVinci Resolve Project Server application, if used) is running and accessible before proceeding to start the Laterbase services.
105+
* Make sure the primary PostgreSQL server (and DaVinci Resolve Project Server, if used) is running before starting Laterbase.
131106

132107
3. **Create Backup Directory:**
133108
* In the same directory as the `docker-compose.yml` file on your Docker host, create the backups directory (if using the default `LOCAL_BACKUP_PATH`):
134109
```bash
135110
mkdir backups
136111
```
137112

138-
4. **(Removed)** Rclone configuration is no longer needed. Duplicati is configured via its Web UI.
139113

140-
## Usage
114+
## Usage & configuration of duplicati and pgadmin,
141115

142116
1. **Build and Start Containers:**
143117
* Navigate to the project directory in your terminal.
@@ -176,16 +150,3 @@ graph TD
176150
```bash
177151
docker-compose down
178152
```
179-
180-
## Files
181-
182-
* `docker-compose.yml`: Defines the services (`standby`, `backup-agent`, `duplicati`, `pgadmin`, `scheduler`), their configurations, volumes, and network.
183-
* `app/Dockerfile`: Instructions to build the PostgreSQL standby server image (based on `postgres:15`).
184-
* `backup/Dockerfile.backup`: Instructions to build the `backup-agent` image (based on Debian, includes only `postgresql-client`).
185-
* `.env`: Configuration file for environment variables (database credentials, pgAdmin login, etc.). **Requires user configuration.**
186-
* `app/prepare_primary_db.sh`: **(New)** Script to automate granting replication role and creating the replication slot on the primary server via `psql`. Run manually before starting services.
187-
* `app/setup_standby.sh`: Script run inside the standby container on first start to perform the initial base backup and configure replication.
188-
* `backup/backup.sh`: Script run hourly (via Ofelia scheduler) inside the backup agent container to perform `pg_dump` backups into the `/backups` volume and manage local `.sql.gz` file retention.
189-
* `backup/entrypoint.sh`: (Removed/Unused) No longer needed for the simplified `backup-agent`.
190-
* `./backups/` (Directory to be created, or path set in `LOCAL_BACKUP_PATH`): Host directory where local backup files (`.sql.gz`) are stored by `backup-agent` and read by `duplicati`.
191-
* `duplicati_data` (Docker Volume): Stores Duplicati's configuration database and local state.

app/setup_standby.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ echo "Base backup completed."
4949
touch "$PGDATA/standby.signal"
5050
echo "Created standby.signal file."
5151

52-
# Add rule to allow connections from Docker network (e.g., pgAdmin container)
53-
# Use 192.168.65.0/24 based on the error message IP 192.168.65.1
54-
echo "Adding pgAdmin access rule to standby's pg_hba.conf..."
55-
echo "host all all 192.168.65.0/24 md5" >> "$PGDATA/pg_hba.conf"
52+
# Add rule to allow connections from the configured subnet (e.g., pgAdmin container)
53+
# This subnet is defined by the PGADMIN_ACCESS_SUBNET environment variable.
54+
echo "Adding access rule for subnet $PGADMIN_ACCESS_SUBNET to standby's pg_hba.conf..."
55+
echo "host all all ${PGADMIN_ACCESS_SUBNET} md5" >> "$PGDATA/pg_hba.conf"
56+
echo "host all all ${PG_REALWORLD_SUBNET} md5" >> "$PGDATA/pg_hba.conf"
5657

5758
# Configure primary connection info in postgresql.auto.conf
5859
# This file is automatically included by postgresql.conf

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ services:
2020
POSTGRES_PASSWORD: ${REPL_PASSWORD} # Required by base image entrypoint
2121
# --- Other Settings ---
2222
POSTGRES_INITDB_ARGS: "--no-sync" # Faster init, safe for initial setup
23+
PGADMIN_ACCESS_SUBNET: ${PGADMIN_ACCESS_SUBNET:-127.0.0.1/32}
24+
PG_REALWORLD_SUBNET: ${PG_REALWORLD_SUBNET}
2325
volumes:
2426
- laterbase_standby_data:${PGDATA:-/var/lib/postgresql/data/pgdata}
2527
ports:
26-
- "5433:5432"
28+
- "5432:5432"
2729
restart: unless-stopped
2830
networks:
2931
- network

0 commit comments

Comments
 (0)