Skip to content

gander-tools/n8n-backup

Repository files navigation

n8n-backup

TDD Bun TypeScript Claude Code License: GPL-3.0 Test Coverage

CLI utility for full backup and restore of n8n workflows, credentials, and tags via REST API

A modern, type-safe CLI tool built with Bun and TypeScript that enables comprehensive backup and restore operations for n8n automation workflows. All backups are versioned and stored in PocketBase with full audit trails.

✨ Features

  • πŸ”„ Full Backup & Restore - Complete snapshot of workflows, credentials, and tags
  • πŸ“¦ PocketBase Storage - Versioned backups with strict audit trails
  • πŸ” Profile Management - Multiple n8n instances with encrypted credentials
  • πŸ“Š Detailed Reporting - Per-object status tracking and comprehensive metrics
  • βœ… Version Validation - Strict n8n version compatibility checks
  • πŸ›‘οΈ Error Resilience - Never fails mid-operation, always reports issues
  • πŸ§ͺ Test-Driven Development - 80%+ test coverage with TDD methodology

πŸš€ Quick Start

Prerequisites

  • Bun >= 1.3 (install)
  • n8n instance with API access
  • PocketBase for backup storage

Installation

# Install globally via bun
bun install -g @gander-tools/n8n-backup

# Or use with bunx (no installation required)
bunx @gander-tools/n8n-backup

Basic Usage

# Backup workflows from default profile
n8n-backup backup

# Restore from specific version
n8n-backup restore <version_id>

# Sync between profiles
n8n-backup sync --source prod --target staging

# List available profiles
n8n-backup profiles list

πŸ“‹ Commands

n8n-backup backup

Creates a full snapshot of workflows, credentials, and tags from n8n via REST API.

Options:

  • --profile <name> - Profile to use (default: default profile)
  • --output <dir> - Output directory for reports
  • --verbose - Enable detailed logging

Output:

  • New version record in PocketBase
  • Per-object reports (workflow_report, credential_report, tag_report)
  • Audit record with full operation metadata

n8n-backup restore <version_id>

Restores data from a specific backup version to target n8n instance.

Requirements:

  • Exact minor version match between source and target n8n
  • If version mismatch: operation aborts with no changes

Options:

  • --profile <name> - Target profile
  • --dry-run - Preview changes without applying

Behavior:

  • Always runs in ignore-errors mode
  • Skipped/errored objects are reported
  • Never fails hard mid-operation

n8n-backup sync

Performs backup from source and restore to target as a single operation.

n8n-backup sync --source prod --target staging --backup

Options:

  • --source <profile> - Source profile (authoritative)
  • --target <profile> - Target profile
  • --backup - Create backup before sync

n8n-backup profiles

Manage n8n instance profiles.

# Add new profile
n8n-backup profiles add --name prod --url https://n8n.example.com --api-key KEY

# List profiles
n8n-backup profiles list

# Set default profile
n8n-backup profiles set-default prod

πŸ—οΈ Architecture

Built with clean, layered architecture following TDD principles:

src/
β”œβ”€β”€ commands/       # CLI entry points (backup, restore, sync)
β”œβ”€β”€ services/       # Business logic (api-client, pocketbase-client)
β”œβ”€β”€ types/          # TypeScript definitions
└── utils/          # Helper functions

tests/
β”œβ”€β”€ unit/           # Fast, isolated tests
└── integration/    # Component interaction tests (Docker)

πŸ§ͺ Test-Driven Development

This project strictly follows TDD with the Red-Green-Refactor cycle:

  1. πŸ”΄ RED - Write a failing test
  2. 🟒 GREEN - Write minimal code to pass
  3. πŸ”΅ REFACTOR - Improve and optimize

Coverage Requirements:

  • Minimum: 80% (enforced in CI/CD)
  • Target: 90%+
  • All paths: happy, sad, and edge cases
# Run tests in TDD watch mode
bun test --watch

# Run with coverage report
bun test --coverage

See tests/README.md for detailed testing guide.

πŸ› οΈ Development

Setup

# Clone repository
git clone https://github.com/gander-tools/n8n-backup.git
cd n8n-backup

# Install dependencies
bun install

# Install git hooks (Lefthook)
bun run prepare

Development Workflow

# Run in development mode
bun run dev

# Run tests (TDD mode)
bun test --watch

# Lint and format
bun run lint
bun run format

# Type checking
bun run typecheck

# Run full CI pipeline locally
bun run ci

Code Quality

  • Linter/Formatter: Biome (not ESLint/Prettier)
  • Git Hooks: Lefthook (enforces format, lint, tests)
  • CI/CD: GitHub Actions (lint, format, test, build)

πŸ“Š Data Model

All backups stored in PocketBase with the following structure:

  • versions - Backup metadata, metrics, timestamps
  • workflows - Workflow data + per-object reports
  • credentials - Encrypted credentials + reports
  • tags - Tag data + reports
  • audits - Complete audit trail
  • profiles - n8n instance configurations

Each backup creates a new version with all data linked by version_id.

πŸ” Security

⚠️ Important Disclaimer:

This tool does not include built-in security beyond PocketBase encryption. You are fully responsible for:

  • Securely storing configuration and API keys
  • PocketBase access control and permissions
  • Preventing unauthorized access to backups
  • Data protection compliance (GDPR, etc.)

API keys are stored encrypted in PocketBase, but securing the PocketBase instance itself is your responsibility.

πŸ“¦ Technology Stack

🀝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

Development Requirements:

  • Follow TDD methodology (write tests first!)
  • Maintain 80%+ test coverage
  • Use Biome for linting/formatting
  • Follow conventional commits

πŸ“ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Copyright (C) 2025 Adam GΔ…sowski

πŸ”— Links

πŸ“š Documentation

🎯 Roadmap

Status: Project in planning phase. See ROADMAP.md for complete feature list.

  • MVP: Core backup and restore functionality
  • Profile management system
  • Sync command with merge strategies
  • Selective backup (filter by ID, tags, date)
  • Differential backup (track changes)
  • Advanced output formats (JSON, CI mode)
  • Retention policies and cleanup command
  • Encryption and signing (GPG/KMS)

For detailed implementation plan, see the complete roadmap.

πŸ’¬ Support

If you encounter any issues or have questions:

  1. Check the documentation
  2. Search existing issues
  3. Open a new issue

Built with ❀️ using Test-Driven Development

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •