Updated for nself v0.4.8
Learn how to backup and restore your nself database with automatic versioning, point-in-time recovery, and safe rollback procedures.
nself deploy rollback to revert deploymentsnself env export to backup environment configurationsnself provides comprehensive backup and restore capabilities to protect your data and enable safe database operations. Every migration automatically creates a backup, and you can create manual backups at any time.
Backups are automatically created during:
nself db updatenself db runnself deploy operationsBackups are stored in bin/dbsyncs/ with timestamps:
bin/dbsyncs/
├── 2026-01-24_14-30-00/
│ ├── backup.sql
│ └── metadata.json
└── 2026-01-24_15-45-30/
├── backup.sql
└── metadata.jsonCreate a manual backup at any time:
# Create a timestamped backup
nself db backup
# Backup with custom name
nself db backup --name before-major-changeQuickly revert to the most recent backup:
# Restore to last backup
nself db revert
# This is useful after a failed migration or incorrect data changeRestore from a specific backup file:
# List available backups
ls bin/dbsyncs/
# Restore from specific backup
nself db restore bin/dbsyncs/2025-08-06_14-30-00/backup.sqlCheck your database and backup status:
# View database status
nself db status
# Example output:
# Database Status
# Schema file: schema.dbml
# Hash: b4dc5d616f59...
# Migrations: 1
# Latest migrations:
# - 1_init
# Backups: 3
# PostgreSQL: RunningBackup and restore environment configurations:
# Export environment configuration
nself env export staging --output staging-env.tar.gz
# Import environment configuration
nself env import staging-env.tar.gz
# This includes:
# - .env file
# - .env.secrets file (if exists)
# - server.json (if exists)Roll back to previous deployment:
# Rollback if deployment fails
nself deploy rollback
# View deployment history
nself deploy logsFor production environments:
# Set up automated daily backups via cron
0 2 * * * cd /path/to/project && nself db backup --name "daily-$(date +%Y%m%d)"
# Keep only last 30 backups
0 3 * * * find bin/dbsyncs -type d -mtime +30 -exec rm -rf {} +
# Before major deployments, create named backup
nself db backup --name "pre-deploy-v1.2.0"# Fix permissions
chmod 755 bin/dbsyncs
chown -R $(whoami) bin/dbsyncs# Ensure PostgreSQL is running
nself start postgres
# Wait for PostgreSQL to be ready
sleep 5
# Retry restore
nself db revert