Skip to content

Backups

The nexus-backup script is installed to /usr/local/bin/nexus-backup by the installer. It snapshots both the PostgreSQL database and the uploads directory in one command.


Terminal window
sudo nexus-backup

The script must be run as root. It produces two files in /opt/nexus-backups/:

FileContents
db_YYYYMMDD_HHMMSS.sql.gzCompressed PostgreSQL dump of the nexus_prod database
uploads_YYYYMMDD_HHMMSS.tar.gzCompressed archive of /opt/nexus-data/uploads/

The backup directory is created automatically if it doesn’t exist.


Database: The script runs pg_dump inside the running database container (nexus-db-1) and pipes the output through gzip:

Terminal window
docker exec nexus-db-1 pg_dump -U nexus nexus_prod | gzip > /opt/nexus-backups/db_TIMESTAMP.sql.gz

Uploads: The script archives the uploads directory:

Terminal window
tar -czf /opt/nexus-backups/uploads_TIMESTAMP.tar.gz -C /opt/nexus-data uploads/

The script keeps the 10 most recent backups of each type and automatically deletes older ones. With daily backups, this gives 10 days of retention.


Schedule nexus-backup with cron to run automatically. To back up daily at 2 AM:

Terminal window
sudo crontab -e

Add:

0 2 * * * /usr/local/bin/nexus-backup >> /var/log/nexus-backup.log 2>&1

  1. Stop the Nexus application container so no writes occur during restore:
Terminal window
cd /opt/nexus
docker compose -f docker-compose.prod.yml stop app
  1. Restore the database dump into the running database container:
Terminal window
gunzip -c /opt/nexus-backups/db_TIMESTAMP.sql.gz | docker exec -i nexus-db-1 psql -U nexus -d nexus_prod
  1. Restart the application:
Terminal window
docker compose -f docker-compose.prod.yml start app
Terminal window
tar -xzf /opt/nexus-backups/uploads_TIMESTAMP.tar.gz -C /opt/nexus-data

This restores into /opt/nexus-data/uploads/, overwriting existing files.


nexus-backup covers the database and user-uploaded files. It does not back up:

  • /opt/nexus/.env — back this up manually and store it securely. It contains all secrets and is irreplaceable.
  • /opt/nexus/Caddyfile — back this up if you’ve added custom site blocks.
  • The Nexus application code at /opt/nexus/ — this is recreatable by running the installer or nexus-update, but consider backing it up if you’ve made local customisations.