Skip to main content

Yet another backup tool for various configurations

Project description

cockup

PyPI - Version

English | 中文

Yet another backup tool for various configurations.

Installation

PyPI

pip install cockup

Homebrew

# Single-line installation
brew install huaium/tap/cockup

# Or, using `brew tap`
brew tap huaium/tap
brew install cockup

Install from source

  1. Clone or download this repository
  2. Navigate to the project root, and run:
pip install -e .

Usage

cockup list

You may want to use it as a reference when writing your own backup rules.

# List potential config paths for all installed Homebrew casks
cockup list

# List potential config paths for specified cask
cockup list cask-name-1 [cask-name-n...]

cockup backup & restore

# Backup files according to configuration
cockup backup /path/to/config.yaml

# Restore files from backup
cockup restore /path/to/config.yaml

cockup hook

# Run hooks interactively
cockup hook /path/to/config.yaml

# Or, run a specified hook by its name
cockup hook /path/to/config.yaml --name hook_name

Configuration

Create a YAML configuration file with the following structure:

Required Fields

# Where backups are stored
# If you use relative path, it will be relative to the config file's directory
destination: "/path/to/backup/directory"

# List of backup rules
rules:
  - from: "/source/directory"
    targets: ["*.conf", "*.json"]
    to: "subdirectory"

Optional Fields

# Include rules and hooks from other config files
include:
  - "./another_config.yaml"

# Clean mode, whether to remove existing backup folder (default: false)
clean: false

# Whether to preserve metadata when backing up (default: true)
metadata: true

# Global hooks
hooks:
  pre-backup:
    - name: "Setup"
      command: ["echo", "Starting backup"]
  post-backup:
    - name: "Cleanup"
      command: ["echo", "Backup complete"]
  pre-restore:
    - name: "Prepare"
      command: ["echo", "Starting restore"]
  post-restore:
    - name: "Finish"
      command: ["echo", "Restore complete"]

Rule Structure

Each rule defines what to backup:

- from: "/source/directory/in/pattern" # Wildcards are supported
  targets:
    # Folders or files under `from`
    - "pattern1" # Wildcards are also supported
    - "relative/path/to/file"
  to: "backup/subdirectory" # A folder under `destination`
  on-start: # Optional rule-level hooks
    - name: "Before Rule"
      command: ["echo", "Processing rule"]
  on-end:
    - name: "After Rule"
      command: ["echo", "Rule complete"]

Please be aware that when using wildcards in from, to prevent duplicate files caused by matching multiple directories, cockup will locate the first safe directory without wildcards and set it as from. The paths containing wildcards encountered during the search process will be prepended to each target.

For example, if you have:

- from: "/source/directory/in/prefix*/pattern"
  targets:
    - "relative/path/to/file"
  to: "backup/subdirectory"

We will finally get:

- from: "/source/directory/in"
  targets:
    - "prefix*/pattern/relative/path/to/file"
  to: "backup/subdirectory"

Hook Structure

Hooks support custom commands.

By default, you will be prompted to confirm if your configuration file contains any hooks. Use the flag --quiet or -q to suppress it.

If you want to run them within a specified shell, use commands like bash -c after ensuring your commands are safe.

- name: "Hook Name" # Required: Hook identifier
  command: ["cmd", "arg1"] # Required: Command args list
  output: false # Optional: Print output (default: false)
  timeout: 10 # Optional: Timeout in seconds
  env: # Optional: environment variables used for the command
    ENV_1: 1
    ENV_2: 2

Please note that you cannot pass environment variables directly using syntax like $ENV_1, but the subprocess you launch can access those variables.

For example, you may want to use it to dump Homebrew bundle into a file and place it under the folder defined by destination:

- name: "Brewfile Dumping"
  command: ["brew", "bundle", "dump", "--force", "--file", "Brewfile"]
  output: true
  timeout: 10

Include

You can simply include rules and hooks from other configuration files using include.

Please note that only rules and hooks will be included, and they will be placed before the rules and hooks defined in the main config, using the clean and metadata fields from the main config for execution.

include:
  - "path_to/config_one.yaml"
  - "path_to/config_two.yaml"

Refer to sample to view a configuration demo.

Development

Basically, this project use just to unify the development workflow. If you are not going to use it, please refer to justfile in the project root to get access to the original commands.

Install test dependencies

Use pytest as the test framework.

just sync-all

Run directly

With the command form of just run [ARGS].

# `cockup list`
just run list

# `cockup backup`
just run backup /path/to/config.yaml

Run sample

A sample with minimal configs is provided for manual testing.

# Test `cockup backup`
just sample-backup

# Or test `cockup restore`
just sample-restore

# Or test `cockup hook`
just sample-hook [hook_name]

Test

just test works as an alias for pytest.

# Run all tests
just test

# Run with coverage
just test --cov=cockup

# Run specific test
just test tests/test_config.py -v

Build

just build works as an alias for uv build.

License

Please refer to LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cockup-0.1.10.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cockup-0.1.10-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file cockup-0.1.10.tar.gz.

File metadata

  • Download URL: cockup-0.1.10.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cockup-0.1.10.tar.gz
Algorithm Hash digest
SHA256 5a3d8a13979f8ddfc594756fe41fde6d2fef24ae78cd05ca448fbf2fb6b4f7fc
MD5 b2ea9a37102355de5532d2f63592f530
BLAKE2b-256 d262ad713c0a4414a18b93d55d52c8c26543cda8be8539041088bc55524d1926

See more details on using hashes here.

Provenance

The following attestation bundles were made for cockup-0.1.10.tar.gz:

Publisher: pypi.yaml on huaium/cockup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cockup-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: cockup-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cockup-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 b652faee8db765bf468f22158b8ffc9a2defdbee35ca8f6508585c54d5965664
MD5 21e6870825d4f36f189aa3f96d354560
BLAKE2b-256 fb84dcee0c1819e2112a340c9f6cf77b029c09d52f20d61ada7eed1e9acda008

See more details on using hashes here.

Provenance

The following attestation bundles were made for cockup-0.1.10-py3-none-any.whl:

Publisher: pypi.yaml on huaium/cockup

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page