Skip to content

Modern self-hosted database backup management system with automated scheduling, REST API, webhooks, and Docker support. Supports MySQL, PostgreSQL, and MongoDB.

License

Notifications You must be signed in to change notification settings

emirhannaneli/simple-backup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Simple Backup

Simple Backup Logo

A modern, web-based database backup management system built with Next.js 14+, TypeScript, and Prisma. Simple Backup allows you to configure database connections, schedule automated backups, manage backup files, and integrate with external systems via API keys and webhooks.

Next.js TypeScript Prisma License

✨ Features

πŸ—„οΈ Database Support

  • MySQL - Full support for MySQL/MariaDB databases
  • PostgreSQL - Complete PostgreSQL backup capabilities
  • MongoDB - MongoDB database backup support
  • Redis - RDB snapshot backup support
  • Cassandra - Snapshot backup support
  • Elasticsearch - Snapshot backup via REST API
  • InfluxDB - Influx backup support
  • Neo4j - Database dump support
  • SQLite - File-based backup support
  • H2 - Script/export backup support

βš™οΈ Core Functionality

  • Multiple Datasources - Manage multiple database connections
  • Automated Scheduling - Cron-based job scheduling for regular backups
  • Manual Triggers - Run backups on-demand via UI or API
  • Backup Management - View, download, and manage backup files
  • Connection Testing - Test database connections before creating jobs

πŸ” Security

  • User Authentication - JWT-based authentication with HTTP-only cookies
  • Password Encryption - AES-256-GCM encryption for database passwords
  • API Key Management - Generate and manage API keys for programmatic access
  • Role-Based Access - Admin and User roles

πŸ”” Integrations

  • Webhooks - Configure webhooks for job success/failure events
  • REST API - Complete REST API for all operations
  • API Documentation - Built-in API documentation page

🎨 User Interface

  • Modern UI - Built with Shadcn/UI and Tailwind CSS
  • Dark/Light Mode - Theme support
  • Responsive Design - Works on desktop and mobile devices
  • Real-time Updates - Live status updates for jobs and backups

🐳 Deployment

  • Docker Support - Ready-to-use Dockerfile and docker-compose.yml
  • Docker Secrets - Secure secret management with Docker secrets
  • Production Ready - Optimized for production deployments

πŸš€ Quick Start

Prerequisites

  • Node.js 20+ or Bun

  • Database client tools installed (depending on which databases you want to backup):

    • MySQL: mysql and mysqldump
    • PostgreSQL: psql and pg_dump
    • MongoDB: mongosh and mongodump
    • Redis: redis-cli
    • Cassandra: cqlsh and nodetool
    • Elasticsearch: curl (REST API)
    • InfluxDB: influx CLI
    • Neo4j: cypher-shell and neo4j-admin
    • SQLite: sqlite3
    • H2: h2.jar (Java required)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/simple-backup.git
    cd simple-backup
  2. Install dependencies

    bun install
    # or
    npm install
  3. Set up environment variables

    cp .env.example .env

    Edit .env and set:

    DATABASE_URL="file:./prisma/system.db"
    JWT_SECRET="your-super-secret-jwt-key-min-32-chars"
    ENCRYPTION_KEY="your-super-secret-encryption-key-32-chars"
    BACKUP_BASE_PATH="./backups"
  4. Initialize the database

    bun run prisma:generate
    bun run prisma:migrate
    bun run prisma:seed
  5. Start the development server

    bun run dev
  6. Access the application

    • Open http://localhost:3001
    • Login with default credentials: admin / admin
    • Important: Change the default password after first login!

🐳 Docker Deployment

Quick Start with Docker

  1. Create secret files

    mkdir -p secrets
    echo "file:/data/system.db" > secrets/DATABASE_URL
    echo "your-jwt-secret" > secrets/JWT_SECRET
    echo "your-encryption-key" > secrets/ENCRYPTION_KEY
    echo "/data/backups" > secrets/BACKUP_BASE_PATH
  2. Start with Docker Compose

    docker-compose up -d
  3. Access the application

Note: You can also use *_FILE environment variables to specify custom file paths for secrets:

  • DATABASE_URL_FILE=/custom/path/db-url
  • JWT_SECRET_FILE=/custom/path/jwt-secret
  • ENCRYPTION_KEY_FILE=/custom/path/encryption-key
  • BACKUP_BASE_PATH_FILE=/custom/path/backup-path

