Skip to main content

A simple tool to backup and restore data as tgz files.

Project description

Tests codecov

ezbak

A simple backup management tool that can be used both as a command-line interface and as a Python package. ezbak provides automated backup creation, management, and cleanup operations with support for multiple destinations, compression, and intelligent retention policies.

Features

  • Create compressed backups of files and directories in tgz format
  • Support for multiple backup destinations
  • Configurable compression levels
  • Intelligent retention policies (time-based and count-based)
  • File filtering with regex patterns
  • Time-based backup labeling (yearly, monthly, weekly, daily, hourly, minutely)
  • Automatic backup pruning based on retention policies
  • Restore functionality

Installation

# with uv
uv add ezbak

# with pip
pip install ezbak

Usage

Python Package

ezbak is primarily designed to be used as a Python package in your projects:

from pathlib import Path
from ezbak import ezbak

# Initialize backup manager
backup_manager = ezbak(
    name="my-backup",
    sources=[Path("/path/to/source")],
    destinations=[Path("/path/to/destination")],
    time_based_policy={
        "yearly": 1,
        "monthly": 12,
        "weekly": 4,
        "daily": 7,
        "hourly": 24,
        "minutely": 60,
    },
    log_level="INFO",
    log_file=Path("/path/to/log.txt"),
    exclude_regex=r"\.DS_Store$",
    label_time_units=True,
)

# Create a backup
backup_files = backup_manager.create_backup()

# List existing backups
backups = backup_manager.list_backups()

# Prune old backups
deleted_files = backup_manager.prune_backups()

# Restore latest backup
backup_manager.restore_latest_backup(destination=Path("/path/to/restore"))

Configuration Options

  • name (str): Backup name
  • sources (list[Path]): List of source paths
  • destinations (list[Path]): List of destination paths
  • compression_level (int): Compression level (1-9)
  • max_backups (int): Maximum number of backups to keep
  • time_based_policy (dict[str, int]): Time-based retention policy (dictionary of time units and number of backups to keep)
  • timezone (str): Timezone for backup timestamps
  • log_level (str): Logging level
  • log_file (Path | str): Path to log file
  • exclude_regex (str): Regex pattern to exclude files
  • include_regex (str): Regex pattern to include files
  • label_time_units (bool): Whether to label time units in filenames

Retention Policies

If neither max_backups and time_based_policy are provided, all backups are kept. Keep in mind that these are mutually exclusive, and if both are provided, max_backups will be used.

The time-based retention policy is a dictionary of time units and number of backups to keep. The time units are:

  • yearly
  • monthly
  • weekly
  • daily
  • hourly
  • minutely

For example, the following policy will keep the most recent 2 yearly backups, 12 monthly backups, 4 weekly backups, 7 daily backups, 24 hourly backups, and 10 minutely backups:

time_based_policy = {
    "yearly": 2,
    "monthly": 12,
    "weekly": 4,
    "daily": 7,
    "hourly": 24,
    "minutely": 10,
}

Backup Naming

- Backup files are named in the format: `{name}-{timestamp}-{period}.{extension}`
- When `label_time_units` is False, the period is omitted
- If a backup with the same name exists, a UUID is appended to prevent conflicts
- The timestamp format is ISO 8601: `YYYYMMDDTHHMMSS`

Command Line Interface

For convenience, ezbak also provides a command-line interface with several subcommands:

Create a Backup

ezbak create --name my-backup --sources /path/to/source --destinations /path/to/destination

Additional options:

  • --include-regex: Include files matching the regex pattern
  • --exclude-regex: Exclude files matching the regex pattern
  • --compression-level: Set compression level (1-9)
  • --no-label: Disable time unit labeling in backup filenames

List Backups

ezbak list --locations /path/to/backups

Prune Backups

ezbak prune --destinations /path/to/backups --max-backups 10

Time-based retention options:

  • --yearly: Number of yearly backups to keep
  • --monthly: Number of monthly backups to keep
  • --weekly: Number of weekly backups to keep
  • --daily: Number of daily backups to keep
  • --hourly: Number of hourly backups to keep
  • --minutely: Number of minutely backups to keep

Restore Backup

ezbak restore --destination /path/to/restore

Environment Variables

ezbak can be configured using environment variables with the EZBAK_ prefix:

  • EZBAK_NAME: Backup name
  • EZBAK_SOURCES: Comma-separated list of source paths
  • EZBAK_DESTINATIONS: Comma-separated list of destination paths
  • EZBAK_TZ: Timezone for backup timestamps
  • EZBAK_LOG_LEVEL: Logging level
  • EZBAK_LOG_FILE: Path to log file
  • EZBAK_COMPRESSION_LEVEL: Compression level (1-9)
  • EZBAK_TIME_BASED_POLICY: JSON string of time-based retention policy
  • EZBAK_MAX_BACKUPS: Maximum number of backups to keep
  • EZBAK_EXCLUDE_REGEX: Regex pattern to exclude files
  • EZBAK_INCLUDE_REGEX: Regex pattern to include files
  • EZBAK_LABEL_TIME_UNITS: Whether to label time units in filenames

Contributing

See CONTRIBUTING.md for more information.

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

ezbak-0.2.0.tar.gz (82.3 kB view details)

Uploaded Source

Built Distribution

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

ezbak-0.2.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file ezbak-0.2.0.tar.gz.

File metadata

  • Download URL: ezbak-0.2.0.tar.gz
  • Upload date:
  • Size: 82.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for ezbak-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fac9261f2cd69314bef3ac15d1d72d1b73d7678005fc142654bc7021fedd9ca5
MD5 fe955754d3a1d51983b2159a648d59c3
BLAKE2b-256 907b38870b982486d1cbe0a488d26ccbfb30e02685a67c5613c9eec9ff70a180

See more details on using hashes here.

File details

Details for the file ezbak-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ezbak-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for ezbak-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 944c9b985df2f5085f7e2a11365b36f2487d8d5c91f85041fc45df46863843d3
MD5 b5ed26b553d9ed825889b4ce43b78de7
BLAKE2b-256 d00bc0a4ddbb6370d3756a044564de823abd10fcac94bb387a407c6b190ec1a5

See more details on using hashes here.

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