A simple tool to backup and restore data as tgz files.
Project description
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 namesources (list[Path]): List of source pathsdestinations (list[Path]): List of destination pathscompression_level (int): Compression level (1-9)max_backups (int): Maximum number of backups to keeptime_based_policy (dict[str, int]): Time-based retention policy (dictionary of time units and number of backups to keep)timezone (str): Timezone for backup timestampslog_level (str): Logging levellog_file (Path | str): Path to log fileexclude_regex (str): Regex pattern to exclude filesinclude_regex (str): Regex pattern to include fileslabel_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:
yearlymonthlyweeklydailyhourlyminutely
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 nameEZBAK_SOURCES: Comma-separated list of source pathsEZBAK_DESTINATIONS: Comma-separated list of destination pathsEZBAK_TZ: Timezone for backup timestampsEZBAK_LOG_LEVEL: Logging levelEZBAK_LOG_FILE: Path to log fileEZBAK_COMPRESSION_LEVEL: Compression level (1-9)EZBAK_TIME_BASED_POLICY: JSON string of time-based retention policyEZBAK_MAX_BACKUPS: Maximum number of backups to keepEZBAK_EXCLUDE_REGEX: Regex pattern to exclude filesEZBAK_INCLUDE_REGEX: Regex pattern to include filesEZBAK_LABEL_TIME_UNITS: Whether to label time units in filenames
Contributing
See CONTRIBUTING.md for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fac9261f2cd69314bef3ac15d1d72d1b73d7678005fc142654bc7021fedd9ca5
|
|
| MD5 |
fe955754d3a1d51983b2159a648d59c3
|
|
| BLAKE2b-256 |
907b38870b982486d1cbe0a488d26ccbfb30e02685a67c5613c9eec9ff70a180
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
944c9b985df2f5085f7e2a11365b36f2487d8d5c91f85041fc45df46863843d3
|
|
| MD5 |
b5ed26b553d9ed825889b4ce43b78de7
|
|
| BLAKE2b-256 |
d00bc0a4ddbb6370d3756a044564de823abd10fcac94bb387a407c6b190ec1a5
|