The priority order is: *_FILE env var > /run/secrets/* > direct env var > default.

For detailed Docker setup instructions, see Docker Documentation.

πŸ“– Usage Guide

Simple Backup Dashboard

Simple Backup Dashboard

Creating a Datasource

  1. Navigate to Datasources in the sidebar

  2. Click Create Datasource

  3. Fill in the connection details:

    • Name: A friendly name for this connection
    • Database Type: Select from MySQL, PostgreSQL, MongoDB, Redis, Cassandra, Elasticsearch, InfluxDB, Neo4j, SQLite, or H2
    • Host: Database server hostname or IP (not required for SQLite)
    • Port: Database server port (defaults provided, not required for SQLite)
    • Username: Database username (optional for Redis, not required for SQLite)
    • Password: Database password (optional for Redis, not required for SQLite)
    • Database Name/Path: Target database name, file path (for SQLite/H2), or JDBC URL (for H2)
  4. Click Test Connection to verify the connection

  5. Click Create to save

Creating a Backup Job

  1. Navigate to Jobs in the sidebar

  2. Click Create Job

  3. Configure the job:

    • Title: A descriptive name for the job
    • Datasource: Select a configured datasource
    • Cron Expression: Schedule using cron syntax (helper available)
    • Destination Path: Where to save backups
    • Active: Enable/disable the job
  4. Click Create to save

Running a Backup Manually

  1. Go to Jobs page

  2. Find the job you want to run

  3. Click the Run button (play icon)

  4. Monitor the status in the Backups page

Managing Backups

  1. Navigate to Backups in the sidebar

  2. View all backup files with their status

  3. Download backups using the download button

  4. Delete old backups as needed

API Access

  1. Navigate to API Keys in the sidebar

  2. Click Create API Key

  3. Copy the generated API key (shown only once!)

  4. Use the API key in the X-API-Key header for API requests

See the built-in API Docs page for complete API documentation.

πŸ”Œ API Documentation

The application includes a comprehensive API documentation page accessible at /api-docs when logged in.

Authentication

Session-based (Web UI)

  • Login via /api/auth/login with username and password
  • Session stored in HTTP-only cookie

API Key-based

  • Include X-API-Key header in API requests
  • API keys can be created in the UI

Example API Usage

# Create a MySQL datasource
curl -X POST http://localhost:3001/api/datasources \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production MySQL",
    "type": "MYSQL",
    "host": "localhost",
    "port": 3306,
    "username": "root",
    "password": "password",
    "databaseName": "mydb"
  }'

# Create a Redis datasource (username/password optional)
curl -X POST http://localhost:3001/api/datasources \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Redis Cache",
    "type": "REDIS",
    "host": "localhost",
    "port": 6379,
    "databaseName": "0"
  }'

# Create a SQLite datasource (host/port not required)
curl -X POST http://localhost:3001/api/datasources \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Local SQLite",
    "type": "SQLITE",
    "databaseName": "/path/to/database.db"
  }'

# Trigger a backup job
curl -X POST http://localhost:3001/api/trigger/job-id \
  -H "X-API-Key: your-api-key"

# List backups
curl http://localhost:3001/api/backups \
  -H "X-API-Key: your-api-key"

πŸ—οΈ Architecture

Tech Stack

  • Framework: Next.js 14+ (App Router)
  • Language: TypeScript
  • Database: SQLite (via Prisma)
  • ORM: Prisma
  • Styling: Tailwind CSS
  • UI Components: Shadcn/UI
  • Authentication: JWT (jose) + Argon2
  • Scheduling: node-schedule
  • Validation: Zod

Project Structure

simple-backup/
β”œβ”€β”€ app/                    # Next.js app directory
β”‚   β”œβ”€β”€ (dashboard)/        # Dashboard routes
β”‚   β”œβ”€β”€ api/                # API routes
β”‚   β”œβ”€β”€ login/              # Login page
β”‚   └── layout.tsx          # Root layout
β”œβ”€β”€ components/             # React components
β”‚   β”œβ”€β”€ ui/                 # Shadcn/UI components
β”‚   └── ...                 # Feature components
β”œβ”€β”€ lib/                    # Utility libraries
β”‚   β”œβ”€β”€ auth.ts             # Authentication
β”‚   β”œβ”€β”€ backup-service.ts   # Backup execution
β”‚   β”œβ”€β”€ scheduler.ts        # Job scheduling
β”‚   β”œβ”€β”€ database-commands.ts # DB command builders
β”‚   └── ...                 # Other utilities
β”œβ”€β”€ prisma/                 # Prisma schema and migrations
β”œβ”€β”€ public/                 # Static assets
└── secrets/                # Docker secrets (gitignored)

Key Components

  • Backup Service: Executes database backups using native tools

  • Scheduler: Manages cron job scheduling

  • API Routes: RESTful API endpoints

  • Middleware: Authentication and authorization

  • UI Components: Reusable React components

πŸ”’ Security

Password Storage

  • Database passwords are encrypted using AES-256-GCM

  • Each encryption uses a unique salt

  • Encryption key stored securely (use Docker secrets in production)

Authentication

  • JWT tokens with 7-day expiration

  • HTTP-only cookies for web sessions

  • API keys with prefix-based validation

Best Practices

  • Always use strong secrets in production

  • Rotate API keys regularly

  • Use HTTPS in production

  • Keep database client tools updated

πŸ§ͺ Development

Available Scripts

# Development
bun run dev          # Start development server (port 3001)

# Production
bun run build        # Build for production
bun run start        # Start production server

# Database
bun run prisma:generate   # Generate Prisma Client
bun run prisma:migrate    # Run migrations
bun run prisma:seed      # Seed database

# Linting
bun run lint         # Run ESLint

Environment Variables

Variable Description Default
DATABASE_URL SQLite database path file:./prisma/system.db
JWT_SECRET JWT signing secret (required in production)
ENCRYPTION_KEY Encryption key for passwords (required in production)
BACKUP_BASE_PATH Base path for backup files ./backups (local), /data/backups (Docker)
NEXT_PUBLIC_APP_URL Public app URL http://localhost:80 (Docker), http://localhost:3001 (local dev)

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“š Documentation

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ› Issues

If you encounter any issues or have feature requests, please open an issue on GitHub.

πŸ™ Acknowledgments

πŸ“§ Support

For support, please open an issue on GitHub or contact the maintainers.


Note: This is a self-hosted solution. Make sure to:

  • Use strong secrets in production
  • Set up proper backups for the application database
  • Configure firewall rules appropriately
  • Keep all dependencies updated
  • Monitor disk space for backup storage

About

Modern self-hosted database backup management system with automated scheduling, REST API, webhooks, and Docker support. Supports MySQL, PostgreSQL, and MongoDB.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages