Introduction
When you run a technical blog, traffic data is how you learn what readers do and decide where to take the content. I had been using Google Analytics, but the GA4 interface keeps getting heavier, and I didn’t want every visitor’s browsing behavior landing on a third party’s servers.
After comparing Umami, Plausible and Matomo, I went with Umami: the tracker is small, it doesn’t use cookies, the data lives in my own PostgreSQL, and the v3 REST API is complete enough. Version 3.5.0, released on November 12, 2026, added browser error tracking and stricter security policies, which gave me a good reason to run a full deployment in my Homelab.
This time it wasn’t just about getting the containers up. I actually verified the tracker script, the /api/collect endpoint, Nginx TLS, the Hugo integration, and backup and restore; every screenshot comes from the test environment. For a public deployment, just swap in your own domain, certificate and ports.
Technology Choices
Why Umami
Before deciding to self-host analytics, I compared the main open-source options side by side:
| Dimension | Umami | Plausible | Matomo |
|---|---|---|---|
| Language/framework | Next.js (Node.js) | Elixir + Phoenix | PHP + MySQL |
| Tracker size | ~4 KB (gzip) | ~1 KB | ~22 KB |
| Cookies | No | No | Yes (can be disabled) |
| GDPR compliance | Compliant by default | Compliant by default | Needs configuration |
| Database | PostgreSQL (v3) | PostgreSQL + ClickHouse | MySQL/MariaDB |
| Resource usage | Low (~512 MB) | Medium (~1 GB) | High (~2 GB) |
| API | Full REST API | Limited | Full |
| Deployment complexity | Low | Medium | High |
| Real-time dashboard | Yes | Yes | Yes |
| Custom events | Yes | Yes | Yes |
| License | MIT | AGPL-3.0 | GPL-3.0 |
Why I ended up choosing Umami:
- The tracker is about 4 KB gzipped, so it barely affects page load
- No cookies, so no consent banner
- Only two containers to run: Umami and PostgreSQL
- v3 has a full REST API, which makes it easy to feed Grafana or my own scripts later
- MIT license, with no restrictions on commercial use
Architecture
When a visitor loads a blog page, stats.js sends a POST to Umami’s collect endpoint; Nginx terminates TLS and forwards the request to the local Umami container, which writes to PostgreSQL through Prisma.
graph TB
subgraph Visitor side
A[Visitor browser] -->|"loads stats.js"| B[Blog page]
B -->|"POST /api/collect"| C[Nginx 443]
end
subgraph Server
C -->|"proxy_pass 127.0.0.1:3000"| D[Umami 3.5.0]
D -->|"Prisma ORM"| E[(PostgreSQL 15)]
E -->|"data volume"| F["/var/lib/postgresql/data"]
end
subgraph Operations
G[Cron] -->|"pg_dump"| E
G -->|"zstd compression"| H[Local backup]
H -->|"rclone sync"| I[S3 object storage]
J[healthcheck] -->|"/api/heartbeat"| D
end
style A fill:#e1f5fe
style D fill:#fff3e0
style E fill:#e8f5e9
style I fill:#fce4ec
Key design decisions:
- TLS terminates at Nginx: certificate management stays in one place, and the Umami container only exposes its port on localhost
- PostgreSQL exposes no port: the database talks to Umami only over the internal Docker network
- Backups written twice: one copy locally, another in remote object storage
- Health checks: a container-level healthcheck plus external probing, so an outage is noticed quickly
Deployment
Test Environment
The deployment and verification in this post were done on a single Debian 12 VM:
- Umami 3.5.0 (
docker.umami.is/umami-software/umami:3.5.0) - PostgreSQL 15.20 (
postgres:15-alpine) - Docker 29.9.3, Docker Compose v5.7.1
- Nginx 1.22.1, with certificates issued by an internal step-ca
- Port 443 is taken by k3s’s Traefik, so Nginx listens on 9443; for a public deployment, switch back to 443
Prerequisites
- A Linux server that can run Docker (Debian 12 in this post)
- Docker Engine and the Docker Compose plugin (Compose v5.7.1 here)
- A domain name with an A record pointing at the server IP
- A TLS certificate: Let’s Encrypt on the public internet, or step-ca or your own CA on an internal network
Directory Layout
# Create the project directory on the server
mkdir -p /opt/umami/{backups,scripts}
cd /opt/umami
The final directory layout:
/opt/umami/
├── docker-compose.yml # Container orchestration
├── .env # Environment variables (secrets)
├── backups/ # Local backup directory
│ └── umami_20261115_030147.sql.zst
└── scripts/
├── backup.sh # Automated backup script
└── restore.sh # Restore script
Generating Secrets
Umami needs three independent random values: the database password, APP_SECRET and TWO_FACTOR_ENCRYPTION_KEY.
# APP_SECRET: signs login tokens and feeds into anonymous session ID derivation
openssl rand -hex 32
# TWO_FACTOR_ENCRYPTION_KEY: encrypts users' 2FA secrets
openssl rand -hex 32
# PostgreSQL password. Use hex rather than base64 so / + = don't need URL encoding
openssl rand -hex 24
Before 3.5.0, Umami fell back to deriving a key from DATABASE_URL when APP_SECRET was not set; that fallback was removed in 3.5.0, and an empty value or the placeholder replace-me-with-a-random-string is rejected.
When upgrading from an older version, if APP_SECRET was never set, you can temporarily set it to the original DATABASE_URL value to keep existing sessions; afterwards switch to an independent random value. Changing it logs everyone out.
TWO_FACTOR_ENCRYPTION_KEY is a 64-character hex string (256 bits) used to encrypt users’ 2FA secrets. Keep this value long-term: if you change it, accounts with 2FA enabled can no longer verify.
Environment File
Put sensitive values in a .env file, separate from docker-compose.yml:
cat > /opt/umami/.env << 'EOF'
# PostgreSQL
POSTGRES_DB=umami
POSTGRES_USER=umami
POSTGRES_PASSWORD=<password generated above>
# Umami
DATABASE_URL=postgresql://umami:<same password>@db:5432/umami
APP_SECRET=<64-char hex>
TWO_FACTOR_ENCRYPTION_KEY=<another 64-char hex>
# Hardening
DISABLE_TELEMETRY=1
DISABLE_UPDATES=1
# If another proxy layer such as Cloudflare sits in front, set these as appropriate
# TRUSTED_PROXIES=10.0.0.0/8,172.16.0.0/12
EOF
# Restrict permissions so only root can read it
chmod 600 /opt/umami/.env
Docker Compose
# /opt/umami/docker-compose.yml
---
services:
umami:
# Registry used in the official docs; the image tag is 3.5.0, not v3.5.0 as on the release page
image: docker.umami.is/umami-software/umami:3.5.0
container_name: umami
ports:
- "127.0.0.1:3000:3000"
env_file:
- .env
environment:
# Behind a reverse proxy, the header that carries the real client IP
CLIENT_IP_HEADER: X-Real-IP
# Custom tracking endpoint path to dodge ad blockers
COLLECT_API_ENDPOINT: /api/collect
# Custom tracker script name to dodge ad blockers
TRACKER_SCRIPT_NAME: stats.js
depends_on:
db:
condition: service_healthy
init: true
restart: always
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:3000/api/heartbeat || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
deploy:
resources:
limits:
memory: 512M
cpus: "1.0"
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
db:
image: postgres:15-alpine
container_name: umami-db
env_file:
- .env
volumes:
- umami-db-data:/var/lib/postgresql/data
# Don't publish ports to the host; reachable only on the Docker network
expose:
- "5432"
restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
deploy:
resources:
limits:
memory: 256M
cpus: "0.5"
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
# PostgreSQL tuning parameters
command:
- "postgres"
- "-c"
- "shared_buffers=64MB"
- "-c"
- "effective_cache_size=128MB"
- "-c"
- "work_mem=4MB"
- "-c"
- "maintenance_work_mem=32MB"
- "-c"
- "random_page_cost=1.1"
- "-c"
- "log_min_duration_statement=1000"
- "-c"
- "timezone=UTC"
volumes:
umami-db-data:
driver: local
portsbinds127.0.0.1:3000:3000rather than0.0.0.0:3000:3000, so Umami is only reachable through the reverse proxy- PostgreSQL uses
exposeinstead ofports, so the port is reachable only inside the Docker network - Set the
.envfile to mode600and never commit it to Git
v3.5.0, but the Docker image tag is 3.5.0. Using v3.5.0 fails with manifest unknown. The registry in the official docs is docker.umami.is, and the same image is also on ghcr.io/umami-software/umami. In production, pin a version rather than using latest.The settings above are a conservative configuration for a small site (under 50,000 page views per day):
shared_buffers=64MB: shared memory PostgreSQL uses to cache data pages, usually 25% of available memory; with the container capped at 256MB, that comes out to 64MBeffective_cache_size=128MB: tells the query planner how much memory the OS can use for caching, which affects index selectionwork_mem=4MB: memory limit for a single sort or hash operation; Umami’s queries aren’t complex, so 4MB is enoughlog_min_duration_statement=1000: logs queries taking longer than 1 second, which helps with performance troubleshootingtimezone=UTC: the Umami docs recommend running PostgreSQL in UTC
Starting the Services
cd /opt/umami
# Pull the images and start
docker compose up -d
# Check container status
docker compose ps
# Watch the Umami startup logs and confirm there are no errors
docker compose logs -f umami
On first start, Umami checks the database connection and runs Prisma migrations. The actual logs show:
umami | ✓ DATABASE_URL is defined.
umami | ✓ Database connection successful.
umami | ✓ Database version check successful.
umami | 27 migrations found in prisma/migrations
Once both containers are healthy, hit Umami on port 3000 to confirm the service is up:
curl -s http://127.0.0.1:3000/api/heartbeat
# {"ok":true}
First Login and Changing the Password
On first start, Umami creates a default admin account:
- Username:
admin - Password:
umami
Since 3.5.0, logging in with the default password forces a password change before you can continue. The password change is under Settings -> Security; older versions had it on the Profile page.
While you’re there, enable 2FA. This requires TWO_FACTOR_ENCRYPTION_KEY to be set in .env; without it, 2FA cannot be enabled.
Nginx Reverse Proxy
The config below assumes you already have a TLS certificate (obtained through Certbot or otherwise):
# /etc/nginx/sites-available/analytics.example.com
server {
listen 80;
listen [::]:80;
server_name analytics.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name analytics.example.com;
# TLS certificate
ssl_certificate /etc/letsencrypt/live/analytics.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/analytics.example.com/privkey.pem;
# TLS security parameters
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
ssl_session_tickets off;
# HSTS. Only add preload after confirming every subdomain uses HTTPS
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
# Security response headers
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# Access logs
access_log /var/log/nginx/analytics.access.log;
error_log /var/log/nginx/analytics.error.log;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
# Pass the real client IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Tracker script caching: the script rarely changes, so clients can cache it
location = /stats.js {
proxy_pass http://127.0.0.1:3000/stats.js;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Cache for 1 day
expires 1d;
}
}
expires 1d already generates Cache-Control: max-age=86400. Adding another add_header Cache-Control "public, immutable" line puts two Cache-Control headers in the response. Keep just one.On this VM, 443 is already taken by k3s’s Traefik and 8443 is step-ca, so Nginx listens on 9443 with a certificate issued by step-ca. For testing, use --resolve to point the domain at localhost and -k to skip the client’s trust check for the private CA; in a browser you need to add the Homelab Root CA to the trust store first. For a public deployment, just switch to 443 and a public certificate; the proxy config stays the same.
For issuing and renewing internal certificates, see the earlier Homelab certificate management in practice.
Enable the config and verify:
# Create a symlink to enable the site
ln -s /etc/nginx/sites-available/analytics.example.com /etc/nginx/sites-enabled/
# Check the config syntax
nginx -t
# Reload Nginx
systemctl reload nginx
# Test HTTPS access
curl -s -o /dev/null -w "%{http_code}\n" https://analytics.example.com/api/heartbeat
# 200

