⚙️ Restore workflows and credentials from remote FTP backup storage

308 views · ⚙️ DevOps & CI/CD

Description

Restore workflows & credentials from FTP - Remote Backup Solution

This n8n template provides a safe and intelligent restore solution for self-hosted n8n instances, allowing you to restore workflows and credentials from FTP remote backups.

Perfect for disaster recovery or migrating between environments, this workflow automatically identifies your most recent FTP backup and provides a manual restore capability that intelligently excludes the current workflow to prevent conflicts. Works seamlessly with date-organized backup folders stored on any FTP/SFTP server.

Good to know

How it works

Restore Process (Manual)

  1. Manual trigger with configurable pinned data options (credentials: true/false, worflows: true/false)
  2. The Init node sets up all necessary paths, timestamps, and configuration variables using your environment settings
  3. The workflow connects to your FTP server and scans for available backup dates
  4. Automatically identifies the most recent backup folder (latest YYYY-MM-DD date)
  5. Creates temporary restore folders on your local server for downloaded files
  6. If restoring credentials:
    • Lists all credential files from FTP backup folder
    • Downloads credential files to temporary local folder
    • Writes files to disk using “Read/Write Files from Disk” node
    • Direct import using n8n’s import command
    • Credentials are imported with their encrypted format intact
  7. If restoring workflows:
    • Lists all workflow JSON files from FTP backup folder
    • Downloads workflow files to temporary local folder
    • Filters out the credentials subfolder to prevent importing it as a workflow
    • Writes workflow files to disk
    • Intelligently excludes the current restore workflow to prevent conflicts
    • Imports all other workflows using n8n’s import command
  8. Optional email notifications provide detailed restore summaries with command outputs
  9. Temporary files remain on server for verification (manual cleanup recommended)

How to use

Prerequisites

Initial Setup

  1. Configure your environment variables:

    • N8N_ADMIN_EMAIL: Your email for notifications (optional)
    • FTP_BACKUP_FOLDER: FTP path where backups are stored (e.g., /n8n-backups)
    • N8N_PROJECTS_DIR: Projects root directory (e.g., /files/n8n-projects-data)
    • GENERIC_TIMEZONE: Your local timezone (e.g., Europe/Paris)
    • N8N_ENCRYPTION_KEY: Required if restoring credentials to a new environment (see dedicated section below)
  2. Create your FTP credential in n8n:

    • Add a new FTP/SFTP credential
    • Configure host, port, username, and password/key
    • Test the connection
  3. Update the Init node:

    • (Optional) Configure your email here: const N8N_ADMIN_EMAIL = $env.N8N_ADMIN_EMAIL || 'youremail@world.com';
    • Set PROJECT_FOLDER_NAME to "Workflow-backups" (or your preferred name)
    • Set FTP_BACKUP_FOLDER to match your FTP backup path (default: /n8n-backups)
    • Set credentials to "n8n-credentials" (or your backup credentials folder name)
    • Set FTPName to a descriptive name for your FTP server (used in notifications)
  4. Configure FTP credentials in nodes:

    • Update the FTP credential in “List Credentials Folders” node
    • Verify all FTP nodes use the same credential
    • Test connection by executing “List Credentials Folders” node
  5. Optional: Configure SMTP for email notifications:

    • Add SMTP credential in n8n
    • Activate “SUCCESS email Credentials” and “SUCCESS email Workflows” nodes
    • Or remove email nodes if not needed

Performing a Restore

  1. Open the workflow and locate the “Start Restore” manual trigger node
  2. Edit the pinned data to choose what to restore:
    {
      "credentials": true,
      "worflows": true
    }
    • credentials: true - Restore credentials from FTP
    • worflows: true - Restore workflows from FTP (note: typo preserved from original)
    • Set both to true to restore everything
  3. Update the node’s notes to reflect your choice (for documentation)
  4. Click “Execute workflow” on the “Start Restore” node
  5. The workflow will:
    • Connect to FTP and find the most recent backup
    • Download selected files to temporary local folders
    • Import credentials and/or workflows
    • Send success email with detailed operation logs
  6. Check the console logs or email for detailed restore summary

Important Notes

Critical: N8N_ENCRYPTION_KEY Configuration

Why this is critical: n8n generates an encryption key automatically on first launch and saves it in the ~/.n8n/config file. However, if this file is lost (for example, due to missing Docker volume persistence), n8n will generate a NEW key, making all previously encrypted credentials inaccessible.

When you need to configure N8N_ENCRYPTION_KEY:

How credentials encryption works:

Solution: Retrieve and configure the encryption key

Step 1: Get the key from your source environment

# Check if the key is defined in environment variables
docker-compose exec n8n printenv N8N_ENCRYPTION_KEY

If this command returns nothing, the key is auto-generated and stored in n8n’s data volume:

# Enter the container
docker-compose exec n8n sh

# Check configuration file
cat /home/node/.n8n/config

# Exit container
exit

Step 2: Configure the key in your target environment

Option A: Using .env file (recommended for security)

# Add to your .env file
N8N_ENCRYPTION_KEY=your_retrieved_key_here

Then reference it in docker-compose.yml:

services:
  n8n:
    environment:
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}

Option B: Directly in docker-compose.yml (less secure)

services:
  n8n:
    environment:
      - N8N_ENCRYPTION_KEY=your_retrieved_key_here

Step 3: Restart n8n

docker-compose restart n8n

Step 4: Now restore your credentials

Only after configuring the encryption key, run the restore workflow with credentials: true.

Best practice for future backups:

Requirements

FTP Server

Existing Backups on FTP

Environment

Credentials

Technical Notes

FTP Connection and Download Process

Smart Workflow Exclusion

Credentials Subfolder Filtering

Timezone Handling

Security

Troubleshooting

Common Issues

  1. FTP connection fails: Verify FTP credentials are correctly configured and server is accessible
  2. No backups found: Ensure the FTP_BACKUP_FOLDER path is correct and contains date-formatted folders (YYYY-MM-DD)
  3. Permission errors: Ensure Docker user has write access to N8N_PROJECTS_DIR for temporary folders
  4. Path not found: Verify all volume mounts in docker-compose.yml match your project folder location
  5. Import fails: Check that backup files are in valid n8n export format
  6. Download errors: Verify FTP path structure matches expected format (date folder / credentials subfolder / files)
  7. Workflow conflicts: The workflow automatically excludes itself, but ensure backup files are properly named
  8. Credentials not restored: Verify the FTP backup contains a n8n-credentials subfolder with credential files
  9. Credentials decrypt error: Ensure N8N_ENCRYPTION_KEY matches the source environment

Error Handling

Version Compatibility


This workflow is designed for FTP/SFTP remote backup restoration. For local disk backups, see the companion workflow “n8n Restore from Disk”.

Works best with backups from: “Automated n8n Workflows & Credentials Backup to Local/Server Disk & FTP”

🔗 Nodes Used

Send Email, FTP, Stop and Error, Filter, Read/Write Files from Disk

📥 Import

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

📖 Importing guide · 🔑 Credential setup