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.
Running a backup
Section titled “Running a backup”sudo nexus-backupThe script must be run as root. It produces two files in /opt/nexus-backups/:
| File | Contents |
|---|---|
db_YYYYMMDD_HHMMSS.sql.gz | Compressed PostgreSQL dump of the nexus_prod database |
uploads_YYYYMMDD_HHMMSS.tar.gz | Compressed archive of /opt/nexus-data/uploads/ |
The backup directory is created automatically if it doesn’t exist.
How the backup works
Section titled “How the backup works”Database: The script runs pg_dump inside the running database container (nexus-db-1) and pipes the output through gzip:
docker exec nexus-db-1 pg_dump -U nexus nexus_prod | gzip > /opt/nexus-backups/db_TIMESTAMP.sql.gzUploads: The script archives the uploads directory:
tar -czf /opt/nexus-backups/uploads_TIMESTAMP.tar.gz -C /opt/nexus-data uploads/Retention policy
Section titled “Retention policy”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.
Automating backups
Section titled “Automating backups”Schedule nexus-backup with cron to run automatically. To back up daily at 2 AM:
sudo crontab -eAdd:
0 2 * * * /usr/local/bin/nexus-backup >> /var/log/nexus-backup.log 2>&1Restoring from a backup
Section titled “Restoring from a backup”Restoring the database
Section titled “Restoring the database”- Stop the Nexus application container so no writes occur during restore:
cd /opt/nexusdocker compose -f docker-compose.prod.yml stop app- Restore the database dump into the running database container:
gunzip -c /opt/nexus-backups/db_TIMESTAMP.sql.gz | docker exec -i nexus-db-1 psql -U nexus -d nexus_prod- Restart the application:
docker compose -f docker-compose.prod.yml start appRestoring uploads
Section titled “Restoring uploads”tar -xzf /opt/nexus-backups/uploads_TIMESTAMP.tar.gz -C /opt/nexus-dataThis restores into /opt/nexus-data/uploads/, overwriting existing files.
What is not backed up
Section titled “What is not backed up”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 ornexus-update, but consider backing it up if you’ve made local customisations.