Add more documentetion
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
# Nextcloud Docker Migration - Environment Configuration
|
||||||
|
# Copy this file to .env and fill in your values
|
||||||
|
# NEVER commit .env to version control!
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# DATABASE CREDENTIALS (Required)
|
||||||
|
# =============================================================================
|
||||||
|
# These must match what you used during restore or what exists in the backup
|
||||||
|
DB_TYPE=postgresql # postgresql or mariadb
|
||||||
|
DB_ROOT_PASS=changeme_strong_root_password_here
|
||||||
|
DB_NAME=nextcloud
|
||||||
|
DB_USER=nextcloud
|
||||||
|
DB_PASS=changeme_strong_user_password_here
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# NEXTCLOUD DATA DIRECTORY
|
||||||
|
# =============================================================================
|
||||||
|
# Host directory where Nextcloud files will be stored (data, config, custom_apps)
|
||||||
|
NEXTCLOUD_DATA_DIR=/opt/nextcloud/nextcloud-data
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# TRUSTED DOMAINS (CRITICAL - Nextcloud will reject requests without this)
|
||||||
|
# =============================================================================
|
||||||
|
# Comma-separated, no spaces. Include all domains/IPs you'll use to access Nextcloud
|
||||||
|
# Examples:
|
||||||
|
# NEXTCLOUD_TRUSTED_DOMAINS=localhost
|
||||||
|
# NEXTCLOUD_TRUSTED_DOMAINS=cloud.example.com,localhost
|
||||||
|
# NEXTCLOUD_TRUSTED_DOMAINS=cloud.example.com,192.168.1.100,localhost
|
||||||
|
NEXTCLOUD_TRUSTED_DOMAINS=localhost
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# OPTIONAL: INITIAL ADMIN USER (Only used on fresh database install)
|
||||||
|
# =============================================================================
|
||||||
|
# If restoring from backup, these are ignored (existing users preserved)
|
||||||
|
# NEXTCLOUD_ADMIN_USER=admin
|
||||||
|
# NEXTCLOUD_ADMIN_PASSWORD=changeme_admin_password
|
||||||
|
# NEXTCLOUD_ADMIN_EMAIL=admin@example.com
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# OPTIONAL: PHP SETTINGS (Adjust for large uploads)
|
||||||
|
# =============================================================================
|
||||||
|
# PHP_MEMORY_LIMIT=512M
|
||||||
|
# PHP_MAX_EXECUTION_TIME=300
|
||||||
|
# PHP_UPLOAD_MAX_FILESIZE=10G
|
||||||
|
# PHP_POST_MAX_SIZE=10G
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# OPTIONAL: CONTAINER NAMES (Override if needed)
|
||||||
|
# =============================================================================
|
||||||
|
# DB_CONTAINER=nextcloud-db
|
||||||
|
# NEXTCLOUD_CONTAINER=nextcloud
|
||||||
|
# REDIS_CONTAINER=nextcloud-redis
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# OPTIONAL: NETWORK/PORT SETTINGS
|
||||||
|
# =============================================================================
|
||||||
|
# NEXTCLOUD_PORT=8080 # Host port for Nextcloud web UI
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Nginx Proxy Manager Docker Migration - Environment Configuration
|
||||||
|
# Copy this file to .env and fill in your values
|
||||||
|
# NEVER commit .env to version control!
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# DATABASE TYPE
|
||||||
|
# =============================================================================
|
||||||
|
# sqlite: Default, simpler, no extra container needed
|
||||||
|
# mariadb: Better performance for high-traffic setups
|
||||||
|
DB_TYPE=sqlite
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# MARIADB CREDENTIALS (Only required if DB_TYPE=mariadb)
|
||||||
|
# =============================================================================
|
||||||
|
# These must match what you used during restore or what exists in the backup
|
||||||
|
# DB_ROOT_PASS=changeme_strong_root_password_here
|
||||||
|
# DB_NAME=npm
|
||||||
|
# DB_USER=npm
|
||||||
|
# DB_PASS=changeme_strong_user_password_here
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# NPM DATA DIRECTORY
|
||||||
|
# =============================================================================
|
||||||
|
# Host directory where NPM files will be stored (config, database, SSL certs)
|
||||||
|
NPM_DATA_DIR=/opt/npm/npm-data
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# OPTIONAL: CONTAINER NAMES (Override if needed)
|
||||||
|
# =============================================================================
|
||||||
|
# DB_CONTAINER=npm-db
|
||||||
|
# NPM_CONTAINER=nginx-proxy-manager
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# OPTIONAL: PORT SETTINGS (Override if ports 80/81/443 in use)
|
||||||
|
# =============================================================================
|
||||||
|
# HTTP_PORT=80
|
||||||
|
# ADMIN_PORT=81
|
||||||
|
# HTTPS_PORT=443
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
# Quick Start: TrueNAS Nextcloud → Docker
|
||||||
|
|
||||||
|
## One-Line Commands
|
||||||
|
|
||||||
|
### On TrueNAS (Backup)
|
||||||
|
```bash
|
||||||
|
ssh root@truenas "APP_NAMESPACE=nextcloud BACKUP_DEST=/mnt/tank/backups/nextcloud bash -s" < backup-nextcloud-truenas.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### On Docker Host (Restore + Start)
|
||||||
|
```bash
|
||||||
|
# 1. Copy backup from TrueNAS to Docker host
|
||||||
|
scp root@truenas:/mnt/tank/backups/nextcloud/nextcloud_backup_*.tar.gz* /opt/nextcloud/
|
||||||
|
|
||||||
|
# 2. Run restore (set your passwords)
|
||||||
|
cd /opt/nextcloud
|
||||||
|
DB_TYPE=postgresql DB_ROOT_PASS=your_root_pass DB_PASS=your_user_pass ./restore-nextcloud-docker.sh nextcloud_backup_*.tar.gz
|
||||||
|
|
||||||
|
# 3. Edit .env with same passwords + trusted domains
|
||||||
|
nano .env
|
||||||
|
# Set: DB_ROOT_PASS=xxx DB_PASS=yyy NEXTCLOUD_TRUSTED_DOMAINS=your-domain.com,localhost
|
||||||
|
|
||||||
|
# 4. Start!
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# 5. Post-restore commands
|
||||||
|
docker-compose exec nextcloud php occ maintenance:mode --off
|
||||||
|
docker-compose exec nextcloud php occ upgrade
|
||||||
|
docker-compose exec nextcloud php occ db:add-missing-indices
|
||||||
|
docker-compose exec nextcloud php occ db:add-missing-primary-keys
|
||||||
|
```
|
||||||
|
|
||||||
|
## Minimum Required Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# TRUENAS: Run backup
|
||||||
|
ssh root@truenas
|
||||||
|
/tmp/backup-nextcloud-truenas.sh
|
||||||
|
|
||||||
|
# DOCKER HOST: Restore and start
|
||||||
|
scp root@truenas:/mnt/tank/backups/nextcloud/nextcloud_backup_*.tar.gz* .
|
||||||
|
DB_TYPE=postgresql DB_ROOT_PASS=xxx DB_PASS=yyy ./restore-nextcloud-docker.sh nextcloud_backup_*.tar.gz
|
||||||
|
cp .env.example .env # Edit with passwords + trusted domains
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Post-restore
|
||||||
|
docker-compose exec nextcloud php occ maintenance:mode --off
|
||||||
|
docker-compose exec nextcloud php occ upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verify It Works
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check containers running
|
||||||
|
docker-compose ps
|
||||||
|
|
||||||
|
# View Nextcloud logs
|
||||||
|
docker-compose logs -f nextcloud
|
||||||
|
|
||||||
|
# Test web access
|
||||||
|
curl -I http://localhost:8080
|
||||||
|
|
||||||
|
# Check Nextcloud status
|
||||||
|
docker-compose exec nextcloud php occ status
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Customizations
|
||||||
|
|
||||||
|
| Need | Command |
|
||||||
|
|------|---------|
|
||||||
|
| Custom backup location | `BACKUP_DEST=/mnt/pool/backups ./backup-nextcloud-truenas.sh` |
|
||||||
|
| Different namespace | `APP_NAMESPACE=my-nextcloud ./backup-nextcloud-truenas.sh` |
|
||||||
|
| Use MariaDB | `DB_TYPE=mariadb ./backup-nextcloud-truenas.sh` |
|
||||||
|
| Only restore files | `SKIP_DB=true ./restore-nextcloud-docker.sh backup.tar.gz` |
|
||||||
|
| Only restore database | `SKIP_FILES=true ./restore-nextcloud-docker.sh backup.tar.gz` |
|
||||||
|
| Custom data dir | `NEXTCLOUD_DATA_DIR=/data/nextcloud ./restore-nextcloud-docker.sh backup.tar.gz` |
|
||||||
|
| Non-interactive | `FORCE=true ./restore-nextcloud-docker.sh backup.tar.gz` |
|
||||||
|
|
||||||
|
## File Locations After Migration
|
||||||
|
|
||||||
|
```
|
||||||
|
/opt/nextcloud/
|
||||||
|
├── docker-compose.yml # Generated
|
||||||
|
├── .env # YOUR PASSWORDS + TRUSTED_DOMAINS HERE
|
||||||
|
├── nextcloud_backup_*.tar.gz # Backup archive (delete after verify)
|
||||||
|
├── nextcloud_backup_*.sha256 # Checksum
|
||||||
|
├── RESTORE_INFO_*.txt # Documentation
|
||||||
|
└── nextcloud-data/
|
||||||
|
├── data/ # User files
|
||||||
|
├── config/ # config.php
|
||||||
|
└── custom_apps/ # Custom apps
|
||||||
|
```
|
||||||
|
|
||||||
|
## Rollback Plan
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop Docker Nextcloud
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
# TrueNAS app untouched - restart in TrueNAS UI
|
||||||
|
# Or restore from backup (keeps last 7 by default):
|
||||||
|
ls /mnt/tank/backups/nextcloud/nextcloud_backup_*.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
## Critical .env Settings
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# REQUIRED - Database passwords
|
||||||
|
DB_ROOT_PASS=strong_random_password_here
|
||||||
|
DB_PASS=strong_random_password_here
|
||||||
|
|
||||||
|
# REQUIRED - Your domain(s) for Nextcloud to accept
|
||||||
|
NEXTCLOUD_TRUSTED_DOMAINS=cloud.example.com,localhost,192.168.1.50
|
||||||
|
|
||||||
|
# Optional - Admin user (only for fresh install)
|
||||||
|
# NEXTCLOUD_ADMIN_USER=admin
|
||||||
|
# NEXTCLOUD_ADMIN_PASSWORD=secure_admin_password
|
||||||
|
```
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
# Quick Start: TrueNAS Nginx Proxy Manager → Docker
|
||||||
|
|
||||||
|
## One-Line Commands
|
||||||
|
|
||||||
|
### On TrueNAS (Backup)
|
||||||
|
```bash
|
||||||
|
ssh root@truenas "APP_NAMESPACE=nginx-proxy-manager BACKUP_DEST=/mnt/tank/backups/npm bash -s" < backup-nginx-proxy-manager-truenas.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### On Docker Host (Restore + Start)
|
||||||
|
```bash
|
||||||
|
# 1. Copy backup from TrueNAS to Docker host
|
||||||
|
scp root@truenas:/mnt/tank/backups/npm/npm_backup_*.tar.gz* /opt/npm/
|
||||||
|
|
||||||
|
# 2. Run restore (SQLite - default, no DB passwords)
|
||||||
|
cd /opt/npm
|
||||||
|
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
|
||||||
|
|
||||||
|
# 3. Edit .env if needed (usually not needed for SQLite)
|
||||||
|
nano .env
|
||||||
|
|
||||||
|
# 4. Start!
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# 5. Access at http://docker-host:81
|
||||||
|
# Default login: admin@example.com / changeme (CHANGE IMMEDIATELY!)
|
||||||
|
```
|
||||||
|
|
||||||
|
### With MariaDB Instead
|
||||||
|
```bash
|
||||||
|
# TRUENAS: Backup with MariaDB
|
||||||
|
ssh root@truenas "DB_TYPE=mariadb APP_NAMESPACE=nginx-proxy-manager BACKUP_DEST=/mnt/tank/backups/npm bash -s" < backup-nginx-proxy-manager-truenas.sh
|
||||||
|
|
||||||
|
# DOCKER HOST: Restore with MariaDB
|
||||||
|
cd /opt/npm
|
||||||
|
DB_TYPE=mariadb DB_ROOT_PASS=xxx DB_PASS=yyy ./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
|
||||||
|
cp .env.example .env # Edit with: DB_ROOT_PASS=xxx DB_PASS=yyy
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## Minimum Required Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# TRUENAS: Run backup
|
||||||
|
ssh root@truenas
|
||||||
|
/tmp/backup-nginx-proxy-manager-truenas.sh
|
||||||
|
|
||||||
|
# DOCKER HOST: Restore and start (SQLite)
|
||||||
|
scp root@truenas:/mnt/tank/backups/npm/npm_backup_*.tar.gz* .
|
||||||
|
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## Verify It Works
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check containers running
|
||||||
|
docker-compose ps
|
||||||
|
|
||||||
|
# View NPM logs
|
||||||
|
docker-compose logs -f nginx-proxy-manager
|
||||||
|
|
||||||
|
# Test admin UI
|
||||||
|
curl -I http://localhost:81
|
||||||
|
|
||||||
|
# Test HTTP proxy
|
||||||
|
curl -I http://localhost
|
||||||
|
|
||||||
|
# Test HTTPS proxy
|
||||||
|
curl -kI https://localhost
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Customizations
|
||||||
|
|
||||||
|
| Need | Command |
|
||||||
|
|------|---------|
|
||||||
|
| Custom backup location | `BACKUP_DEST=/mnt/pool/backups ./backup-nginx-proxy-manager-truenas.sh` |
|
||||||
|
| Different namespace | `APP_NAMESPACE=my-npm ./backup-nginx-proxy-manager-truenas.sh` |
|
||||||
|
| Use MariaDB | `DB_TYPE=mariadb ./backup-nginx-proxy-manager-truenas.sh` |
|
||||||
|
| Only restore certs | `SKIP_DB=true ./restore-nginx-proxy-manager-docker.sh backup.tar.gz` |
|
||||||
|
| Only restore database | `SKIP_FILES=true ./restore-nginx-proxy-manager-docker.sh backup.tar.gz` |
|
||||||
|
| Custom data dir | `NPM_DATA_DIR=/data/npm ./restore-nginx-proxy-manager-docker.sh backup.tar.gz` |
|
||||||
|
| Non-interactive | `FORCE=true ./restore-nginx-proxy-manager-docker.sh backup.tar.gz` |
|
||||||
|
|
||||||
|
## File Locations After Migration
|
||||||
|
|
||||||
|
```
|
||||||
|
/opt/npm/
|
||||||
|
├── docker-compose.yml # Generated
|
||||||
|
├── .env # MariaDB passwords only (SQLite needs none)
|
||||||
|
├── npm_backup_*.tar.gz # Backup archive (delete after verify)
|
||||||
|
├── npm_backup_*.sha256 # Checksum
|
||||||
|
├── RESTORE_INFO_*.txt # Documentation
|
||||||
|
└── npm-data/
|
||||||
|
├── data/
|
||||||
|
│ ├── database.sqlite # SQLite DB (if used)
|
||||||
|
│ ├── config/ # production.json
|
||||||
|
│ └── custom_ssl/ # Custom SSL certs
|
||||||
|
└── letsencrypt/
|
||||||
|
├── live/ # Active Let's Encrypt certs
|
||||||
|
├── archive/ # Cert history
|
||||||
|
└── renewal/ # Renewal configs
|
||||||
|
```
|
||||||
|
|
||||||
|
## Rollback Plan
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop Docker NPM
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
# TrueNAS app untouched - restart in TrueNAS UI
|
||||||
|
# Or restore from backup (keeps last 7 by default):
|
||||||
|
ls /mnt/tank/backups/npm/npm_backup_*.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
## Critical Post-Restore Steps
|
||||||
|
|
||||||
|
1. **Login at http://docker-host:81**
|
||||||
|
- Email: `admin@example.com`
|
||||||
|
- Password: `changeme`
|
||||||
|
- **CHANGE PASSWORD IMMEDIATELY!**
|
||||||
|
|
||||||
|
2. **Verify Proxy Hosts**
|
||||||
|
- Check Hosts → Proxy Hosts
|
||||||
|
- Update Forward Hostname/IP if Docker network changed
|
||||||
|
- Test each proxy works
|
||||||
|
|
||||||
|
3. **Verify SSL Certificates**
|
||||||
|
- Check SSL Certificates tab
|
||||||
|
- Force renewal if needed
|
||||||
|
|
||||||
|
4. **Update Upstream IPs** (if changed)
|
||||||
|
- Old TrueNAS app IPs → New Docker service names
|
||||||
|
- Example: `192.168.1.100:8080` → `nextcloud:80`
|
||||||
|
|
||||||
|
## .env Settings (MariaDB Only)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Only needed for DB_TYPE=mariadb
|
||||||
|
DB_TYPE=mariadb
|
||||||
|
DB_ROOT_PASS=strong_random_password_here
|
||||||
|
DB_PASS=strong_random_password_here
|
||||||
|
|
||||||
|
# Not needed for SQLite (default)
|
||||||
|
# DB_TYPE=sqlite
|
||||||
|
```
|
||||||
@@ -0,0 +1,411 @@
|
|||||||
|
# TrueNAS Nextcloud App → Docker Migration
|
||||||
|
|
||||||
|
This guide covers migrating a Nextcloud instance from a TrueNAS App (Kubernetes/k3s) to a Docker container.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
| Script | Purpose | Run On |
|
||||||
|
|--------|---------|--------|
|
||||||
|
| `backup-nextcloud-truenas.sh` | Backup Nextcloud from TrueNAS App | TrueNAS host |
|
||||||
|
| `restore-nextcloud-docker.sh` | Restore Nextcloud to Docker | Docker host |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
### On TrueNAS Host
|
||||||
|
- TrueNAS with Nextcloud app installed
|
||||||
|
- SSH access to TrueNAS (or TrueNAS Shell)
|
||||||
|
- `k3s kubectl` available (usually at `/usr/local/bin/k3s kubectl`)
|
||||||
|
- `pg_dump` (PostgreSQL) or `mariadb-dump`/`mysqldump` (MariaDB) installed
|
||||||
|
- Write access to backup destination dataset
|
||||||
|
|
||||||
|
### On Docker Host
|
||||||
|
- Docker Engine installed
|
||||||
|
- Docker Compose (v2 plugin or standalone)
|
||||||
|
- Write access to Docker data directory
|
||||||
|
- **Recommended**: 4GB+ RAM for Nextcloud + Database + Redis
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### 1. Backup on TrueNAS
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# SSH into TrueNAS
|
||||||
|
ssh root@truenas.local
|
||||||
|
|
||||||
|
# Copy the backup script to TrueNAS
|
||||||
|
scp backup-nextcloud-truenas.sh root@truenas.local:/tmp/
|
||||||
|
|
||||||
|
# Run the backup script
|
||||||
|
APP_NAMESPACE=nextcloud \
|
||||||
|
BACKUP_DEST=/mnt/tank/backups/nextcloud \
|
||||||
|
/tmp/backup-nextcloud-truenas.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Environment Variables for Backup:**
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `APP_NAMESPACE` | `nextcloud` | Kubernetes namespace of Nextcloud app |
|
||||||
|
| `BACKUP_DEST` | `/mnt/tank/backups/nextcloud` | Destination dataset path |
|
||||||
|
| `DB_TYPE` | `postgresql` | Database type: `postgresql` or `mariadb` |
|
||||||
|
| `DB_HOST` | auto-detect | Database host |
|
||||||
|
| `DB_PORT` | auto-detect | Database port (5432 PG / 3306 MariaDB) |
|
||||||
|
| `DB_NAME` | `nextcloud` | Database name |
|
||||||
|
| `DB_USER` | `nextcloud` | Database user |
|
||||||
|
| `DB_PASS` | auto-detect | Database password |
|
||||||
|
| `PVC_DATA` | auto-detect | Data PVC name |
|
||||||
|
| `PVC_CONFIG` | auto-detect | Config PVC name |
|
||||||
|
| `PVC_APPS` | auto-detect | Custom apps PVC name |
|
||||||
|
| `RETENTION_COUNT` | `7` | Number of backups to keep |
|
||||||
|
| `COMPRESSION_LEVEL` | `6` | gzip compression (1-9) |
|
||||||
|
| `MAINTENANCE_MODE` | `true` | Enable maintenance mode during backup |
|
||||||
|
|
||||||
|
### 2. Transfer Backup to Docker Host
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# From your workstation, pull the backup from TrueNAS
|
||||||
|
scp root@truenas.local:/mnt/tank/backups/nextcloud/nextcloud_backup_*.tar.gz* .
|
||||||
|
|
||||||
|
# Copy to Docker host
|
||||||
|
scp nextcloud_backup_*.tar.gz* user@docker-host:/opt/nextcloud/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Restore on Docker Host
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# SSH into Docker host
|
||||||
|
ssh user@docker-host
|
||||||
|
|
||||||
|
# Make scripts executable
|
||||||
|
chmod +x restore-nextcloud-docker.sh
|
||||||
|
|
||||||
|
# Run restore (set required passwords)
|
||||||
|
DB_TYPE=postgresql \
|
||||||
|
DB_ROOT_PASS=your_root_password \
|
||||||
|
DB_PASS=your_nextcloud_password \
|
||||||
|
./restore-nextcloud-docker.sh /opt/nextcloud/nextcloud_backup_20240115_120000.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
**Environment Variables for Restore:**
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `DOCKER_DIR` | `/opt/nextcloud` | Docker project directory |
|
||||||
|
| `COMPOSE_FILE` | `docker-compose.yml` | Compose filename |
|
||||||
|
| `DB_CONTAINER` | `nextcloud-db` | Database container name |
|
||||||
|
| `NEXTCLOUD_CONTAINER` | `nextcloud` | Nextcloud container name |
|
||||||
|
| `DB_TYPE` | `postgresql` | Database type: `postgresql` or `mariadb` |
|
||||||
|
| `DB_ROOT_PASS` | **required** | Database root password |
|
||||||
|
| `DB_NAME` | `nextcloud` | Database name |
|
||||||
|
| `DB_USER` | `nextcloud` | Database user |
|
||||||
|
| `DB_PASS` | **required** | Database user password |
|
||||||
|
| `NEXTCLOUD_DATA_DIR` | `${DOCKER_DIR}/nextcloud-data` | Host data directory |
|
||||||
|
| `REDIS_ENABLED` | `true` | Enable Redis cache |
|
||||||
|
| `SKIP_DB` | `false` | Skip database restore |
|
||||||
|
| `SKIP_FILES` | `false` | Skip files restore |
|
||||||
|
| `FORCE` | `false` | Skip confirmations |
|
||||||
|
|
||||||
|
### 4. Configure and Start Nextcloud
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/nextcloud
|
||||||
|
|
||||||
|
# Edit .env with your passwords and domain (IMPORTANT!)
|
||||||
|
nano .env
|
||||||
|
|
||||||
|
# Required changes in .env:
|
||||||
|
# - DB_ROOT_PASS=your_strong_root_password
|
||||||
|
# - DB_PASS=your_strong_user_password
|
||||||
|
# - NEXTCLOUD_TRUSTED_DOMAINS=your-domain.com,localhost,192.168.x.x
|
||||||
|
|
||||||
|
# Start containers
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Check logs
|
||||||
|
docker-compose logs -f nextcloud
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Post-Restore Steps
|
||||||
|
|
||||||
|
After containers are running, run these commands:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Disable maintenance mode (if backup had it enabled)
|
||||||
|
docker-compose exec nextcloud php occ maintenance:mode --off
|
||||||
|
|
||||||
|
# Run database upgrades
|
||||||
|
docker-compose exec nextcloud php occ upgrade
|
||||||
|
|
||||||
|
# Fix database schema
|
||||||
|
docker-compose exec nextcloud php occ db:add-missing-indices
|
||||||
|
docker-compose exec nextcloud php occ db:add-missing-primary-keys
|
||||||
|
|
||||||
|
# Clear cache
|
||||||
|
docker-compose exec nextcloud php occ cache:clear
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Access Nextcloud
|
||||||
|
|
||||||
|
Open your browser to `http://<docker-host>:8080`
|
||||||
|
|
||||||
|
- If database was restored: Your existing Nextcloud with all files/users
|
||||||
|
- If fresh database: Nextcloud installer will appear
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Detailed Workflow
|
||||||
|
|
||||||
|
### Backup Process (TrueNAS)
|
||||||
|
|
||||||
|
The backup script performs these steps:
|
||||||
|
|
||||||
|
1. **Detection**: Finds Kubernetes namespace, database credentials, and PVCs
|
||||||
|
2. **Maintenance Mode**: Enables `occ maintenance:mode --on` (configurable)
|
||||||
|
3. **Manifests**: Exports all K8s resources
|
||||||
|
4. **Database**: Dumps PostgreSQL or MariaDB database
|
||||||
|
5. **Files**: Creates temporary pods to copy data from PVCs:
|
||||||
|
- `data/` → Nextcloud data directory (user files)
|
||||||
|
- `config/` → Nextcloud config directory (config.php)
|
||||||
|
- `apps/` → Nextcloud custom apps (if separate PVC)
|
||||||
|
6. **Archive**: Creates compressed `.tar.gz` with checksum
|
||||||
|
7. **Cleanup**: Disables maintenance mode, removes old backups
|
||||||
|
8. **Info**: Generates `RESTORE_INFO_<timestamp>.txt`
|
||||||
|
|
||||||
|
### Restore Process (Docker)
|
||||||
|
|
||||||
|
The restore script performs these steps:
|
||||||
|
|
||||||
|
1. **Validation**: Verifies backup archive integrity (checksum)
|
||||||
|
2. **Extraction**: Unpacks backup to temporary directory
|
||||||
|
3. **Docker Compose**: Generates `docker-compose.yml` and `.env` template
|
||||||
|
4. **Database**: Recreates database and restores from SQL dump
|
||||||
|
5. **Files**: Syncs data, config, and custom apps to host directory
|
||||||
|
6. **Permissions**: Fixes file ownership for www-data (UID 33)
|
||||||
|
7. **Guidance**: Shows next steps including `occ` commands
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Docker Compose Structure
|
||||||
|
|
||||||
|
The generated `docker-compose.yml` creates:
|
||||||
|
|
||||||
|
```
|
||||||
|
nextcloud/
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── .env # Your passwords (EDIT THIS!)
|
||||||
|
├── nextcloud-data/ # Host-mounted Nextcloud data
|
||||||
|
│ ├── data/ # User files
|
||||||
|
│ ├── config/ # config.php
|
||||||
|
│ └── custom_apps/ # Custom apps (if used)
|
||||||
|
└── db-data/ # Database volume (Docker managed)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Services Included
|
||||||
|
|
||||||
|
| Service | Image | Purpose |
|
||||||
|
|---------|-------|---------|
|
||||||
|
| `db` | `postgres:16` or `mariadb:10.11` | Database |
|
||||||
|
| `redis` | `redis:7-alpine` | Memory cache |
|
||||||
|
| `nextcloud` | `nextcloud:latest` | Nextcloud app |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Common Scenarios
|
||||||
|
|
||||||
|
### Migration with Same Database Credentials
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# On TrueNAS, note the DB_PASS from backup output or secret
|
||||||
|
# On Docker host, use same passwords:
|
||||||
|
DB_TYPE=postgresql \
|
||||||
|
DB_ROOT_PASS=same_as_truenas \
|
||||||
|
DB_PASS=same_as_truenas \
|
||||||
|
./restore-nextcloud-docker.sh backup.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fresh Database, Restore Only Files
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SKIP_DB=true \
|
||||||
|
./restore-nextcloud-docker.sh backup.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Restore Only Database
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SKIP_FILES=true \
|
||||||
|
./restore-nextcloud-docker.sh backup.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using MariaDB Instead of PostgreSQL
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Backup (TrueNAS)
|
||||||
|
DB_TYPE=mariadb ./backup-nextcloud-truenas.sh
|
||||||
|
|
||||||
|
# Restore (Docker)
|
||||||
|
DB_TYPE=mariadb \
|
||||||
|
DB_ROOT_PASS=xxx DB_PASS=yyy \
|
||||||
|
./restore-nextcloud-docker.sh backup.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom Data Directory
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NEXTCLOUD_DATA_DIR=/data/nextcloud \
|
||||||
|
./restore-nextcloud-docker.sh backup.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Nextcloud-Specific Configuration
|
||||||
|
|
||||||
|
### Trusted Domains
|
||||||
|
|
||||||
|
**Critical**: Update `NEXTCLOUD_TRUSTED_DOMAINS` in `.env` before starting:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NEXTCLOUD_TRUSTED_DOMAINS=localhost,nextcloud.example.com,192.168.1.100
|
||||||
|
```
|
||||||
|
|
||||||
|
### Redis Configuration
|
||||||
|
|
||||||
|
Redis is enabled by default in the generated compose. Nextcloud will auto-configure it via environment variables.
|
||||||
|
|
||||||
|
### Cron Jobs
|
||||||
|
|
||||||
|
Set up background jobs (recommended: system cron):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Add to host crontab (runs every 5 minutes)
|
||||||
|
*/5 * * * * docker exec -u www-data nextcloud php -f /var/www/html/cron.php
|
||||||
|
```
|
||||||
|
|
||||||
|
Or use Docker cron container.
|
||||||
|
|
||||||
|
### HTTPS / Reverse Proxy
|
||||||
|
|
||||||
|
Put Nextcloud behind a reverse proxy (Traefik, Nginx Proxy Manager, Caddy):
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# Example Traefik labels in docker-compose.yml
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.nextcloud.rule=Host(\`cloud.example.com\`)"
|
||||||
|
- "traefik.http.routers.nextcloud.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.services.nextcloud.loadbalancer.server.port=80"
|
||||||
|
```
|
||||||
|
|
||||||
|
Then set `overwrite.cli.url` and `overwriteprotocol` in `config.php`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Backup Fails: "Database dump failed"
|
||||||
|
|
||||||
|
1. Check database credentials are correct
|
||||||
|
2. Ensure `pg_dump` (PostgreSQL) or `mariadb-dump` (MariaDB) is installed on TrueNAS
|
||||||
|
3. Verify database is accessible:
|
||||||
|
```bash
|
||||||
|
# PostgreSQL
|
||||||
|
pg_dump -h <DB_HOST> -U <DB_USER> -d <DB_NAME> -c
|
||||||
|
# MariaDB
|
||||||
|
mariadb -h <DB_HOST> -u <DB_USER> -p<DB_PASS> <DB_NAME> -e "SELECT 1"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Backup Fails: "PVC not found"
|
||||||
|
|
||||||
|
1. Check PVC names: `k3s kubectl get pvc -n nextcloud`
|
||||||
|
2. Set `PVC_DATA`, `PVC_CONFIG`, `PVC_APPS` explicitly
|
||||||
|
|
||||||
|
### Restore Fails: "Database not ready"
|
||||||
|
|
||||||
|
1. Check database container logs: `docker-compose logs db`
|
||||||
|
2. Ensure `DB_ROOT_PASS` in `.env` matches what you passed to restore script
|
||||||
|
3. PostgreSQL: check `pg_isready` works
|
||||||
|
|
||||||
|
### Nextcloud Shows "Database Connection Failed"
|
||||||
|
|
||||||
|
1. Verify `.env` has correct `POSTGRES_HOST=db` or `MYSQL_HOST=db`
|
||||||
|
2. Check `POSTGRES_DB`/`MYSQL_DATABASE`, `POSTGRES_USER`/`MYSQL_USER`, `POSTGRES_PASSWORD`/`MYSQL_PASSWORD`
|
||||||
|
3. Ensure database container is healthy: `docker-compose ps`
|
||||||
|
|
||||||
|
### Permission Errors on Files
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm -v /opt/nextcloud/nextcloud-data:/data alpine:latest \
|
||||||
|
sh -c "chown -R 33:33 /data && find /data -type d -exec chmod 750 {} \\; && find /data -type f -exec chmod 640 {} \\;"
|
||||||
|
```
|
||||||
|
|
||||||
|
### "Trusted Domain" Error
|
||||||
|
|
||||||
|
Add your domain to `config.php` or use `NEXTCLOUD_TRUSTED_DOMAINS` in `.env`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose exec nextcloud php occ config:system:set trusted_domains 1 --value="your-domain.com"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Large Backup Times Out
|
||||||
|
|
||||||
|
For very large instances, run restore in steps:
|
||||||
|
```bash
|
||||||
|
# Restore DB first
|
||||||
|
SKIP_FILES=true ./restore-nextcloud-docker.sh backup.tar.gz
|
||||||
|
# Then files
|
||||||
|
SKIP_DB=true ./restore-nextcloud-docker.sh backup.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Security Notes
|
||||||
|
|
||||||
|
1. **Never commit `.env` to version control** - contains passwords
|
||||||
|
2. **Use strong passwords** for `DB_ROOT_PASS` and `DB_PASS`
|
||||||
|
3. **Restrict backup access** - backup archives contain all user files and database
|
||||||
|
4. **Use HTTPS in production** - put Nextcloud behind a reverse proxy
|
||||||
|
5. **Regular backups** - Set up automated backups for the Docker deployment
|
||||||
|
6. **Update Nextcloud regularly** - `docker-compose pull && docker-compose up -d`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## File Structure After Restore
|
||||||
|
|
||||||
|
```
|
||||||
|
/opt/nextcloud/
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── .env # ← EDIT THIS FIRST
|
||||||
|
├── nextcloud_backup_*.tar.gz # Backup archive (can delete after verify)
|
||||||
|
├── nextcloud_backup_*.sha256 # Checksum
|
||||||
|
├── RESTORE_INFO_*.txt # Restore documentation
|
||||||
|
└── nextcloud-data/
|
||||||
|
├── data/
|
||||||
|
│ ├── user1/files/...
|
||||||
|
│ └── ...
|
||||||
|
├── config/
|
||||||
|
│ ├── config.php
|
||||||
|
│ └── ...
|
||||||
|
└── custom_apps/
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you encounter issues:
|
||||||
|
|
||||||
|
1. Check the log output from both scripts
|
||||||
|
2. Verify all prerequisites are met
|
||||||
|
3. Ensure network connectivity between containers
|
||||||
|
4. Check TrueNAS app logs: `k3s kubectl logs -n nextcloud -l app=nextcloud`
|
||||||
|
5. Check Docker logs: `docker-compose logs nextcloud`
|
||||||
|
6. Run `docker-compose exec nextcloud php occ status` for Nextcloud health
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT License - Feel free to use and modify for your needs.
|
||||||
@@ -0,0 +1,424 @@
|
|||||||
|
# TrueNAS Nginx Proxy Manager App → Docker Migration
|
||||||
|
|
||||||
|
This guide covers migrating an Nginx Proxy Manager instance from a TrueNAS App (Kubernetes/k3s) to a Docker container.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
| Script | Purpose | Run On |
|
||||||
|
|--------|---------|--------|
|
||||||
|
| `backup-nginx-proxy-manager-truenas.sh` | Backup NPM from TrueNAS App | TrueNAS host |
|
||||||
|
| `restore-nginx-proxy-manager-docker.sh` | Restore NPM to Docker | Docker host |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
### On TrueNAS Host
|
||||||
|
- TrueNAS with Nginx Proxy Manager app installed
|
||||||
|
- SSH access to TrueNAS (or TrueNAS Shell)
|
||||||
|
- `k3s kubectl` available (usually at `/usr/local/bin/k3s kubectl`)
|
||||||
|
- `sqlite3` (for SQLite) or `mariadb-dump`/`mysqldump` (for MariaDB) installed
|
||||||
|
- Write access to backup destination dataset
|
||||||
|
|
||||||
|
### On Docker Host
|
||||||
|
- Docker Engine installed
|
||||||
|
- Docker Compose (v2 plugin or standalone)
|
||||||
|
- Write access to Docker data directory
|
||||||
|
- Ports 80, 81, 443 available
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### 1. Backup on TrueNAS
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# SSH into TrueNAS
|
||||||
|
ssh root@truenas.local
|
||||||
|
|
||||||
|
# Copy the backup script to TrueNAS
|
||||||
|
scp backup-nginx-proxy-manager-truenas.sh root@truenas.local:/tmp/
|
||||||
|
|
||||||
|
# Run the backup script
|
||||||
|
APP_NAMESPACE=nginx-proxy-manager \
|
||||||
|
BACKUP_DEST=/mnt/tank/backups/npm \
|
||||||
|
/tmp/backup-nginx-proxy-manager-truenas.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Environment Variables for Backup:**
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `APP_NAMESPACE` | `nginx-proxy-manager` | Kubernetes namespace of NPM app |
|
||||||
|
| `BACKUP_DEST` | `/mnt/tank/backups/npm` | Destination dataset path |
|
||||||
|
| `DB_TYPE` | `sqlite` | Database type: `sqlite` or `mariadb` |
|
||||||
|
| `DB_HOST` | auto-detect | Database host (MariaDB only) |
|
||||||
|
| `DB_PORT` | auto-detect | Database port (3306 MariaDB) |
|
||||||
|
| `DB_NAME` | `npm` | Database name |
|
||||||
|
| `DB_USER` | `npm` | Database user |
|
||||||
|
| `DB_PASS` | auto-detect | Database password |
|
||||||
|
| `PVC_DATA` | auto-detect | Data PVC name (config, SQLite DB) |
|
||||||
|
| `PVC_LETS_ENCRYPT` | auto-detect | Let's Encrypt certificates PVC |
|
||||||
|
| `RETENTION_COUNT` | `7` | Number of backups to keep |
|
||||||
|
| `COMPRESSION_LEVEL` | `6` | gzip compression (1-9) |
|
||||||
|
|
||||||
|
### 2. Transfer Backup to Docker Host
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# From your workstation, pull the backup from TrueNAS
|
||||||
|
scp root@truenas.local:/mnt/tank/backups/npm/npm_backup_*.tar.gz* .
|
||||||
|
|
||||||
|
# Copy to Docker host
|
||||||
|
scp npm_backup_*.tar.gz* user@docker-host:/opt/npm/
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Restore on Docker Host
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# SSH into Docker host
|
||||||
|
ssh user@docker-host
|
||||||
|
|
||||||
|
# Make scripts executable
|
||||||
|
chmod +x restore-nginx-proxy-manager-docker.sh
|
||||||
|
|
||||||
|
# Run restore (SQLite - default, no DB passwords needed)
|
||||||
|
./restore-nginx-proxy-manager-docker.sh /opt/npm/npm_backup_20240115_120000.tar.gz
|
||||||
|
|
||||||
|
# OR for MariaDB:
|
||||||
|
DB_TYPE=mariadb \
|
||||||
|
DB_ROOT_PASS=your_root_password \
|
||||||
|
DB_PASS=your_npm_password \
|
||||||
|
./restore-nginx-proxy-manager-docker.sh /opt/npm/npm_backup_20240115_120000.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
**Environment Variables for Restore:**
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `DOCKER_DIR` | `/opt/npm` | Docker project directory |
|
||||||
|
| `COMPOSE_FILE` | `docker-compose.yml` | Compose filename |
|
||||||
|
| `DB_CONTAINER` | `npm-db` | Database container name (MariaDB only) |
|
||||||
|
| `NPM_CONTAINER` | `nginx-proxy-manager` | NPM container name |
|
||||||
|
| `DB_TYPE` | `sqlite` | Database type: `sqlite` or `mariadb` |
|
||||||
|
| `DB_ROOT_PASS` | required for MariaDB | Database root password |
|
||||||
|
| `DB_NAME` | `npm` | Database name |
|
||||||
|
| `DB_USER` | `npm` | Database user |
|
||||||
|
| `DB_PASS` | required for MariaDB | Database user password |
|
||||||
|
| `NPM_DATA_DIR` | `${DOCKER_DIR}/npm-data` | Host data directory |
|
||||||
|
| `SKIP_DB` | `false` | Skip database restore |
|
||||||
|
| `SKIP_FILES` | `false` | Skip files restore |
|
||||||
|
| `FORCE` | `false` | Skip confirmations |
|
||||||
|
|
||||||
|
### 4. Configure and Start NPM
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/npm
|
||||||
|
|
||||||
|
# Edit .env with your passwords (if using MariaDB)
|
||||||
|
nano .env
|
||||||
|
|
||||||
|
# Start containers
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Check logs
|
||||||
|
docker-compose logs -f nginx-proxy-manager
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Access Nginx Proxy Manager
|
||||||
|
|
||||||
|
Open your browser to `http://<docker-host>:81`
|
||||||
|
|
||||||
|
**Default login (CHANGE IMMEDIATELY!):**
|
||||||
|
- Email: `admin@example.com`
|
||||||
|
- Password: `changeme`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Detailed Workflow
|
||||||
|
|
||||||
|
### Backup Process (TrueNAS)
|
||||||
|
|
||||||
|
The backup script performs these steps:
|
||||||
|
|
||||||
|
1. **Detection**: Finds Kubernetes namespace, database type, and PVCs
|
||||||
|
2. **Manifests**: Exports all K8s resources
|
||||||
|
3. **Database**:
|
||||||
|
- SQLite: Backed up as part of data PVC (file: `data/database.sqlite`)
|
||||||
|
- MariaDB: Dumps database with `mariadb-dump`
|
||||||
|
4. **Files**: Creates temporary pods to copy data from PVCs:
|
||||||
|
- `data/` → NPM data directory (config, SSL certs, SQLite DB)
|
||||||
|
- `letsencrypt/` → Let's Encrypt certificates (if separate PVC)
|
||||||
|
5. **Archive**: Creates compressed `.tar.gz` with checksum
|
||||||
|
6. **Cleanup**: Removes old backups per retention policy
|
||||||
|
7. **Info**: Generates `RESTORE_INFO_<timestamp>.txt`
|
||||||
|
|
||||||
|
### Restore Process (Docker)
|
||||||
|
|
||||||
|
The restore script performs these steps:
|
||||||
|
|
||||||
|
1. **Validation**: Verifies backup archive integrity (checksum)
|
||||||
|
2. **Extraction**: Unpacks backup to temporary directory
|
||||||
|
3. **Docker Compose**: Generates `docker-compose.yml` and `.env` template
|
||||||
|
4. **Database** (MariaDB only): Recreates database and restores from SQL dump
|
||||||
|
5. **Files**: Syncs data and letsencrypt directories to host
|
||||||
|
6. **Guidance**: Shows next steps including default login credentials
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Docker Compose Structure
|
||||||
|
|
||||||
|
The generated `docker-compose.yml` creates:
|
||||||
|
|
||||||
|
### SQLite (Default)
|
||||||
|
```
|
||||||
|
npm/
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── .env # Your config
|
||||||
|
├── npm-backup_*.tar.gz # Backup archive
|
||||||
|
├── npm-backup_*.sha256 # Checksum
|
||||||
|
├── RESTORE_INFO_*.txt # Restore documentation
|
||||||
|
└── npm-data/
|
||||||
|
├── data/ # NPM config, database.sqlite, custom SSL
|
||||||
|
│ ├── database.sqlite
|
||||||
|
│ ├── config/
|
||||||
|
│ └── custom_ssl/
|
||||||
|
└── letsencrypt/ # Let's Encrypt certificates
|
||||||
|
├── live/
|
||||||
|
└── archive/
|
||||||
|
```
|
||||||
|
|
||||||
|
### MariaDB
|
||||||
|
```
|
||||||
|
npm/
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── .env # Your passwords (EDIT THIS!)
|
||||||
|
├── npm-backup_*.tar.gz
|
||||||
|
├── npm-backup_*.sha256
|
||||||
|
├── RESTORE_INFO_*.txt
|
||||||
|
└── npm-data/
|
||||||
|
├── data/ # NPM config, custom SSL
|
||||||
|
└── letsencrypt/ # Let's Encrypt certificates
|
||||||
|
```
|
||||||
|
*(Database stored in Docker volume `db-data`)*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Database Options
|
||||||
|
|
||||||
|
### SQLite (Default, Simpler)
|
||||||
|
- **Pros**: No separate database container, simpler setup, portable
|
||||||
|
- **Cons**: Less performant for high-traffic setups
|
||||||
|
- **Backup**: Single file `data/database.sqlite` in data PVC
|
||||||
|
- **Restore**: Automatic with file restore
|
||||||
|
|
||||||
|
### MariaDB (Production Recommended)
|
||||||
|
- **Pros**: Better performance, concurrent access, standard SQL
|
||||||
|
- **Cons**: Extra container, more complex
|
||||||
|
- **Backup**: SQL dump via `mariadb-dump`
|
||||||
|
- **Restore**: Requires `DB_ROOT_PASS` and `DB_PASS`
|
||||||
|
|
||||||
|
**To use MariaDB:**
|
||||||
|
```bash
|
||||||
|
# Backup (TrueNAS) - auto-detects if MariaDB secret exists
|
||||||
|
DB_TYPE=mariadb ./backup-nginx-proxy-manager-truenas.sh
|
||||||
|
|
||||||
|
# Restore (Docker)
|
||||||
|
DB_TYPE=mariadb \
|
||||||
|
DB_ROOT_PASS=strong_root_pass \
|
||||||
|
DB_PASS=strong_user_pass \
|
||||||
|
./restore-nginx-proxy-manager-docker.sh backup.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Common Scenarios
|
||||||
|
|
||||||
|
### Migration with SQLite (Default)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# TrueNAS backup (auto-detects SQLite)
|
||||||
|
./backup-nginx-proxy-manager-truenas.sh
|
||||||
|
|
||||||
|
# Docker restore (no DB passwords needed)
|
||||||
|
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Migration with MariaDB
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# TrueNAS backup
|
||||||
|
DB_TYPE=mariadb ./backup-nginx-proxy-manager-truenas.sh
|
||||||
|
|
||||||
|
# Docker restore
|
||||||
|
DB_TYPE=mariadb \
|
||||||
|
DB_ROOT_PASS=xxx DB_PASS=yyy \
|
||||||
|
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Only Restore Certificates (Let's Encrypt)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
SKIP_DB=true \
|
||||||
|
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom Data Directory
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NPM_DATA_DIR=/data/npm \
|
||||||
|
./restore-nginx-proxy-manager-docker.sh npm_backup_*.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Nginx Proxy Manager Specific Notes
|
||||||
|
|
||||||
|
### Default Login Credentials
|
||||||
|
|
||||||
|
After first startup, **immediately change** the default admin:
|
||||||
|
- Email: `admin@example.com`
|
||||||
|
- Password: `changeme`
|
||||||
|
|
||||||
|
### Proxy Host Configuration
|
||||||
|
|
||||||
|
After restore, verify all proxy hosts:
|
||||||
|
1. Check **Hosts → Proxy Hosts** - all entries should appear
|
||||||
|
2. Verify **Forward Hostname/IP** - may need updates if Docker network changed
|
||||||
|
3. Test each proxy host works
|
||||||
|
|
||||||
|
### SSL Certificates
|
||||||
|
|
||||||
|
Let's Encrypt certificates in `letsencrypt/` restore automatically:
|
||||||
|
- `live/` - Active certificates
|
||||||
|
- `archive/` - Certificate history
|
||||||
|
- `renewal/` - Renewal configs
|
||||||
|
|
||||||
|
Certificates should work immediately if domain names unchanged.
|
||||||
|
|
||||||
|
### Custom SSL Certificates
|
||||||
|
|
||||||
|
Custom SSL certs stored in `data/custom_ssl/` restore automatically.
|
||||||
|
|
||||||
|
### Access Lists & Audit Logs
|
||||||
|
|
||||||
|
- Access lists: Restored from database
|
||||||
|
- Audit logs: Restored from database (SQLite or MariaDB)
|
||||||
|
|
||||||
|
### Network Considerations
|
||||||
|
|
||||||
|
**Important**: If your Docker host IP changed, update proxy host forward IPs:
|
||||||
|
- Old: `192.168.1.100:8080` (TrueNAS app IP)
|
||||||
|
- New: `172.17.0.5:8080` (Docker container IP) or service name
|
||||||
|
|
||||||
|
Use Docker service names when possible:
|
||||||
|
```
|
||||||
|
# Instead of IP, use service name
|
||||||
|
Forward Hostname: nextcloud
|
||||||
|
Port: 80
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Backup Fails: "Database dump failed" (MariaDB)
|
||||||
|
|
||||||
|
1. Check database credentials
|
||||||
|
2. Ensure `mariadb-dump` installed on TrueNAS
|
||||||
|
3. Verify database accessible:
|
||||||
|
```bash
|
||||||
|
mariadb -h <DB_HOST> -u <DB_USER> -p<DB_PASS> <DB_NAME> -e "SELECT 1"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Backup Fails: "PVC not found"
|
||||||
|
|
||||||
|
1. Check PVC names: `k3s kubectl get pvc -n nginx-proxy-manager`
|
||||||
|
2. Set `PVC_DATA`, `PVC_LETS_ENCRYPT` explicitly
|
||||||
|
|
||||||
|
### Restore Fails: "Database not ready" (MariaDB)
|
||||||
|
|
||||||
|
1. Check database logs: `docker-compose logs db`
|
||||||
|
2. Ensure `DB_ROOT_PASS` in `.env` matches restore script
|
||||||
|
3. Check MariaDB healthcheck passes
|
||||||
|
|
||||||
|
### NPM Web UI Not Accessible
|
||||||
|
|
||||||
|
1. Check container running: `docker-compose ps`
|
||||||
|
2. Check logs: `docker-compose logs nginx-proxy-manager`
|
||||||
|
3. Verify ports 80, 81, 443 not used by host
|
||||||
|
4. Check firewall allows ports
|
||||||
|
|
||||||
|
### Proxy Hosts Show 502 Bad Gateway
|
||||||
|
|
||||||
|
1. Verify upstream service is running
|
||||||
|
2. Check forward hostname/IP in proxy host config
|
||||||
|
3. Use Docker service names instead of IPs
|
||||||
|
4. Check Docker network connectivity:
|
||||||
|
```bash
|
||||||
|
docker exec nginx-proxy-manager ping nextcloud
|
||||||
|
```
|
||||||
|
|
||||||
|
### SSL Certificate Errors
|
||||||
|
|
||||||
|
1. Check certificates exist in `npm-data/letsencrypt/live/`
|
||||||
|
2. Verify certificate matches domain
|
||||||
|
3. Force renewal in NPM UI: **SSL Certificates → Force Renewal**
|
||||||
|
|
||||||
|
### Permission Issues
|
||||||
|
|
||||||
|
NPM runs as root (UID 0) in container, so permissions are usually fine. If issues:
|
||||||
|
```bash
|
||||||
|
docker run --rm -v /opt/npm/npm-data:/data alpine:latest \
|
||||||
|
sh -c "chown -R 0:0 /data && chmod -R 755 /data"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Security Notes
|
||||||
|
|
||||||
|
1. **Change default admin password immediately!**
|
||||||
|
2. **Never commit `.env` to version control** - contains passwords (MariaDB)
|
||||||
|
3. **Use strong passwords** for `DB_ROOT_PASS` and `DB_PASS` (MariaDB)
|
||||||
|
4. **Restrict backup access** - archives contain SSL private keys!
|
||||||
|
5. **Use HTTPS for admin UI** - put NPM behind itself or another proxy
|
||||||
|
6. **Regular backups** - Set up automated backups for Docker deployment
|
||||||
|
7. **Update NPM regularly** - `docker-compose pull && docker-compose up -d`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## File Structure After Restore
|
||||||
|
|
||||||
|
```
|
||||||
|
/opt/npm/
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── .env # ← EDIT THIS (MariaDB passwords)
|
||||||
|
├── npm_backup_*.tar.gz # Backup archive
|
||||||
|
├── npm_backup_*.sha256 # Checksum
|
||||||
|
├── RESTORE_INFO_*.txt # Restore documentation
|
||||||
|
└── npm-data/
|
||||||
|
├── data/
|
||||||
|
│ ├── database.sqlite # SQLite DB (if used)
|
||||||
|
│ ├── config/
|
||||||
|
│ │ └── production.json # NPM config
|
||||||
|
│ └── custom_ssl/ # Custom SSL certificates
|
||||||
|
└── letsencrypt/
|
||||||
|
├── live/ # Active certs
|
||||||
|
├── archive/ # Cert history
|
||||||
|
└── renewal/ # Renewal configs
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
If you encounter issues:
|
||||||
|
|
||||||
|
1. Check log output from both scripts
|
||||||
|
2. Verify all prerequisites met
|
||||||
|
3. Check TrueNAS app logs: `k3s kubectl logs -n nginx-proxy-manager -l app=nginx-proxy-manager`
|
||||||
|
4. Check Docker logs: `docker-compose logs nginx-proxy-manager`
|
||||||
|
5. Verify network connectivity: `docker exec nginx-proxy-manager ping <upstream-service>`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT License - Feel free to use and modify for your needs.
|
||||||
Reference in New Issue
Block a user