backup

Files
Databases
Snapshot a directory and upload it to remote

Usage:
  snaper backup files [flags]

Aliases:
  files, fs, filesystem

Examples:
snaper backup files /path/to/backup
snaper backup files mybackup

Flags:
      --all                          Backup all directories configured
      --concurrent int               Number of concurrent workers to use for upload
      --configure                    Only configure the backup without running it
      --encryption-key string        Encryption key to use for encrypting data
      --encryption-key-file string   Encryption key file to read for encrypting data
      --exclude strings              Paths to exclude from backup (separated by commas)
      --follow-symlinks              Follow symlinks when backing up files
  -h, --help                         help for files
      --ignore-existing              Check for existing files on S3 and ignore them (only for bug fixing)
      --include strings              Paths to include in backup (separated by commas)
  -n, --name string                  Name of the backup (optional)
  -p, --path string                  Directory path to backup (optional)
Dump a database and upload it to remote

Usage:
  snaper backup database [flags]

Aliases:
  database, db, databases

Examples:
snaper backup db mydatabase --type mysql
snaper backup db --all

Flags:
      --all                          Backup all databases configured in config.yaml
      --all-databases                Backup all databases existing on the server
      --auth-db string               Authentication database (mongodb only)
      --configure                    Only configure the backup without running it
      --direct-connection            Use direct connection to the database (mongodb only)
      --encryption-key string        Encryption key to use for encrypting data
      --encryption-key-file string   Encryption key file to read for encrypting data
  -h, --help                         help for database
      --hex-blob                     Dump binary columns using hexadecimal notation (mysql only)
  -H, --host string                  Hostname of the database server (default "localhost")
  -n, --name string                  Database name to backup
  -p, --password string              Password to use for connecting to the database (prefer using MYSQL_PASSWORD/PGPASSWORD/MONGODB_PASSWORD)
  -P, --port int                     Port of the database server
      --routines                     Backup database routines like functions of procedures (mysql only)
      --single-transaction           Dump all tables in a single transaction (mysql only)
      --triggers                     Backup database triggers (mysql only)
  -t, --type string                  Database type (mysql, postgresql)
  -u, --username string              Username to use for connecting to the database

Global Flags:
      --concurrent   Run file and database backups concurrently

MySQL and PostgreSQL support socket connections. This method will be attempted by default if you specify β€œlocalhost” as the host (which is the default value). If you want to force a TCP/IP connection instead, specify 127.0.0.1.

Usage Examples

Backup a directory while excluding files

# Exclude a specific directory and all its contents
# When backing up /var, exclude /var/cache and everything inside it
snaper backup files /var --exclude "/var/cache/**"

# Exclude multiple subdirectories (cache and log)
snaper backup files /path/to/backup --exclude "var/cache/**,var/log/**"

# Exclude all node_modules directories at any depth
snaper backup files ./app --exclude "**/node_modules/**"

# Exclude all .log files at any depth
snaper backup files /app --exclude "**/*.log"

# Include only Python files, except tests (using ** for recursive matching)
snaper backup files /project --include "**/*.py" --exclude "**/*test*.py,**/*_test.py"

# Exclude .log files but keep error.log at the root level
snaper backup files /app --include "error.log" --exclude "**/*.log"

Filtering Options (Pattern Matching)

Matching Rules

  • Patterns match against the full absolute path of files.
    Ex: backing up /home/user with pattern Documents/** β†’ matches /home/user/Documents/**.

  • Relative patterns are converted to absolute:

    • logs/** becomes /path/to/backup/logs/**
  • The slash (/) and wildcards matter:

    • myfile β†’ only /path/to/backup/myfile (exact match at root)
    • dir/myfile β†’ only /path/to/backup/dir/myfile
    • **/myfile β†’ any file named myfile at any depth
    • *.log β†’ only .log files at the root level
    • **/*.log β†’ all .log files at any depth
  • Useful patterns:

    • * β†’ any string except / (*.log, cache*)
    • ** β†’ matches recursively including / (**/logs/**, **/*.py)
    • ? β†’ a single character (file?.txt)

Priority Order

  1. Inclusions are evaluated before exclusions.
  2. If a file matches both, it is excluded.

Example:

snaper backup files /project \
  --include "**/*.py" \
  --exclude "**/*test*.py"

All Python files are included, but test files are excluded.