Adding a Site and Integrating Hugo
Adding a Site in Umami
- Log in to the Umami admin at
https://analytics.example.com - Go to Websites in the left navigation and click Add website
- Fill in the site name (for example
blog.plz.ac) and domain - After saving, a Website ID (UUID format) is generated; note it down
Hugo DoIt Theme Integration
The DoIt theme already has an Umami branch in themes/DoIt/layouts/_partials/plugin/analytics.html, so you only need to configure it in config.toml:
[params.analytics]
enable = true
[params.analytics.umami]
data_website_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Replace with your Website ID
src = "https://analytics.example.com/stats.js" # Tracker script URL
data_host_url = "https://analytics.example.com" # Umami instance URL
data_domains = "blog.plz.ac" # Restrict to your domain so local development doesn't pollute the data
Note that src uses stats.js rather than the default script.js. This matches TRACKER_SCRIPT_NAME: stats.js in docker-compose.yml.
Custom script names and endpoint paths are an effective way to dodge ad blockers. Most filter rules target default paths like script.js and /api/send; renaming noticeably improves how complete your data is.
If you want to keep Google Analytics alongside for comparison, the two can coexist:
[params.analytics]
enable = true
[params.analytics.google]
id = "G-XXXXXXXXXX"
anonymizeIP = true
[params.analytics.umami]
data_website_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
src = "https://analytics.example.com/stats.js"
data_host_url = "https://analytics.example.com"
data_domains = "blog.plz.ac"
Manual Integration (Non-DoIt Themes)
If your Hugo theme doesn’t support Umami natively, add it to the template’s <head> by hand:
<!-- Umami Analytics -->
<script
defer
src="https://analytics.example.com/stats.js"
data-website-id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
data-host-url="https://analytics.example.com"
data-domains="blog.plz.ac"
></script>
What the key attributes do:
| Attribute | Purpose |
|---|---|
defer |
Loads asynchronously without blocking page rendering |
data-website-id |
Unique site identifier, from the Umami admin |
data-host-url |
Umami instance URL; required when deployed on a different origin |
data-domains |
Restricts tracking to your domain so local development doesn’t pollute the data |
data-do-not-track |
Set to "true" to respect the browser’s DNT setting |
data-auto-track |
Set to "false" to turn off automatic tracking and report through the JS API instead |
Verification
Containers and Heartbeat
# Container health
docker compose ps
# API heartbeat
curl -s http://127.0.0.1:3000/api/heartbeat
# {"ok":true}
# Heartbeat through Nginx
curl -s -o /dev/null -w "%{http_code}\n" https://analytics.example.com/api/heartbeat
# 200

