file_dir_backup
file_dir_backup 是一个用于文件和目录备份的 Python 第三方库,支持全量备份和增量备份,同时支持 rsync 和 shutil 两种备份方法。
安装
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
使用配置文件
支持的配置文件查找规则:
- 环境变量
FILE_DIR_BACKUP_CONFIG ~/.file_dir_backup.cfg./etc/file_dir_backup.cfg/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 tests.test_file_dir_backup
Metadata
Release files for file-dir-backup 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| file_dir_backup-0.1.4.tar.gz | 7.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| file_dir_backup-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.2 kB
Release files / file_dir_backup-0.1.4.tar.gz
| Download URL | file_dir_backup-0.1.4.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06ab214c1c9f39c7626fb788d263be69be39fb09c13241a7484a39782b33ccc7
|
|
BLAKE2b-256 checksum How to use checksums |
ab8b469c19efbcd10d80e9c2249d98f2993a721dfa4dc075f7dd2e0fb7c17ad7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.6
|
Release files / file_dir_backup-0.1.4-py3-none-any.whl
| Download URL | file_dir_backup-0.1.4-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a0f3f5f4ca5b534cb9d9e017d35be686d2b87702f93e9cb3f80d56d429ba78f
|
|
BLAKE2b-256 checksum How to use checksums |
eefbef6724e397baa4edbc9cf735aec4ea7a28005c5b9825702a731199bcd99f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.6
|