Add Borgmatic backup

This commit is contained in:
2025-12-09 02:45:07 +03:30
parent f9d16ab078
commit 9ad4da8fe0
4 changed files with 216 additions and 0 deletions

105
backup/borgmatic-README.md Normal file
View File

@@ -0,0 +1,105 @@
# Borgmatic Backup
Automated backup solution using [borgmatic](https://torsion.org/borgmatic/) for Docker volumes and PostgreSQL databases with xattr preservation.
## What Gets Backed Up
**Named Volumes:**
- `opencloud-config` - OpenCloud configuration
- `opencloud-data` - OpenCloud user data
- `gitea_data` - Gitea repositories and data
- `odoo-db-data` - Odoo filestore
- `odoo-config` - Odoo configuration
**PostgreSQL Databases:**
- `giteadb` - Gitea database
- `odoodb` - Odoo database
## Features
- Preserves extended attributes (xattrs) and ACLs
- Deduplication and zstd compression
- Automated PostgreSQL dumps before each backup
- Retention: 7 daily, 4 weekly, 6 monthly, 1 yearly
- Scheduled daily at 3:00 AM
## Setup
1. Add to your `.env`:
```bash
BORG_PASSPHRASE=your-strong-passphrase
```
2. Initialize the repository (first time only):
```bash
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borgmatic init --encryption repokey-blake2
```
## Usage
### Run Manual Backup
```bash
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borgmatic --stats -v 1
```
### Start Scheduled Backups
```bash
docker compose -f backup/borgmatic.yml up -d
```
### List Archives
```bash
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borgmatic list
```
### Restore
```bash
# List files in an archive
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borg list ::archive-name
# Extract entire archive
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borg extract ::archive-name
# Extract specific path
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borg extract ::archive-name source/gitea_data
```
### Restore PostgreSQL Database
```bash
# Extract dump from backup
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borg extract ::archive-name source/pgdumps/giteadb.dump
# Restore to database
docker exec -i postgres pg_restore -U admin -d giteadb -c /path/to/giteadb.dump
```
### Check Repository
```bash
docker compose -f backup/borgmatic.yml run --rm borgmatic \
borgmatic check
```
## Configuration
- `backup/borgmatic.yml` - Docker compose service
- `config/borgmatic/config.yaml` - Borgmatic configuration
- `config/borgmatic/crontab.txt` - Backup schedule
## Security
⚠️ **Keep `BORG_PASSPHRASE` safe** - without it, backups cannot be restored.

50
backup/borgmatic.yml Normal file
View File

@@ -0,0 +1,50 @@
---
services:
borgmatic:
image: ghcr.io/borgmatic-collective/borgmatic:latest
container_name: borgmatic
restart: unless-stopped
environment:
TZ: ${TIMEZONE:-UTC}
BORG_PASSPHRASE: ${BORG_PASSPHRASE}
BORG_RELOCATED_REPO_ACCESS_IS_OK: "yes"
# PostgreSQL connection
PGHOST: postgres
PGPORT: "5432"
PGUSER: ${POSTGRES_ADMIN_USER}
PGPASSWORD: ${POSTGRES_ADMIN_PASSWORD}
volumes:
# Borgmatic configuration
- ./config/borgmatic:/etc/borgmatic.d:ro
# Borg repository storage
- ${BORG_REPO_DIR:-borg-repo}:/borg/repo
# Named volumes to backup (read-only)
- opencloud-config:/source/opencloud-config:ro
- opencloud-data:/source/opencloud-data:ro
- gitea_data:/source/gitea_data:ro
- odoo-db-data:/source/odoo-db-data:ro
- odoo-config:/source/odoo-config:ro
# PostgreSQL dumps directory
- borgmatic-pgdumps:/source/pgdumps
# Borg cache and state
- borgmatic-cache:/root/.cache/borg
- borgmatic-state:/root/.borgmatic
labels:
- "traefik.enable=false"
volumes:
opencloud-config:
external: true
opencloud-data:
external: true
gitea_data:
external: true
odoo-db-data:
external: true
odoo-config:
external: true
borg-repo:
borgmatic-pgdumps:
borgmatic-cache:
borgmatic-state: