Skip to content

rs-pro/rsbackup

Repository files navigation

rsbackup

A modern restic wrapper for database and directory backups with legacy rbackup compatibility.

Features

  • Legacy rbackup compatibility: Supports existing YAML configuration files
  • Database backups: MySQL, PostgreSQL, MongoDB with native dump tools
  • Docker support: Backup from Docker containers and Compose services
  • Directory backups: File and folder backup with include/exclude patterns
  • Shell commands: Custom backup scripts and commands
  • Modern CLI: Built with Cobra for better UX
  • Restic integration: Uses restic as the underlying backup system

Installation

go install github.com/rs-pro/rsbackup/cmd/rsbackup@latest

Or build from source:

git clone https://github.com/rs-pro/rsbackup.git
cd rsbackup
go build -o rsbackup cmd/rsbackup/main.go

Quick Start

  1. Install restic (required dependency):
# Ubuntu/Debian
apt install restic

# macOS
brew install restic

# Or download from https://restic.net/
  1. Initialize a restic repository:
restic init --repo /path/to/backup/repo
  1. Create a backup configuration file (see examples/):
- type: dir
  path: /home/user/documents
  exclude:
    - "*.tmp"

- type: db
  activerecord:
    adapter: postgresql
    database: myapp
    username: postgres
    password: secret
  1. Run backup:
rsbackup backup --repository /path/to/backup/repo --password mypassword config.yml

Configuration

rsbackup supports both legacy rbackup format and modern configuration:

Legacy Format (rbackup compatible)

- type: dir
  path: /data/app
  include: ["uploads"]
  exclude: [".git", "*.log"]

- type: db
  activerecord:
    adapter: mysql2
    database: myapp
    host: localhost
    username: user
    password: pass

- type: db
  env: production
  ar_config: /app/config/database.yml

Modern Format

jobs:
  - type: directory
    path: ~/Documents
    exclude: ["*.tmp"]
    
  - type: docker
    docker:
      container_name: mysql_container
      exec_command: ["mysqldump", "-u", "root", "mydb"]
      
  - type: compose
    compose:
      compose_file: ./docker-compose.yml
      service_name: database
      exec_command: ["pg_dump", "myapp"]

Backup Types

Directory Backup

- type: dir
  path: /path/to/directory
  include:          # Optional: include only these patterns
    - "*.important"
  exclude:          # Optional: exclude these patterns  
    - "*.log"
    - ".git"
    - "regexp:\\.tmp$"

Database Backup

Direct Configuration

- type: db
  activerecord:
    adapter: mysql2|postgresql
    database: dbname
    host: localhost
    port: 3306
    username: user
    password: pass
    dump_params: ["--single-transaction"]  # Optional

- type: db
  mongoid:
    database: myapp
    hosts: ["localhost:27017"]
    username: user        # Optional
    password: pass        # Optional
    auth_source: admin    # Optional

Rails Configuration Files

- type: db
  env: production
  ar_config: /app/config/database.yml

- type: db  
  env: production
  mg_config: /app/config/mongoid.yml

Docker Backup

- type: docker
  docker:
    container_name: mycontainer
    exec_command: ["mysqldump", "-u", "root", "mydb"]
    env:                 # Optional
      MYSQL_PWD: secret

Docker Compose Backup

- type: compose
  compose:
    compose_file: ./docker-compose.yml
    service_name: database
    exec_command: ["pg_dump", "-U", "postgres", "mydb"]
    env:                 # Optional
      PGPASSWORD: secret

Shell Command Backup

- type: shell
  shell:
    command: tar
    args: ["-czf", "-", "/var/log"]
    working_dir: /tmp    # Optional
    env:                 # Optional
      BACKUP_DATE: "2024-01-01"

# Or from config file
- type: shell
  env: production
  shell_config: /app/config/backup_scripts.yml

CLI Usage

# Backup with configuration file
rsbackup backup --repository /backup/repo --password secret config.yml

# Use password file instead
rsbackup backup --repository /backup/repo --password-file /path/to/passfile config.yml  

# Force full backup (ignore changes)
rsbackup backup --repository /backup/repo --password secret --force config.yml

# Initialize repository
rsbackup init

# Show version
rsbackup version

# Get help
rsbackup help

Environment Variables

  • RESTIC_REPOSITORY: Default repository path
  • RESTIC_PASSWORD: Default password
  • RESTIC_PASSWORD_FILE: Default password file
  • DB_HOST, DB_USER, DB_PASSWORD: Database connection (can be used in Rails configs)

Migration from rbackup

rsbackup is designed to be a drop-in replacement for rbackup:

  1. Your existing YAML configuration files should work without changes
  2. Replace rbackup command with rsbackup
  3. Add --repository and --password flags (restic requirements)

Key Differences

  • Uses restic instead of custom storage
  • Modern CLI with better error messages
  • Added Docker and Compose support
  • Better validation and error handling
  • No built-in server component (use restic REST server)

Examples

See the examples/ directory for complete configuration examples:

  • legacy-config.yml: rbackup compatible configuration
  • modern-config.yml: Modern format with new features
  • database.yml: Rails database configuration example
  • mongoid.yml: Rails mongoid configuration example

Requirements

  • Go 1.23+
  • restic (must be installed and in PATH)
  • Database tools: mysqldump, pg_dump, mongodump (for respective database types)
  • Docker (for Docker/Compose backups)

License

MIT License - see LICENSE file for details.

About

RS Backup [pre-alpha]

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •