Florent
Workflows by Florent
Random Process Scheduler
# Random Process Scheduler ### Turn predictable automations into human-like activity with random scheduling across easily customisable time slots. Perfect for content publishing with organic scheduling patterns, social media automation, API systems that need to avoid rate limiting, or any automation requiring randomised timing control across multiple periods. All times are configured in local timezone with automatic UTC conversion for technical operations. Features easy slot management with chronological ordering, gap support, and 24-hour window scheduling. ### How to use - Set `schedulerExecutionTime` in **Init** node (match it to **Schedule Trigger** cron) - Define **time slots** with start/end hours and probability values (see below) - Configure **Execute sub-process** with your own workflow ID - Configure SMTP credentials, local time zone and optionally project paths ### Step by Step Configuration Two variables to set in the **Init** node's **"Custom Configuration"** section: **1. When the scheduler runs daily:** ```javascript const schedulerExecutionTime = 1; // 1am (24h clock; must match Schedule Trigger node) ``` **2. Your execution slots:** ```javascript const subprocessTimeSlots = { morning: { start: 6, end: 12, probability: 0.85 }, afternoon: { start: 12, end: 18, probability: 0.85 }, evening: { start: 18, end: 24, probability: 0.5 } }; ``` That's it. Three slots, three probabilities. Add or remove slots, adjust times - it just works. **Real-world example with gaps:** ```javascript const subprocessTimeSlots = { night: { start: 0, end: 2, probability: 0.1 }, // Optional late activity morning: { start: 6, end: 10, probability: 0.85 }, // Gap from 2-6am (no execution) noon: { start: 12, end: 14, probability: 0.85 }, // Gap from 10am-12pm afternoon: { start: 16, end: 18, probability: 0.85 }, // Gap from 2-4pm evening: { start: 20, end: 24, probability: 0.5 } // Gap from 6-8pm }; ``` **3. Configure Execute sub-process with your workflow ID** Your sub-workflow **MUST** start with a **Wait** node and be configured with `{{ $json.executions.relativeDelaySeconds }}` as “Wait Amount”.  **4. Additional Configuration** * SMTP credential * Time zone (**Init** node): `const LOCAL_TIMEZONE = $env.GENERIC_TIMEZONE || 'Europe/Paris';` by default * Project paths (**Init** node): ``` // ⚠️ Your email here • const N8N_ADMIN_EMAIL = $env.N8N_ADMIN_EMAIL || '[email protected]'; // ⚠️ Your projects’ ROOT folder on your mapped server here • const N8N_PROJECTS_DIR = $env.N8N_PROJECTS_DIR || '/files/n8n-projects-data'; // ⚠️ Your project’s folder name here for logging • const PROJECT_FOLDER_NAME = "RPS"; ``` ### Requirements - n8n instance running in Docker with file system access - Volume mapping for persistent storage (e.g., `/local-files:/files`) - **De-activate** Read/Write nodes & Email sends if you do not want to use logging features (file system access optional) - SMTP server for notifications - n8n API credentials for error handling - **Target sub-workflow** with **Wait** node to handle relativeDelaySeconds **IMPORTANT:** Your sub-workflow **MUST** start with a **Wait** node and be configured with `{{ $json.executions.relativeDelaySeconds }}` as “Wait Amount”. ### How it works - **24-Hour Window Algorithm**: Schedules executions from current time until next scheduler run, handling timezone conversions and cross-midnight scenarios - **Automatic Validation**: Checks for overlaps, invalid time ranges, and probability values on every run - **Chronological Processing**: Processes slots in order regardless of how you define them - **Inclusive/Exclusive Boundaries**: 6-12 slot runs from 6:00:00 to 11:59:59 (start inclusive, end exclusive) - **Chained Execution**: Each subprocess receives a relativeDelaySeconds value for sequential execution with calculated intervals - **Comprehensive Monitoring**: Tracks planned vs actual execution times with delay calculations and detailed logging ### Configuration Rules - **No Overlap**: Slots cannot overlap (6-10 and 9-12 is invalid) - **Valid Ranges**: Start 0-23, end 0-24, start < end - **Valid Probability**: 0 to 1 (0.85 = 85% chance) - **Gaps Allowed**: Skip hours completely (e.g., no execution 2-6am) - **Emoji Support**: Use "night", "morning", "noon", "evening" keywords in slot names for visual logs **Use Cases:** - Content publishing with organic scheduling patterns - Social media automation with human-like posting intervals - API systems avoiding rate limits through unpredictable timing - Business hours automation with precise timing control
Restore workflows and credentials from remote FTP backup storage
# 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** - This workflow uses n8n's native import commands (`n8n import:workflow` and `n8n import:credentials`) - Works with date-formatted backup folders (YYYY-MM-DD) stored on FTP servers - The restore process intelligently excludes the current workflow to prevent overwriting itself - Requires FTP/SFTP server access and proper Docker volume configuration - All downloaded files are temporarily stored server-side before import - Compatible with backups created by n8n's export commands and uploaded to FTP - Supports selective restoration: restore only credentials, only workflows, or both ### 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** - Existing n8n backups on FTP server in date-organized folder structure (format: `/ftp-backup-folder/YYYY-MM-DD/`) - Workflow backups as JSON files in the date folder - Credentials backups in subfolder: `/ftp-backup-folder/YYYY-MM-DD/n8n-credentials/` - FTP/SFTP access credentials configured in n8n - For new environments: `N8N_ENCRYPTION_KEY` from source environment (see dedicated section below) **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 || '[email protected]';` - 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: ```json { "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** - The workflow automatically excludes itself during restore to prevent conflicts - Credentials are restored with their encryption intact. If restoring to a new environment, you must configure the `N8N_ENCRYPTION_KEY` from the source environment (see dedicated section below) - Existing workflows/credentials with the same names will be overwritten - Temporary folders are created with date prefix (e.g., `2025-01-15-restore-credentials`) - Test in a non-production environment first if unsure ### 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**: - Restoring to a new n8n instance - When your data directory is not persisted between container recreations - Migrating from one server to another - As a best practice to ensure key persistence across updates **How credentials encryption works**: - Credentials are encrypted with a specific key unique to each n8n instance - This key is auto-generated on first launch and stored in `/home/node/.n8n/config` - When you backup credentials, they remain encrypted but the key is NOT included - If the key file is lost or a new key is generated, restored credentials cannot be decrypted - Setting `N8N_ENCRYPTION_KEY` explicitly ensures the key remains consistent **Solution: Retrieve and configure the encryption key** **Step 1: Get the key from your source environment** ```bash # 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: ```bash # 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)** ```bash # Add to your .env file N8N_ENCRYPTION_KEY=your_retrieved_key_here ``` Then reference it in `docker-compose.yml`: ```yaml services: n8n: environment: - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY} ``` **Option B: Directly in docker-compose.yml (less secure)** ```yaml services: n8n: environment: - N8N_ENCRYPTION_KEY=your_retrieved_key_here ``` **Step 3: Restart n8n** ```bash 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**: - Always save your `N8N_ENCRYPTION_KEY` in a secure location alongside your backups - Consider storing it in a password manager or secure vault - Document it in your disaster recovery procedures ### Requirements **FTP Server** - FTP or SFTP server with existing n8n backups - Read access to backup folder structure - Network connectivity from n8n instance to FTP server **Existing Backups on FTP** - Date-organized backup folders (YYYY-MM-DD format) - Backup files created by n8n's export commands or compatible format - Credentials in subfolder structure: `YYYY-MM-DD/n8n-credentials/` **Environment** - Self-hosted n8n instance (Docker recommended) - Docker volumes mounted with write access to project folder - Access to n8n CLI commands (`n8n import:credentials` and `n8n import:workflow`) - Proper file system permissions for temporary folder creation **Credentials** - FTP/SFTP credential configured in n8n - Optional: SMTP credentials for email notifications ### Technical Notes **FTP Connection and Download Process** - Uses n8n's built-in FTP node for all remote operations - Supports both FTP and SFTP protocols - Downloads files as binary data before writing to disk - Temporary local storage required for import process **Smart Workflow Exclusion** - During workflow restore, the current workflow's name is cleaned and matched against backup files - This prevents the restore workflow from overwriting itself - The exclusion logic handles special characters and spaces in workflow names - A bash command removes the current workflow from the temporary restore folder before import **Credentials Subfolder Filtering** - The "Filter out Credentials sub-folder" node checks for binary data presence - Only items with binary data (actual files) proceed to disk write - Prevents the credentials subfolder from being imported as a workflow **Timezone Handling** - All timestamps use UTC for technical operations - Display times use local timezone for user-friendly readability - FTP backup folder scanning works with YYYY-MM-DD format regardless of timezone **Security** - FTP connections should use SFTP or FTPS for encrypted transmission - Credentials are imported in n8n's encrypted format (encryption preserved) - Temporary files stored in project-specific folders - Consider access controls for who can trigger restore operations - No sensitive credential data is logged in console output ### 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** - "Find Last Backup" node has error output configured to catch FTP listing issues - "Download Workflow Files" node continues on error to handle presence of credentials subfolder - All critical nodes log detailed error information to console - Email notifications include stdout and stderr from import commands ### Version Compatibility - Tested with n8n version 1.113.3 - Compatible with Docker-based n8n installations - Requires n8n CLI access (available in official Docker images) - Works with any FTP/SFTP server (Synology NAS, dedicated FTP servers, cloud FTP services) --- *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"*
Automated workflow & credential restoration system for self-hosted environments
# n8n Restore workflows & credentials from Disk - Self-Hosted Solution ### This n8n template provides a safe and intelligent restore solution for self-hosted n8n instances, allowing you to restore workflows and credentials from disk backups. Perfect for disaster recovery or migrating between environments, this workflow automatically identifies your most recent backup and provides a manual restore capability that intelligently excludes the current workflow to prevent conflicts. Works seamlessly with date-organized backup folders. **Good to know** - This workflow uses n8n's native import commands (`n8n import:workflow` and `n8n import:credentials`) - Works with date-formatted backup folders (YYYY-MM-DD) for easy version identification - The restore process intelligently **excludes the current workflow** to prevent overwriting itself - Requires proper Docker volume configuration and file system permissions - All operations are performed server-side with no external dependencies - Compatible with backups created by n8n's export commands ### How it works **Restore Process (Manual)** 1. Manual trigger with configurable pinned data options (credentials: true/false, workflows: true/false) 2. The Init node sets up all necessary paths, timestamps, and configuration variables using your environment settings 3. The workflow scans your backup folder and automatically identifies the most recent backup 4. If restoring credentials: - Direct import from the latest backup folder using n8n's import command - Credentials are imported with their encrypted format intact 5. If restoring workflows: - Scans the backup folder for all workflow JSON files - Creates a temporary folder with all workflows from the backup - Intelligently excludes the current restore workflow to prevent conflicts - Imports all other workflows using n8n's import command - Cleans up temporary files automatically 6. Optional email notifications provide detailed restore summaries with command outputs ### How to use **Prerequisites** - Existing n8n backups in date-organized folder structure (format: `/backup-folder/YYYY-MM-DD/`) - Workflow backups as JSON files in the date folder - Credentials backups in subfolder: `/backup-folder/YYYY-MM-DD/n8n-credentials/` - For new environments: `N8N_ENCRYPTION_KEY` from source environment (see dedicated section below) **Initial Setup** 1. Configure your environment variables: - `N8N_ADMIN_EMAIL`: Your email for notifications (optional) - `N8N_BACKUP_FOLDER`: Location where your backups are stored (e.g., `/files/n8n-backups`) - `N8N_PROJECTS_DIR`: Projects root directory - `GENERIC_TIMEZONE`: Your local timezone - `N8N_ENCRYPTION_KEY`: Required if restoring credentials to a new environment (see dedicated section below) 2. Update the Init node: - (Optional) Configure your email here: `const N8N_ADMIN_EMAIL = $env.N8N_ADMIN_EMAIL || '[email protected]';` - Set `PROJECT_FOLDER_NAME` to `"Workflow-backups"` (or your preferred name) - Set `credentials` to `"n8n-credentials"` (or your backup credentials folder name) - Verify `BACKUP_FOLDER` path matches where your backups are stored 3. Ensure your Docker setup has: - Mounted volume containing backups (e.g., `/local-files:/files`) - Access to n8n's CLI import commands - Proper file system permissions (read access to backup directories) **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` - Restore credentials - `workflows: true` - Restore workflows - Set both to `true` to restore everything 3. Click "Execute workflow" on the "Start Restore" node to execute the restore 4. The workflow will automatically find the most recent backup (latest date) 5. Check the console logs or optional email for detailed restore summary **Important Notes** - The workflow automatically excludes itself during restore to prevent conflicts - Credentials are restored with their encryption intact. If restoring to a new environment, you must configure the `N8N_ENCRYPTION_KEY` from the source environment (see dedicated section below) - Existing workflows/credentials with the same names will be overwritten - Test in a non-production environment first if unsure ### ⚠ 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**: - Restoring to a new n8n instance - When your data directory is not persisted between container recreations - Migrating from one server to another - As a best practice to ensure key persistence across updates **How credentials encryption works**: - Credentials are encrypted with a specific key unique to each n8n instance - This key is auto-generated on first launch and stored in `/home/node/.n8n/config` - When you backup credentials, they remain encrypted but the key is NOT included - If the key file is lost or a new key is generated, restored credentials cannot be decrypted - Setting `N8N_ENCRYPTION_KEY` explicitly ensures the key remains consistent **Solution: Retrieve and configure the encryption key** **Step 1: Get the key from your source environment** ```bash # 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: ```bash # 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)** ```bash # Add to your .env file N8N_ENCRYPTION_KEY=your_retrieved_key_here ``` Then reference it in `docker-compose.yml`: ```yaml services: n8n: environment: - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY} ``` **Option B: Directly in docker-compose.yml (less secure)** ```yaml services: n8n: environment: - N8N_ENCRYPTION_KEY=your_retrieved_key_here ``` **Step 3: Restart n8n** ```bash 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**: - Always save your `N8N_ENCRYPTION_KEY` in a secure location alongside your backups - Consider storing it in a password manager or secure vault - Document it in your disaster recovery procedures ### Requirements **Existing Backups** - Date-organized backup folders (YYYY-MM-DD format) - Backup files created by n8n's export commands or compatible format **Environment** - Self-hosted n8n instance (Docker recommended) - Docker volumes mounted with access to backup location - Optional: SMTP server configured for email notifications **Credentials (Optional)** - SMTP credentials for email notifications (if using email nodes) ### Technical Notes **Smart Workflow Exclusion** - During workflow restore, the current workflow's name is cleaned and matched against backup files - This prevents the restore workflow from overwriting itself - The exclusion logic handles special characters and spaces in workflow names - A temporary folder is created with all workflows except the current one **Timezone Handling** - All timestamps use UTC for technical operations - Display times use local timezone for user-friendly readability - Backup folder scanning works with YYYY-MM-DD format regardless of timezone **Security** - Credentials are imported in n8n's encrypted format (encryption preserved) - Ensure backup directories have appropriate read permissions - Consider access controls for who can trigger restore operations - No sensitive data is logged in console output ### Troubleshooting **Common Issues** 1. **No backups found**: Verify the `N8N_BACKUP_FOLDER` path is correct and contains date-formatted folders 2. **Permission errors**: Ensure Docker user has read access to backup directories 3. **Path not found**: Verify all volume mounts in `docker-compose.yml` match your backup location 4. **Import fails**: Check that backup files are in valid n8n export format 5. **Workflow conflicts**: The workflow automatically excludes itself, but ensure backup files are properly named 6. **Credentials not restored**: Verify the backup contains a `n8n-credentials` folder with credential files 7. **Credentials decrypt error**: Ensure `N8N_ENCRYPTION_KEY` matches the source environment ### Version Compatibility - Tested with n8n version 1.113.3 - Compatible with Docker-based n8n installations - Requires n8n CLI access (available in official Docker images) --- *This workflow is designed for self-hosted server backup restoration. For FTP/SFTP remote backups, see the companion workflow "n8n Restore from FTP".* *Works best with backups from: "Automated n8n Workflows & Credentials Backup to Local/Server Disk & FTP"*
Complete backup solution for n8n workflows & credentials (local/FTP)
## Automated n8n Workflows & Credentials Backup to Local/Server Disk & FTP Complete backup solution that saves both workflows and credentials to local/server disk with optional FTP upload for off-site redundancy. **What makes this workflow different:** * Backs up workflows AND credentials together * Saves to **local/server** disk (not Git, GitHub, or any cloud services) * Optional **FTP upload** for redundancy (disabled by default) * Comprehensive error handling and email notifications * **Timezone-aware** scheduling * Ready to use with minimal configuration ### How it works **Backup Process (Automated Daily at 4 AM):** 1. **Initialisation** - Sets up timezone-aware timestamps and configurable backup paths for both local/server disk and FTP destinations 2. **Folder Creation** - Creates date-stamped backup directories (YYYY-MM-DD format) on local/server disk 3. **Dual Backup Operations** - Processes credentials and workflows in two separate branches: - **Credentials Branch**: - Exports n8n credentials using the built-in CLI command with backup flag - Lists exported credential files in the credentials folder - Reads each credential file from disk - *Optional*: Uploads to FTP server (disabled by default) - *Optional*: Logs FTP upload results for credentials - **Workflows Branch**: - Retrieves all workflows via n8n API - Cleans workflow names for cross-platform compatibility - Converts workflows to formatted JSON files - Writes files to local/server disk - *Optional*: Uploads to FTP server (disabled by default) - *Optional*: Logs FTP upload results for workflows 4. **Data Aggregation** - Combines all workflow data with binary attachments for comprehensive reporting 5. **Results Merging** - Consolidates credentials FTP logs, workflows FTP logs, and aggregated workflow data 6. **Summary Generation** - Creates detailed backup logs including: - Statistics (file counts, sizes, durations) - Success/failure tracking for local and FTP operations - Error tracking with detailed messages - Timezone-aware timestamps 7. **Notifications** - Sends comprehensive email reports with log files attached and saves execution logs to disk ### How to use **Initial Setup:** 1. **Configure the Init Node** - Open the "Init" node and customize these key parameters in the "Workflow Standard Configuration" section: ```javascript // Admin email for notifications const N8N_ADMIN_EMAIL = $env.N8N_ADMIN_EMAIL || '[email protected]'; // Workflow name (auto-detected) const WORKFLOW_NAME = $workflow.name; // Projects root directory on your server const N8N_PROJECTS_DIR = $env.N8N_PROJECTS_DIR || '/files/n8n-projects-data'; // projects-root-folder/ // └── Your-project-folder-name/ // ├── logs/ // ├── reports/ // ├── ... // └── [other project files] // Project folder name for this backup workflow const PROJECT_FOLDER_NAME = "Workflow-backups"; ``` Then customize these parameters in the "Workflow Custom Configuration" section: ```javascript // Local backup folder (must exist on your server) const BACKUP_FOLDER = $env.N8N_BACKUP_FOLDER || '/files/n8n-backups'; // FTP backup folder (root path on your FTP server) const FTP_BACKUP_FOLDER = $env.N8N_FTP_BACKUP_FOLDER || '/n8n-backups'; // FTP server name for logging (display purposes only) const FTPName = 'Synology NAS 2To'; ``` These variables can also be set as environment variables in your n8n configuration. 2. **Set Up Credentials:** - Configure n8n API credentials for the "Fetch Workflows" node - Configure SMTP credentials for email notifications - *Optional*: Configure FTP credentials if you want to enable off-site backups 3. **Configure Backup Folder:** - Ensure the backup folder path exists on your server - Verify proper write permissions for the n8n process - If running in Docker, ensure volume mapping is correctly configured 4. **Customize Email Settings:** - Update the "Send email" node with your recipient email address or your "N8N_ADMIN_EMAIL" environment value - Adjust email subject and body text as needed **Enabling FTP Upload (Optional):** By default, FTP upload nodes are disabled for easier setup. To enable off-site FTP backups: 1. **Simply activate these 4 nodes** (no other changes needed): - "Upload Credentials To FTP" - "FTP Logger (credentials)" - "Upload Workflows To FTP" - "FTP Logger (workflows)" 2. **Configure FTP credentials** in the two upload nodes 3. The workflow will automatically handle FTP operations and include upload status in reports ### Requirements - n8n API credentials (for workflow fetching) - SMTP server configuration (for email notifications) - Adequate disk space for local backup storage - Proper file system permissions for backup folder access - Docker environment with volume mapping (if running n8n in Docker) - *Optional*: FTP server access and credentials (for off-site backups) ### Good to know - **Security**: Credentials are exported using n8n's secure backup format - actual credential values are not exposed in plain text - **Timezone Handling**: All timestamps respect configured timezone settings (defaults to Europe/Paris, configurable in Init node) - **File Naming**: Automatic sanitization ensures backup files work across different operating systems (removes forbidden characters, limits length to 180 characters) - **FTP Upload**: Disabled by default for easier setup - simply activate 4 nodes to enable off-site backups without any code changes - **Connection Resilience**: FTP operations include error handling for timeout and connection issues without failing the entire backup - **Graceful Degradation**: If FTP nodes are disabled, the workflow completes successfully with local backups only and indicates FTP status in logs - **Error Handling**: Comprehensive error catching with detailed logging and email notifications - **Dual Logging**: Creates both JSON logs (for programmatic parsing) and plain text logs (for human readability) - **Storage**: Individual workflow JSON files allow for selective restore and easier version control integration - **Scalability**: Handles any number of workflows efficiently with detailed progress tracking --- *This automated backup workflow saves your n8n data to both local disk and FTP server. To restore your backups, use:* - [*"n8n Restore from Disk - Self-Hosted Solution" for local/server disk restores*](https://n8n.io/workflows/9154-automated-workflow-and-credential-restoration-system-for-self-hosted-environments/) - [*"n8n Restore from FTP - Remote Backup Solution" for FTP remote restores*](https://n8n.io/workflows/9156-restore-workflows-and-credentials-from-remote-ftp-backup-storage/)