A file and directory backup tool
Project description
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
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.4.tar.gz
(7.6 kB
view details)
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 file_dir_backup-0.1.4.tar.gz.
File metadata
- Download URL: file_dir_backup-0.1.4.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06ab214c1c9f39c7626fb788d263be69be39fb09c13241a7484a39782b33ccc7
|
|
| MD5 |
fb54352bfebda9e3e92c6cd27c69d693
|
|
| BLAKE2b-256 |
ab8b469c19efbcd10d80e9c2249d98f2993a721dfa4dc075f7dd2e0fb7c17ad7
|
File details
Details for the file file_dir_backup-0.1.4-py3-none-any.whl.
File metadata
- Download URL: file_dir_backup-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a0f3f5f4ca5b534cb9d9e017d35be686d2b87702f93e9cb3f80d56d429ba78f
|
|
| MD5 |
bb9e925b8ae4e99e9ff61e5fffa1a7e9
|
|
| BLAKE2b-256 |
eefbef6724e397baa4edbc9cf735aec4ea7a28005c5b9825702a731199bcd99f
|