knowledge › Self Hosting

Nextcloud

Using Docker, I run an instance of Nextcloud on my home server that's backed up to Backblaze B2.

Docker

This is the bare minimum required to set up Nextcloud with a PostgreSQL database. Additional setup is required for placing this service behind a reverse proxy like jwilder/nginx-proxy or Traefik.

version: '3.7'

services: 
  nextcloud:
    container_name: 'nextcloud'
    image: nextcloud:17-apache
    restart: unless-stopped
    volumes:
      - ./nextcloud:/var/www/html
      - /storage/media/for/data:/var/www/html/data:rw
    environment:
      POSTGRES_HOST: postgres
      POSTGRES_DB: my_db_name
      POSTGRES_USER: my_db_user
      POSTGRES_PASSWORD: 'db_password'
    depends_on:
      - postgres

  postgres:
    image: postgres:11-alpine
    container_name: 'postgres'
    restart: unless-stopped
    volumes:
      - ./postgresql_data:/var/lib/postgresql/data

Backups

Backups are carried out by BorgBackup using this backup script inspired by their Automating backups article.

This script supports adding a .nobackup file to a directory to avoid backing it up.

Creating a new Borg backup

First, create the repository. This command will prompt you for a passphrase to encrypt the backup with.

borg init --encryption=repokey /path/to/repo.borg

Next create the cron jobs with sudo crontab -e. They might look something like this to run a backup every night at 3AM.

0 3 * * * export BORG_PASSPHRASE=password; /path/to/backup.sh /path/to/repo.borg /path/to/dir

Backblaze B2

At the time of writing I let my Synology NAS device backup the borg repos to Backblaze B2 with its "Cloud Sync" package. In the future I hope to use rclone to achieve this on the server itself rather than relying on the NAS software.