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 Distribution

file_dir_backup-0.1.3.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file file_dir_backup-0.1.3.tar.gz.

File metadata

  • Download URL: file_dir_backup-0.1.3.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.6

File hashes

Hashes for file_dir_backup-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a4abfefb156ebe551e3c5cdd6de99d8418d31658d85f7592a4fc6618e9724672
MD5 40a2ba7ef0cf712f175f4c2ca8545f5b
BLAKE2b-256 1a74333cd9abd4f2b8497fb9eadc2f198abbd9a317075e130cd574fa55d538c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for file_dir_backup-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 23eb76c4b24b294cb8aa1c2f26c105838ebeaa375793cbd5578372c02c974164
MD5 fc87aa6b7279b936f4c4f76028cbe428
BLAKE2b-256 cd303baec8c45485d8c92008aaba3bea4848184515e22dd765a671235bb44f7e

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