Skip to main content

A file and directory backup tool

Project description

file_dir_backup

file_dir_backup 是一个用于文件和目录备份的 Python 第三方库,支持全量备份和增量备份,同时支持 rsyncshutil 两种备份方法。

安装

pip install file_dir_backup

使用方法

命令行使用

#  查看帮助
$ file_dir_backup -h
usage: file_dir_backup [-h] [--backup-type {full,incremental}] [--method {rsync,shutil}] [--compress] [--bandwidth-limit BANDWIDTH_LIMIT] source destination

File and directory backup tool

positional arguments:
  source                Source directory to backup
  destination           Destination directory for backup

optional arguments:
  -h, --help            show this help message and exit
  --backup-type {full,incremental}
                        Backup type: full or incremental
  --method {rsync,shutil}
                        Backup method: rsync or shutil
  --compress            Compress data during transfer
  --bandwidth-limit BANDWIDTH_LIMIT
                        Limit the bandwidth in KB/s



$ file_dir_backup /path/to/source /path/to/destination --backup-type full --method rsync --compress --bandwidth-limit 1000
# 全量同步示例:
#$ file_dir_backup /home/hujianli/test/ /home/hujianli/backup/ --backup-type full --method rsync --compress --bandwidth-limit 1000

# 或者
$ python -m file_dir_backup /path/to/source /path/to/destination --backup-type full --method rsync --compress --bandwidth-limit 1000

# 增量同步示例:
#$ python -m file_dir_backup /home/hujianli/test/ /home/hujianli/backup/ --backup-type incremental --method rsync --compress --bandwidth-limit 1000

使用配置文件

支持的配置文件查找规则:

  1. 环境变量 FILE_DIR_BACKUP_CONFIG
  2. ~/.file_dir_backup.cfg
  3. ./etc/file_dir_backup.cfg
  4. /etc/file_dir_backup.cfg

配置文件格式,以/etc/file_dir_backup.cfg为示例:

[backup]
source = /home/hujianli/test
destination =/home/hujianli/backup
# 备份类型
backup_type = full
# 备份方法
method = rsync
# 是否传输过程中压缩数据
compress = true
# 传输限速
bandwidth_limit = 1000

Python 代码使用

from file_dir_backup import BackupManager
# 示例用法
backup_manager = BackupManager(
    source="/path/to/source",
    destination="/path/to/destination",
    backup_type="full",
    method="rsync"
)
backup_manager.backup()

测试

测试代码在 tests 目录下,使用 unittest 模块进行测试。

python -m unittest test.test_file_dir_backup

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

file_dir_backup-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file file_dir_backup-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for file_dir_backup-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ccfff902b03f57f58cb8376d1d7afb147c19228e1ae80f091d29e87804441153
MD5 cd1e7cc7f4c30adad5c811ee2124fdc9
BLAKE2b-256 4ea26256c43b39aa41f8cfbadf8f635e5e59f3033b32c81aeee52bad5baf0298

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