Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

FEATURE (container): Move PostgreSQL into container

Rostislav Dugind678f9b3a2dd
diff --git a/Dockerfile b/Dockerfile
index 350c7da5..8f33f668 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -53,18 +53,23 @@ RUN CGO_ENABLED=0 \
# ========= RUNTIME =========
FROM --platform=$TARGETPLATFORM debian:bookworm-slim
-# Install PostgreSQL client tools (versions 13-17)
+# Install PostgreSQL server and client tools (versions 13-17)
RUN apt-get update && apt-get install -y --no-install-recommends \
- wget ca-certificates gnupg lsb-release && \
+ wget ca-certificates gnupg lsb-release sudo gosu && \
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
> /etc/apt/sources.list.d/pgdg.list && \
apt-get update && \
apt-get install -y --no-install-recommends \
- postgresql-client-13 postgresql-client-14 postgresql-client-15 \
+ postgresql-17 postgresql-client-13 postgresql-client-14 postgresql-client-15 \
postgresql-client-16 postgresql-client-17 && \
rm -rf /var/lib/apt/lists/*
+# Create postgres user and set up directories
+RUN useradd -m -s /bin/bash postgres || true && \
+ mkdir -p /postgresus-data/pgdata && \
+ chown -R postgres:postgres /postgresus-data/pgdata
+
WORKDIR /app
# Copy Goose from build stage
@@ -87,7 +92,71 @@ RUN if [ ! -f /app/.env ]; then \
fi; \
fi
+# Create startup script
+COPY <<EOF /app/start.sh
+#!/bin/bash
+set -e
+
+# PostgreSQL 17 binary paths
+PG_BIN="/usr/lib/postgresql/17/bin"
+
+# Ensure proper ownership of data directory
+echo "Setting up data directory permissions..."
+mkdir -p /postgresus-data/pgdata
+chown -R postgres:postgres /postgresus-data
+
+# Initialize PostgreSQL if not already initialized
+if [ ! -s "/postgresus-data/pgdata/PG_VERSION" ]; then
+ echo "Initializing PostgreSQL database..."
+ gosu postgres \$PG_BIN/initdb -D /postgresus-data/pgdata --encoding=UTF8 --locale=C.UTF-8
+
+ # Configure PostgreSQL
+ echo "host all all 127.0.0.1/32 md5" >> /postgresus-data/pgdata/pg_hba.conf
+ echo "local all all trust" >> /postgresus-data/pgdata/pg_hba.conf
+ echo "port = 5437" >> /postgresus-data/pgdata/postgresql.conf
+ echo "listen_addresses = 'localhost'" >> /postgresus-data/pgdata/postgresql.conf
+ echo "shared_buffers = 256MB" >> /postgresus-data/pgdata/postgresql.conf
+ echo "max_connections = 100" >> /postgresus-data/pgdata/postgresql.conf
+fi
+
+# Start PostgreSQL in background
+echo "Starting PostgreSQL..."
+gosu postgres \$PG_BIN/postgres -D /postgresus-data/pgdata -p 5437 &
+POSTGRES_PID=\$!
+
+# Wait for PostgreSQL to be ready
+echo "Waiting for PostgreSQL to be ready..."
+for i in {1..30}; do
+ if gosu postgres \$PG_BIN/pg_isready -p 5437 -h localhost >/dev/null 2>&1; then
+ echo "PostgreSQL is ready!"
+ break
+ fi
+ if [ \$i -eq 30 ]; then
+ echo "PostgreSQL failed to start"
+ exit 1
+ fi
+ sleep 1
+done
+
+# Create database and set password for postgres user
+echo "Setting up database and user..."
+gosu postgres \$PG_BIN/psql -p 5437 -h localhost -d postgres << 'SQL'
+ALTER USER postgres WITH PASSWORD 'Q1234567';
+CREATE DATABASE "postgresus" OWNER postgres;
+\q
+SQL
+
+# Start the main application
+echo "Starting Postgresus application..."
+exec ./main
+EOF
+
+RUN chmod +x /app/start.sh
+
EXPOSE 4005
-ENTRYPOINT ["./main"]
+# Volume for PostgreSQL data
+VOLUME ["/postgresus-data"]
+
+ENTRYPOINT ["/app/start.sh"]
CMD []
diff --git a/README.md b/README.md
index 8a50b85c..d3773457 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
<div align="center">
<img src="assets/logo.svg" style="margin-bottom: 20px;" alt="Postgresus Logo" width="250"/>
-
<h3>PostgreSQL monitoring and backup</h3>
<p>Free, open source and self-hosted solution for automated PostgreSQL monitoring and backups. With multiple storage options and notifications</p>
@@ -65,21 +64,29 @@
- **Historical data**: View trends and patterns over time
- **Alert system**: Get notified when issues are detected
+### πŸ“¦ Installation
+
+You have three ways to install Postgresus:
+
+- Script (recommended)
+- Simple Docker run
+- Docker Compose setup
+
<img src="assets/healthchecks.svg" alt="Postgresus Dashboard" width="800"/>
---
## πŸ“¦ Installation
-You have two ways to install Postgresus: via automated script (recommended) or manual Docker Compose setup.
+You have three ways to install Postgresus: automated script (recommended), simple Docker run, or Docker Compose setup.
### Option 1: Automated Installation Script (Recommended, Linux only)
The installation script will:
-- βœ… Install Docker with Docker Compose (if not already installed)
-- βœ… Create optimized `docker-compose.yml` configuration
-- βœ… Set up automatic startup on system reboot via cron
+- βœ… Install Docker with Docker Compose(if not already installed)
+- βœ… Set up Postgresus
+- βœ… Configure automatic startup on system reboot
```bash
sudo apt-get install -y curl && \
@@ -87,7 +94,26 @@ sudo curl -sSL https://raw.githubusercontent.com/RostislavDugin/postgresus/refs/
| sudo bash
```
-### Option 2: Manual Docker Compose Setup
+### Option 2: Simple Docker Run
+
+The easiest way to run Postgresus with embedded PostgreSQL:
+
+```bash
+docker run -d \
+ --name postgresus \
+ -p 4005:4005 \
+ -v ./postgresus-data:/postgresus-data \
+ --restart unless-stopped \
+ rostislavdugin/postgresus:latest
+```
+
+This single command will:
+
+- βœ… Start Postgresus
+- βœ… Store all data in `./postgresus-data` directory
+- βœ… Automatically restart on system reboot
+
+### Option 3: Docker Compose Setup
Create a `docker-compose.yml` file with the following configuration:
@@ -102,29 +128,6 @@ services:
- "4005:4005"
volumes:
- ./postgresus-data:/postgresus-data
- depends_on:
- postgresus-db:
- condition: service_healthy
- restart: unless-stopped
-
- postgresus-db:
- container_name: postgresus-db
- image: postgres:17
- # we use default values, but do not expose
- # PostgreSQL ports so it is safe
- environment:
- - POSTGRES_DB=postgresus
- - POSTGRES_USER=postgres
- - POSTGRES_PASSWORD=Q1234567
- volumes:
- - ./pgdata:/var/lib/postgresql/data
- command: -p 5437
- shm_size: 10gb
- healthcheck:
- test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
- interval: 5s
- timeout: 5s
- retries: 5
restart: unless-stopped
```
diff --git a/backend/.env.production.example b/backend/.env.production.example
index 8b3601bf..c41c7dc7 100644
--- a/backend/.env.production.example
+++ b/backend/.env.production.example
@@ -5,9 +5,9 @@ DEV_DB_PASSWORD=Q1234567
#app
ENV_MODE=production
# db
-DATABASE_DSN=host=postgresus-db user=postgres password=Q1234567 dbname=postgresus port=5437 sslmode=disable
-DATABASE_URL=postgres://postgres:Q1234567@postgresus-db:5437/postgresus?sslmode=disable
+DATABASE_DSN=host=localhost user=postgres password=Q1234567 dbname=postgresus port=5437 sslmode=disable
+DATABASE_URL=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
# migrations
GOOSE_DRIVER=postgres
-GOOSE_DBSTRING=postgres://postgres:Q1234567@postgresus-db:5437/postgresus?sslmode=disable
+GOOSE_DBSTRING=postgres://postgres:Q1234567@localhost:5437/postgresus?sslmode=disable
GOOSE_MIGRATION_DIR=./migrations
\ No newline at end of file
diff --git a/docker-compose.yml.example b/docker-compose.yml.example
index 87d7784e..fe31174d 100644
--- a/docker-compose.yml.example
+++ b/docker-compose.yml.example
@@ -16,27 +16,4 @@ services:
volumes:
- ./postgresus-data:/postgresus-data
container_name: postgresus-local
- depends_on:
- postgresus-db:
- condition: service_healthy
- restart: unless-stopped
-
- postgresus-db:
- image: postgres:17
- # we use default values, but do not expose
- # PostgreSQL ports so it is safe
- environment:
- - POSTGRES_DB=postgresus
- - POSTGRES_USER=postgres
- - POSTGRES_PASSWORD=Q1234567
- volumes:
- - ./pgdata:/var/lib/postgresql/data
- container_name: postgresus-db
- command: -p 5437
- shm_size: 10gb
- healthcheck:
- test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
- interval: 5s
- timeout: 5s
- retries: 5
- restart: unless-stopped
+ restart: unless-stopped
\ No newline at end of file
diff --git a/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx b/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
index 0ee0d357..9eb6629f 100644
--- a/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
+++ b/frontend/src/features/backups/ui/EditBackupConfigComponent.tsx
@@ -341,7 +341,7 @@ export const EditBackupConfigComponent = ({
<Tooltip
className="cursor-pointer"
- title="Number of CPU cores to use for backup processing. Higher values may speed up backups but use more resources."
+ title="Number of CPU cores to use for restore processing. Higher values may speed up restores, but use more resources."
>
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
</Tooltip>
diff --git a/install-postgresus.sh b/install-postgresus.sh
index 796fdec6..877857d3 100644
--- a/install-postgresus.sh
+++ b/install-postgresus.sh
@@ -68,29 +68,6 @@ services:
- "4005:4005"
volumes:
- ./postgresus-data:/postgresus-data
- depends_on:
- postgresus-db:
- condition: service_healthy
- restart: unless-stopped
-
- postgresus-db:
- container_name: postgresus-db
- image: postgres:17
- # we use default values, but do not expose
- # PostgreSQL ports so it is safe
- environment:
- - POSTGRES_DB=postgresus
- - POSTGRES_USER=postgres
- - POSTGRES_PASSWORD=Q1234567
- volumes:
- - ./pgdata:/var/lib/postgresql/data
- command: -p 5437
- shm_size: 10gb
- healthcheck:
- test: ["CMD-SHELL", "pg_isready -U postgres -d postgresus -p 5437"]
- interval: 5s
- timeout: 5s
- retries: 5
restart: unless-stopped
EOF
log "docker-compose.yml created successfully"