Tracker Script and Collect Endpoint
# Confirm the script loads
curl -sI https://analytics.example.com/stats.js | head -5
# HTTP/2 200
# content-length: 9300
In testing, stats.js is 9,300 bytes uncompressed and about 4 KB gzipped.
Next, verify the collect endpoint. With COLLECT_API_ENDPOINT set to /api/collect, the tracker POSTs data to that path:
curl -s -o /dev/null -w "%{http_code}\n" \
-X POST https://analytics.example.com/api/collect \
-H "Content-Type: application/json" \
-H "User-Agent: Mozilla/5.0 ... Chrome/140.0 Safari/537.36" \
-d '{
"type": "event",
"payload": {
"website": "<website-id>",
"hostname": "blog.plz.ac",
"url": "/nginx-collect-test",
"referrer": "",
"title": "Nginx collect test",
"language": "zh-CN",
"screen": "1440x900"
}
}'
# 200
The response body includes sessionId and visitId. In the test environment I compared the website_event row count before and after the write; it went from 1 to 2, so the request really did go through Nginx and into the database.
Reporting from the Browser
Finally, a minimal page to verify stats.js in the browser:
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>Umami tracking test</title>
<script defer
src="https://analytics.example.com/stats.js"
data-website-id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
data-host-url="https://analytics.example.com"></script>
</head>
<body>
<h1>Umami tracking test</h1>
<p>This page is used to verify the tracker and collect endpoint.</p>
</body>
</html>
After opening the page, the Umami dashboard showed 1 visitor, 1 visit and 1 view with path /, and the browser was recognized as Chrome. The data in the screenshot came from this test:

