⚙️ Automated rsync backup with password auth & alert system

122 views · ⚙️ DevOps & CI/CD

Description

Automated Rsync Backup with Password Auth & Alert System

Overview

This n8n workflow provides automated rsync backup capabilities between servers using password authentication. It automatically installs required dependencies, performs the backup operation from a source server to a target server, and sends status notifications via Telegram and SMS.

Features

Setup Instructions

Prerequisites

  1. n8n Instance: Running n8n with Linux environment
  2. Server Access: SSH access to both source and target servers
  3. Telegram Bot: Created via @BotFather (optional)
  4. Textbelt API Key: For SMS notifications (optional)
  5. Network: Connectivity between n8n, source, and target servers

Server Requirements

Source Server:

Target Server:

Configuration Steps

1. Server Parameters Configuration

Open the Server Parameters node and configure:

Source Server Settings:

Target Server Settings:

Rsync Options:

2. Notification Setup (Optional)

Telegram Configuration:

  1. Create bot via @BotFather on Telegram
  2. Get bot token (format: 1234567890:ABCdefGHIjklMNOpqrsTUVwxyz)
  3. Create notification channel
  4. Add bot as administrator
  5. Get channel ID:
    • Send test message to channel
    • Visit: https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
    • Find "chat":{"id":-100XXXXXXXXXX}

SMS Configuration:

  1. Register at https://textbelt.com
  2. Purchase credits
  3. Obtain API key

Update Notification Node: Edit Process Finish Report --- Telegram & SMS node:

3. Security Considerations

Password Storage:

SSH Security:

Testing

  1. Start with small test folder
  2. Verify network connectivity: ping source_host and ping target_host
  3. Test SSH access manually first
  4. Run workflow with test data
  5. Verify backup completion on target server

How to Use

Automatic Operation

Once activated, the workflow runs automatically:

Manual Execution

  1. Open the workflow in n8n
  2. Click on Manual Trigger node
  3. Click “Execute Workflow”
  4. Monitor execution progress

Scheduled Execution

To automate backups:

  1. Replace Manual Trigger with Schedule Trigger node
  2. Configure schedule (e.g., daily at 2 AM)
  3. Save and activate workflow

Workflow Process

Step 1: Dependency Check

The workflow automatically:

  1. Checks if sshpass is installed locally
  2. Installs if missing (supports apt, yum, dnf, apk)
  3. Checks sshpass on source server
  4. Installs on source if needed (with sudo)

Step 2: Backup Execution

Step 3: Status Reporting

Success Message Format:

[Timestamp] -- SUCCESS :: source_host:/path -> target_host:/path :: [rsync output]

Failure Message Format:

[Timestamp] -- ERROR :: source_host -> target_host :: [exit code] -- [error message]

Rsync Options Guide

Common Options:

Example Configurations:

# Basic backup
-avz

# Mirror with deletion
-avz --delete

# Exclude temporary files
-avz --exclude='*.tmp' --exclude='*.cache'

# Bandwidth limited (1MB/s)
-avz --bwlimit=1000

# Dry run test
-avzn --delete

Monitoring

Execution Logs

Verification

After backup:

  1. SSH to target server
  2. Check folder size: du -sh /target/folder
  3. Verify file count: find /target/folder -type f | wc -l
  4. Compare with source: ls -la /target/folder

Troubleshooting

Connection Issues

“Connection refused” error:

“Permission denied” error:

Installation Failures

“Unsupported package manager”:

“sudo: password required”:

Rsync Errors

“rsync error: some files/attrs were not transferred”:

“No space left on device”:

Notification Issues

No Telegram message:

SMS not received:

Best Practices

Backup Strategy

  1. Test First: Always test with small datasets
  2. Schedule Wisely: Run during low-traffic periods
  3. Monitor Space: Ensure adequate storage on target
  4. Verify Backups: Regularly test restore procedures
  5. Rotate Backups: Implement retention policies

Security

  1. Use Strong Passwords: Complex passwords for all accounts
  2. Limit Permissions: Use dedicated backup users
  3. Network Security: Consider VPN for internet transfers
  4. Audit Access: Log all backup operations
  5. Encrypt Sensitive Data: Consider rsync with encryption

Performance

  1. Compression: Use -z for slow networks
  2. Bandwidth Limits: Prevent network saturation
  3. Incremental Backups: Rsync only transfers changes
  4. Parallel Transfers: Consider multiple workflows for different folders
  5. Off-Peak Hours: Schedule during quiet periods

Advanced Configuration

Multiple Backup Jobs

Create separate workflows for:

Backup Rotation

Implement versioning:

# Add timestamp to target folder
target_folder="/backup/data_$(date +%Y%m%d)"

Pre/Post Scripts

Add nodes for:

Error Handling

Enhance workflow with:

Maintenance

Regular Tasks

Monitoring Metrics

Track:

Recovery Procedures

Restore from Backup

To restore files:

# Reverse the rsync direction
rsync -avz target_server:/backup/folder/ source_server:/restore/location/

Disaster Recovery

  1. Document server configurations
  2. Maintain backup access credentials
  3. Test restore procedures regularly
  4. Keep workflow exports as backup

Support Resources

🔗 Nodes Used

Schedule Trigger

📥 Import

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

📖 Importing guide · 🔑 Credential setup