⚙️ Back up databases and files to Box with Mailgun email notifications

22 views · ⚙️ DevOps & CI/CD

Description

Scheduled Backup Automation – Mailgun & Box

This workflow automatically schedules, packages, and uploads backups of your databases, files, or configuration exports to Box cloud storage, then sends a completion email via Mailgun. It is ideal for small-to-medium businesses or solo developers who want hands-off, verifiable backups without writing custom scripts.

Pre-conditions/Requirements

Prerequisites

Required Credentials

Specific Setup Requirements

VariableExamplePurpose
BOX_FOLDER_ID1234567890ID of the Box folder that stores backups
MAILGUN_DOMAINmg.example.comMailgun domain used for sending email
MAILGUN_FROMBackups <backup@mg.example.com>“From” address in status emails
NOTIFY_EMAILadmin@example.comRecipient of backup status emails

How it works

This workflow automatically schedules, packages, and uploads backups of your databases, files, or configuration exports to Box cloud storage, then sends a completion email via Mailgun. It is ideal for small-to-medium businesses or solo developers who want hands-off, verifiable backups without writing custom scripts.

Key Steps:

Set up steps

Setup Time: 15-20 minutes

  1. Clone or import the workflow JSON into your n8n instance.
  2. Create credentials:
    • Box OAuth2: paste Client ID, Client Secret, perform OAuth handshake.
    • Mailgun API: add Private API key and domain.
  3. Update environment variables (BOX_FOLDER_ID, MAILGUN_DOMAIN, etc.) or edit the relevant Set node.
  4. Modify the Code node to run your specific backup command, e.g.:
    pg_dump -U $DB_USER -h $DB_HOST $DB_NAME > /tmp/db_backup.sql
    tar -czf /tmp/full_backup_{{new Date().toISOString()}}.tar.gz /etc/nginx /var/www /tmp/db_backup.sql
  5. Set the CRON schedule inside the Webhook node (or replace with a Cron node) to your desired frequency (daily, weekly, etc.).
  6. Execute once manually to verify the Box upload and email notification.
  7. Enable the workflow.

Node Descriptions

Core Workflow Nodes:

Data Flow:

  1. Webhook/CronCodeMove Binary DataSetSplit In BatchesBoxHTTP RequestIfMailgun

Customization Examples

Add Retention Policy (Auto-delete old backups)

// In a Code node before upload
const retentionDays = 30;
const cutoff = Date.now() - retentionDays * 24*60*60*1000;

items = items.filter(item => {
  return item.json.modifiedAt > cutoff; // keep only recent files
});
return items;

Parallel Upload to S3

// Duplicate the Box node, replace with AWS S3 node
// Use Merge node to combine results before the HTTP Request verification

Data Output Format

The workflow outputs structured JSON data:

{
  "fileName": "full_backup_2023-10-31T00-00-00Z.tar.gz",
  "boxFileId": "9876543210",
  "uploadStatus": "success",
  "timestamp": "2023-10-31T00:05:12Z",
  "emailNotification": "sent"
}

Troubleshooting

Common Issues

  1. “Invalid Box Folder ID” – Verify BOX_FOLDER_ID and ensure the OAuth user has write permissions.
  2. Mailgun 401 Unauthorized – Check that you used the Private API key and the domain is verified.
  3. Backup file too large – Enable chunked upload in Box node or increase client_max_body_size on reverse proxy.

Performance Tips

Pro Tips:


This is a community workflow template provided “as-is” without warranty. Adapt and test in a safe environment before using in production.

🔗 Nodes Used

HTTP Request, Mailgun, Webhook, Convert to/from binary data, Box

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup