DEV Community

Cover image for Database Backup and Restore in NEXUS AI: A Complete Guide
Saif Ali
Saif Ali

Posted on • Originally published at nexusai.run on

Database Backup and Restore in NEXUS AI: A Complete Guide

Every production deployment needs a data recovery plan. NEXUS AI ships built-in backup and restore for all four supported database engines: PostgreSQL, MySQL, MongoDB, and Redis. This guide covers three ways to use it: the dashboard, the CLI, and direct API calls.

What gets backed up

When you deploy a full-stack application on NEXUS AI with a database service, the platform manages the database container alongside your app in a private Docker network. Backups capture a consistent snapshot of that data:

  • PostgreSQL — uses pg_dump in custom format (.dump)
  • MySQL — uses mysqldump SQL export (.sql)
  • MongoDB — uses mongodump compressed archive (.archive)
  • Redis — uses the native RDB snapshot (.rdb)

All backup files are stored server-side and tracked in the NEXUS AI platform. Each backup record shows the engine type, file size, status, and creation time.

Using the CLI

Install or update the CLI:

npm install -g nexusapp-cli
nexus --version
Enter fullscreen mode Exit fullscreen mode

Create a backup

nexus db backup <service-id>
Enter fullscreen mode Exit fullscreen mode

The command streams progress and prints a summary when done:

✔ Backup created
  ID:      3f8a1c2d-...
  Type:    postgresql
  Size:    4.2 MB
  Created: just now
Enter fullscreen mode Exit fullscreen mode

Find your service-id by running nexus deploy status <deployment-name> and looking at the attached services table.

List backups

nexus db backups <service-id>
Enter fullscreen mode Exit fullscreen mode

Output:

ID                                    TYPE          SIZE      STATUS     CREATED
3f8a1c2d-...                          postgresql    4.2 MB    completed  2m ago
1a2b3c4e-...                          postgresql    3.9 MB    completed  1d ago
Enter fullscreen mode Exit fullscreen mode

Restore from a backup

nexus db restore <service-id> <backup-id>
Enter fullscreen mode Exit fullscreen mode

You will be prompted to confirm before the restore runs — this overwrites current data. Use --yes to skip the prompt in scripts:

nexus db restore <service-id> <backup-id> --yes
Enter fullscreen mode Exit fullscreen mode

Restoring PostgreSQL and MySQL replays all data with --clean / --drop semantics so the target schema is wiped before the restore. MongoDB uses --drop per collection. Redis stops the container, swaps the RDB file, and restarts — expect a few seconds of downtime.

Delete a backup

nexus db backup-delete <service-id> <backup-id>
Enter fullscreen mode Exit fullscreen mode

This removes both the file on disk and the tracking record. Deletion is permanent.

Enable daily automated backups

nexus db backup-schedule <service-id> --enable
Enter fullscreen mode Exit fullscreen mode

Once enabled, NEXUS AI runs a backup every 24 hours automatically. To disable:

nexus db backup-schedule <service-id> --disable
Enter fullscreen mode Exit fullscreen mode

Using the REST API

All backup operations are also available over HTTP. Authenticate with a Bearer token from nexus auth token create.

Create a backup

curl -X POST https://nexusai.run/api/deployment-services/<service-id>/backup \
  -H "Authorization: Bearer $NEXUS_TOKEN"
Enter fullscreen mode Exit fullscreen mode

List backups

curl https://nexusai.run/api/deployment-services/<service-id>/backups \
  -H "Authorization: Bearer $NEXUS_TOKEN"
Enter fullscreen mode Exit fullscreen mode

Restore

curl -X POST https://nexusai.run/api/deployment-services/<service-id>/restore \
  -H "Authorization: Bearer $NEXUS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"backupId":"<backup-id>"}'
Enter fullscreen mode Exit fullscreen mode

Toggle scheduled backups

curl -X PATCH https://nexusai.run/api/deployment-services/<service-id>/backup/schedule \
  -H "Authorization: Bearer $NEXUS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"enabled":true}'
Enter fullscreen mode Exit fullscreen mode

Disaster recovery playbook

Here is a practical runbook for restoring after data loss:

1. List your recent backups

nexus db backups <service-id> --json | jq '.[0:3]'
Enter fullscreen mode Exit fullscreen mode

Pick the most recent backup with "status": "completed".

2. Verify the backup exists

nexus db backups <service-id> | grep <backup-id>
Enter fullscreen mode Exit fullscreen mode

3. Run the restore

nexus db restore <service-id> <backup-id> --yes
Enter fullscreen mode Exit fullscreen mode

4. Verify your application

Check your app is healthy after the restore:

nexus deploy status <deployment-name>
Enter fullscreen mode Exit fullscreen mode

Watch for the health check to return healthy before routing traffic back.

Setting up automated backups (recommended)

For any production database, enable daily backups immediately after deploy:

# Deploy your app
nexus deploy source https://github.com/your/repo --name my-app

# Find the database service ID
nexus deploy status my-app --json | jq '.services[] | select(.serviceType == "postgresql") | .id'

# Enable daily backups
nexus db backup-schedule <service-id> --enable
Enter fullscreen mode Exit fullscreen mode

NEXUS AI runs the backup job every 24 hours. The last backup time is visible in nexus deploy status.

What to do before a risky migration

Run a manual backup before any schema migration or destructive operation:

nexus db backup <service-id>
Enter fullscreen mode Exit fullscreen mode

Save the backup ID, run your migration, and restore from that ID if anything goes wrong. This gives you a clean rollback path without downtime planning.

Engine-specific notes

PostgreSQL
Backups use pg_dump -F c (custom format). Restores use pg_restore --clean --if-exists, which drops and recreates all objects. The target database must exist.

MySQL
Backups are plain SQL dumps. Restores pipe the SQL directly into mysql. All tables in the target database are replaced.

MongoDB
Backups use mongodump with authentication against the admin database. Restores use mongorestore --drop, which removes each existing collection before importing. Only the named database is restored.

Redis
Redis backups trigger a BGSAVE and copy the resulting dump.rdb file. Restores stop the container, replace the RDB, and restart. There is a brief connection interruption during restore.

Limitations

  • Backup files are stored on the NEXUS AI server. For off-site copies, download them via the dashboard or export endpoints.
  • Backups reflect the state at the moment pg_dump / mysqldump / mongodump runs. In-flight transactions may not be captured.
  • Redis BGSAVE is non-blocking but the saved RDB may be up to a few seconds behind the latest write.
  • Restoring to a different service ID or engine type is not supported. Restore targets the same container the backup came from.

Top comments (0)