Course/Chapter 2/5. Backups, Updates & Maintenance
    beginner
    Chapter 2: Hosting n8n — Self-Hosted vs Cloud

    5. Backups, Updates & Maintenance

    Implement automated backup strategies and safe update procedures.

    10m Lesson 5 of 5

    Keeping your n8n instance healthy requires regular backups and careful updates. A solid maintenance routine prevents data loss and minimizes downtime.

    Backup Strategy

    1. Database backups: Schedule daily PostgreSQL dumps
    2. Workflow exports: Export workflows as JSON via the API
    3. Credential backups: Included in database backups (encrypted)
    4. File system: Back up the ~/.n8n directory for SQLite setups

    Code Examples

    Automated Backup Script
    bash
    #!/bin/bash
    # backup-n8n.sh - Run daily via cron
    
    DATE=$(date +%Y-%m-%d)
    BACKUP_DIR="/backups/n8n"
    
    # Database backup
    docker exec n8n-postgres pg_dump -U n8n n8n > "$BACKUP_DIR/db-$DATE.sql"
    
    # Export all workflows via API
    curl -s -H "X-N8N-API-KEY: $N8N_API_KEY" \
      https://n8n.example.com/api/v1/workflows \
      > "$BACKUP_DIR/workflows-$DATE.json"
    
    # Compress and clean up old backups
    gzip "$BACKUP_DIR/db-$DATE.sql"
    find "$BACKUP_DIR" -mtime +30 -delete
    
    echo "Backup completed: $DATE"
    Safe Update Procedure
    bash
    # 1. Create a backup first!
    ./backup-n8n.sh
    
    # 2. Pull the latest image
    docker compose pull
    
    # 3. Restart with new version
    docker compose up -d
    
    # 4. Check logs for migration issues
    docker compose logs -f n8n

    Pro Tips

    • 💡Always backup before updating — database migrations can occasionally fail
    • 💡Test updates on a staging instance first if you have mission-critical workflows
    • 💡Set up a cron job to run backups daily: 0 2 * * * /path/to/backup-n8n.sh

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What should you always do before updating n8n?

    2. How can you export workflows programmatically?

    Pass the quiz above to unlock lesson completion