Client IP Verification
Passing the client IP through is the most common failure with a reverse proxy. To verify:
# Check the client IP recorded in the Nginx access log
tail -5 /var/log/nginx/analytics.access.log
# Check the Locations data in the Umami dashboard
# If every visitor shows the same IP or region, the IP isn't being passed through correctly
If the IP is wrong, check these in order:
- Check that Nginx sets
proxy_set_header X-Real-IP $remote_addr - Check that Umami’s
CLIENT_IP_HEADERenvironment variable is set toX-Real-IP - If a CDN such as Cloudflare sits in front, use
CF-Connecting-IPinstead and configure the proxy addresses withTRUSTED_PROXIESas in 3.5.0
Verifying Data Exclusion
Confirm your own IP isn’t counted (optional):
# Add the excluded IP to .env
echo 'IGNORE_IP=your-public-ip/32' >> /opt/umami/.env
# Environment variables are read when the container is created, so recreate it after editing .env
docker compose up -d --force-recreate umami
Hardening
Network Layer
graph LR
A[Public internet] -->|"443/tcp"| B[Nginx]
B -->|"127.0.0.1:3000"| C[Umami]
C -->|"Docker internal network"| D[(PostgreSQL)]
style A fill:#ffcdd2
style B fill:#c8e6c9
style C fill:#fff3e0
style D fill:#e8f5e9
Firewall rules (open only what’s needed):
# If you use ufw
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp comment 'SSH'
ufw allow 80/tcp comment 'HTTP redirect'
ufw allow 443/tcp comment 'HTTPS'
ufw enable
# Confirm port 3000 isn't exposed publicly
ss -tlnp | grep 3000
# You should only see 127.0.0.1:3000
0.0.0.0 are not necessarily governed by ufw. Here Umami is bound to 127.0.0.1 and PostgreSQL only uses expose, so neither port depends on ufw blocking it.Application Layer
What the key environment variables mean for security:
| Variable | Value | Description |
|---|---|---|
APP_SECRET |
64-char hex | Required since 3.5.0; signs login tokens and feeds anonymous session ID derivation |
TWO_FACTOR_ENCRYPTION_KEY |
64-char hex | Encrypts 2FA secrets; must be set before enabling 2FA and kept long-term |
DISABLE_TELEMETRY |
1 |
Disables anonymous telemetry to Umami |
DISABLE_UPDATES |
1 |
Disables background update checks (fewer outbound calls) |
IGNORE_IP |
Admin IP | Excludes your own IP so your traffic doesn’t skew the stats |
CLIENT_IP_HEADER |
X-Real-IP |
Ensures the real client IP is read behind the reverse proxy |
TRUSTED_PROXIES |
Proxy CIDR ranges | For multiple proxy layers, so forged X-Forwarded-For headers aren’t trusted |
TRACKER_SCRIPT_NAME |
stats.js |
Dodges ad blockers’ default rules |
COLLECT_API_ENDPOINT |
/api/collect |
Same idea, for the collect endpoint path |
Container Layer
The docker-compose.yml above already applies these hardening measures:
- Resource limits:
deploy.resources.limitskeeps a misbehaving container from eating the host - Log rotation:
logging.optionscaps each file at 10MB with at most 3 files, so logs can’t fill the disk - Port isolation: PostgreSQL isn’t exposed to the host, and Umami binds only to
127.0.0.1 - Init process:
init: truemakes sure zombie processes inside the container are reaped
Regular Updates
Umami is built on Next.js, so Next.js security vulnerabilities affect it directly. Keep an eye on Umami’s GitHub Releases page and update promptly:
cd /opt/umami
# Change the image tag in docker-compose.yml, then pull
docker compose pull
# Rolling update (stop the old container, then start the new one)
docker compose up -d --force-recreate
# Confirm the service is healthy after the update
docker compose ps
curl -s http://127.0.0.1:3000/api/heartbeat
27_add_error_tracking), and a backup gives you a way out if a migration goes wrong.Backup and Restore
Backup Strategy
graph TB
A[(PostgreSQL)] -->|"pg_dump -Fc"| B[Compressed backup file]
B -->|"zstd compression"| C[Local backup directory]
C -->|"rclone sync"| D[S3 object storage]
C -->|"keep 30 days"| E[Automatic cleanup of old backups]
F[Cron job] -->|"daily 03:00"| A
F -->|"daily 03:30"| C
style A fill:#e8f5e9
style D fill:#fce4ec
Backup specs:
| Metric | Value |
|---|---|
| Frequency | Daily at 3:00 AM |
| Local retention | 30 days |
| Remote backup | S3-compatible object storage |
| Compression | pg_dump custom format + zstd |
| RPO | 24 hours |
| RTO | < 30 minutes |
Automated Backup Script
The script relies on zstd on the host. If it isn’t installed on Debian 12, run apt install zstd first; remote sync also needs rclone installed and configured.
#!/usr/bin/env bash
# /opt/umami/scripts/backup.sh
# Umami PostgreSQL automated backup script
set -euo pipefail
# ---- Config ----
BACKUP_DIR="/opt/umami/backups"
CONTAINER_NAME="umami-db"
DB_USER="umami"
DB_NAME="umami"
RETENTION_DAYS=30
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/umami_${DATE}.sql.zst"
# Remote backup config (optional, requires rclone)
RCLONE_REMOTE="s3:umami-backups"
ENABLE_REMOTE_BACKUP=false
# ---- Logging ----
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
# ---- Preflight checks ----
if ! docker inspect -f '{{.State.Running}}' "${CONTAINER_NAME}" 2>/dev/null | grep -q true; then
log "ERROR: container ${CONTAINER_NAME} does not exist or is not running"
exit 1
fi
mkdir -p "${BACKUP_DIR}"
# ---- Run the backup ----
log "Starting Umami database backup..."
docker exec "${CONTAINER_NAME}" \
pg_dump -U "${DB_USER}" -d "${DB_NAME}" -Fc --clean --if-exists \
| zstd -T0 -9 > "${BACKUP_FILE}"
BACKUP_SIZE=$(du -h "${BACKUP_FILE}" | cut -f1)
log "Backup complete: ${BACKUP_FILE} (${BACKUP_SIZE})"
# ---- Verify backup integrity ----
if ! zstd -t "${BACKUP_FILE}" 2>/dev/null; then
log "ERROR: backup integrity check failed"
rm -f "${BACKUP_FILE}"
exit 1
fi
log "Backup integrity check passed"
# ---- Remote sync ----
if [[ "${ENABLE_REMOTE_BACKUP}" == "true" ]] && command -v rclone &>/dev/null; then
log "Syncing backup to remote storage..."
rclone copy "${BACKUP_FILE}" "${RCLONE_REMOTE}/" --progress
log "Remote sync complete"
fi
# ---- Clean up old backups ----
DELETED=$(find "${BACKUP_DIR}" -name "umami_*.sql.zst" -type f -mtime "+${RETENTION_DAYS}" -print -delete | wc -l)
if [[ "${DELETED}" -gt 0 ]]; then
log "Removed ${DELETED} old backups older than ${RETENTION_DAYS} days"
fi
log "Backup job complete"
Set permissions and the cron job:
chmod 700 /opt/umami/scripts/backup.sh
# Add a cron job that runs at 3:00 AM daily
cat > /etc/cron.d/umami-backup << 'EOF'
# Daily Umami database backup
0 3 * * * root /opt/umami/scripts/backup.sh >> /var/log/umami-backup.log 2>&1
EOF
# Run it once by hand to verify
/opt/umami/scripts/backup.sh
I ran these backup commands in the test environment; the resulting umami_20261115_030147.sql.zst was 12 KB and passed zstd -t.
I then restored the backup into a temporary database, umami_restore_test: the website and website_event row counts matched the source (1 site, 2 events). The restore script doesn’t overwrite the live database directly.
Restore Script
#!/usr/bin/env bash
# /opt/umami/scripts/restore.sh
# Umami PostgreSQL restore script
set -euo pipefail
CONTAINER_NAME="umami-db"
DB_USER="umami"
DB_NAME="umami"
BACKUP_DIR="/opt/umami/backups"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*"
}
# ---- Argument check ----
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <backup-file-path>"
echo ""
echo "Available backups:"
ls -lht "${BACKUP_DIR}"/umami_*.sql.zst 2>/dev/null | head -10
exit 1
fi
BACKUP_FILE="$1"
if [[ ! -f "${BACKUP_FILE}" ]]; then
log "ERROR: backup file does not exist: ${BACKUP_FILE}"
exit 1
fi
# ---- Integrity check ----
log "Verifying backup integrity..."
if ! zstd -t "${BACKUP_FILE}" 2>/dev/null; then
log "ERROR: backup file is corrupted"
exit 1
fi
# ---- Confirmation ----
log "About to restore the database; current data will be overwritten!"
read -rp "Continue? (type yes): " CONFIRM
if [[ "${CONFIRM}" != "yes" ]]; then
log "Operation cancelled"
exit 0
fi
# ---- Stop Umami ----
log "Stopping Umami service..."
cd /opt/umami
docker compose stop umami
# ---- Restore the database ----
log "Starting database restore..."
zstd -d "${BACKUP_FILE}" --stdout \
| docker exec -i "${CONTAINER_NAME}" \
pg_restore -U "${DB_USER}" -d "${DB_NAME}" --clean --if-exists --no-owner --no-privileges
# ---- Restart the service ----
log "Restarting Umami service..."
docker compose start umami
# ---- Verify ----
sleep 10
if curl -sf http://127.0.0.1:3000/api/heartbeat > /dev/null; then
log "Restore complete; the service is running normally"
else
log "WARNING: the service may not have started correctly; check the logs: docker compose logs umami"
fi
chmod 700 /opt/umami/scripts/restore.sh
Restore Drills
Regular restore drills are the only reliable way to know your backups work:
# List available backups
ls -lht /opt/umami/backups/
# Restore the most recent backup
/opt/umami/scripts/restore.sh /opt/umami/backups/umami_20261115_030147.sql.zst
Monitoring and Alerting
Container Health Checks
docker-compose.yml already defines container-level health checks. To see the status:
# Check the health of all containers
docker compose ps
# Example output:
# NAME IMAGE STATUS PORTS
# umami docker.umami.is/umami-software/umami:3.5.0 Up 2 hours (healthy) 127.0.0.1:3000->3000/tcp
# umami-db postgres:15-alpine Up 2 hours (healthy) 5432/tcp
External Probing Script
If you run Prometheus + Alertmanager or another monitoring system, you can probe the /api/heartbeat endpoint with the blackbox exporter. Here is a simple standalone check script:
#!/usr/bin/env bash
# /opt/umami/scripts/check_health.sh
# Simple health check script, used with Cron
UMAMI_URL="https://analytics.example.com/api/heartbeat"
ALERT_EMAIL="[email protected]"
RESPONSE=$(curl -sf -o /dev/null -w "%{http_code}" --max-time 10 "${UMAMI_URL}")
if [[ "${RESPONSE}" != "200" ]]; then
echo "Umami health check failed (HTTP ${RESPONSE})" \
| mail -s "[ALERT] Umami Service Down" "${ALERT_EMAIL}"
fi
# Check every 5 minutes
cat >> /etc/cron.d/umami-backup << 'EOF'
# Umami health check
*/5 * * * * root /opt/umami/scripts/check_health.sh 2>/dev/null
EOF
Prometheus Integration (Optional)
If you already run Prometheus, use the blackbox exporter for HTTP probes:
# Add to blackbox.yml
modules:
umami_heartbeat:
prober: http
timeout: 10s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
valid_status_codes: [200]
method: GET
preferred_ip_protocol: "ip4"
# Add the scrape config to prometheus.yml
scrape_configs:
- job_name: 'umami'
metrics_path: /probe
params:
module: [umami_heartbeat]
target: ['https://analytics.example.com/api/heartbeat']
static_configs:
- targets: ['blackbox-exporter:9115']
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox-exporter:9115
Troubleshooting
Common Problems and Fixes
1. The image won’t pull, or the tag doesn’t exist
The release page says v3.5.0, the image tag is 3.5.0; using v3.5.0 fails with manifest unknown. The official registry is docker.umami.is. If the server can’t reach Docker Hub or the official registry, docker pull on a machine with internet access, then move the image over with docker save, scp and docker load. That is how the PostgreSQL image got into the test environment.
2. Port 443 is taken by another service
ss -tlnp | grep ':443'
# See who owns it
If the machine already runs Traefik, Nginx or another reverse proxy, don’t fight over 443. Either have the existing proxy forward to Umami, or do what the test environment does and let Nginx listen on 9443. Once configured, check it with curl -k against the port directly, then sort out DNS and certificates.
3. The tracker script is blocked by ad blockers
Symptom: the stats.js request doesn’t appear in the browser’s Network panel, or it’s marked blocked.
Fix: make sure TRACKER_SCRIPT_NAME and COLLECT_API_ENDPOINT are set to non-default values. If it’s still blocked, proxy the script under a path on your own domain:
# Add to the blog site's Nginx config
location = /js/s.js {
proxy_pass https://analytics.example.com/stats.js;
proxy_set_header Host analytics.example.com;
proxy_ssl_server_name on;
}
Then change src in the Hugo config to /js/s.js.
4. All geographic data shows as Unknown
Symptom: every visitor’s location in the dashboard’s Locations area is Unknown.
Fix: Umami v3 relies on IP geolocation by default. First confirm the client IP reaches Umami correctly (see CLIENT_IP_HEADER above), then check the GeoIP database:
# The 3.5.0 image ships GeoLite2-City.mmdb; normally there should be a file here
docker exec umami ls -lh /app/geo/
# If it's empty, you can point at a GeoIP database URL
# Add to .env:
# GEO_DATABASE_URL=https://your-geoip-db-url/GeoLite2-City.mmdb
In the test environment this file is about 48 MB and ships with the image. You can also switch to a MaxMind GeoLite2 database you download yourself (registration required for a license key).
5. PostgreSQL connection refused
# Check whether the database container is healthy
docker compose ps db
# Look at the database logs
docker compose logs db | tail -20
# Check the connection count
docker exec umami-db psql -U umami -d umami -c "SELECT count(*) FROM pg_stat_activity;"
6. The Umami container keeps restarting
# Check the exit code
docker inspect umami --format='{{.State.ExitCode}}'
# Check the recent logs
docker compose logs --tail=50 umami
# Common causes:
# - APP_SECRET is empty or still the placeholder (required since 3.5.0)
# - DATABASE_URL is malformed or the password doesn't match
# - PostgreSQL isn't ready yet (the healthcheck handles this)
# - Port 3000 is taken by another process
7. Data growth and cleanup
After running for a while, the database can grow fairly quickly. Check the current size:
docker exec umami-db psql -U umami -d umami -c \
"SELECT pg_size_pretty(pg_database_size('umami'));"
In the Umami admin under Settings -> Websites -> Edit you can set a data retention period or clean up old data manually.
Operations Cheat Sheet
Everyday Commands
# Service status
docker compose -f /opt/umami/docker-compose.yml ps
# Live logs
docker compose -f /opt/umami/docker-compose.yml logs -f
# Restart the service
docker compose -f /opt/umami/docker-compose.yml restart
# Update to a pinned version
cd /opt/umami && docker compose pull && docker compose up -d --force-recreate
# Manual backup
/opt/umami/scripts/backup.sh
# Database size
docker exec umami-db psql -U umami -d umami -c "SELECT pg_size_pretty(pg_database_size('umami'));"
# Open a database shell
docker exec -it umami-db psql -U umami -d umami
Upgrade Checklist
- Read the release notes and check for breaking changes
- Back up the database:
/opt/umami/scripts/backup.sh - Change the image tag in
docker-compose.yml - Pull the new image:
docker compose pull - Recreate the containers:
docker compose up -d --force-recreate - Check the logs:
docker compose logs -f umami - Verify the health check:
curl -s http://127.0.0.1:3000/api/heartbeat - Open the dashboard and confirm everything works
Since 3.5.0, an upgrade also requires two extra checks: APP_SECRET is explicitly set, and the default admin password has been changed (the new version forces this). If you’re upgrading from an older version and APP_SECRET was never set, read the APP_SECRET note above first so nobody gets logged out after the upgrade.
Comments