kmi / file-sync-tool
Python 脚本,用于从客户端系统同步文件。
0.4.8
2023-02-21 08:25 UTC
README
Python 脚本,用于使用rsync从源系统同步到目标系统。
此工具是db-sync-tool的插件。
安装
先决条件
该脚本需要 Python 3.5 或更高版本。为了使用一些附加功能,需要在您的本地机器上安装 pip。
pip
可以从 PyPI 安装库。
$ pip3 install file-sync-tool-kmi
composer
脚本也可以通过 composer 在 packagist.org 上使用。
$ composer require kmi/file-sync-tool
此外,可以通过以下 pip 命令安装 Python 依赖
$ pip3 install -e vendor/kmi/file-sync-tool/
配置
您可以使用 shell 参数或使用单独的配置文件来配置脚本。
配置文件
config.json
包含有关源系统和目标系统的重要信息。
接收模式下 config.json
的示例结构
{ "target": {}, "origin": { "host": "ssh_host", "user": "ssh_user" }, "files": { "config": [ { "origin": "/var/www/html/files/", "target": "/var/www/html/files/", "exclude": [ "*.log" ] } ] } }
文档
通过在 config
条目中添加包含多个传输条目的 files
部分,扩展 config.json
。因此,您必须指定文件同步的 origin
源路径以及 target
目标路径。此外,定义此特定传输的 rsync exclude
。
在 config
条目中,您还可以定义额外的 rsync option
作为覆盖默认选项的列表。
有关更多信息,请参阅 db-sync-tool 的文档。
用法
命令行
通过命令行运行 Python 脚本。
通过 pip 安装
$ file_sync_tool
通过 composer 安装
$ python3 vendor/kmi/file-sync-tool/file_sync_tool
Shell 参数
usage: file_sync_tool [-h] [-f CONFIG_FILE] [-v] [-m] [-o HOST_FILE] [-th TARGET_HOST] [-tu TARGET_USER] [-tpw TARGET_PASSWORD] [-tk TARGET_KEY] [-tpo TARGET_PORT] [-oh ORIGIN_HOST] [-ou ORIGIN_USER] [-opw ORIGIN_PASSWORD] [-ok ORIGIN_KEY] [-opo ORIGIN_PORT] [-fo FILES_ORIGIN] [-ft FILES_TARGET] [-fe FILES_EXCLUDE] [-fop FILES_OPTION] A tool for automatic file synchronization from and to host systems. optional arguments: -h, --help show this help message and exit -f CONFIG_FILE, --config-file CONFIG_FILE Path to configuration file -v, --verbose Enable extended console output -m, --mute Mute console output -o HOST_FILE, --host-file HOST_FILE Using an additional hosts file for merging hosts information with the configuration file -th TARGET_HOST, --target-host TARGET_HOST SSH host to target system -tu TARGET_USER, --target-user TARGET_USER SSH user for target system -tpw TARGET_PASSWORD, --target-password TARGET_PASSWORD SSH password for target system -tk TARGET_KEY, --target-key TARGET_KEY File path to SSH key for target system -tpo TARGET_PORT, --target-port TARGET_PORT SSH port for target system -oh ORIGIN_HOST, --origin-host ORIGIN_HOST SSH host to origin system -ou ORIGIN_USER, --origin-user ORIGIN_USER SSH user for origin system -opw ORIGIN_PASSWORD, --origin-password ORIGIN_PASSWORD SSH password for origin system -ok ORIGIN_KEY, --origin-key ORIGIN_KEY File path to SSH key for origin system -opo ORIGIN_PORT, --origin-port ORIGIN_PORT SSH port for origin system -fo FILES_ORIGIN, --files-origin FILES_ORIGIN File path for origin source of file sync -ft FILES_TARGET, --files-target FILES_TARGET File path for target destination of file sync -fe FILES_EXCLUDE, --files-exclude FILES_EXCLUDE Excludes for file sync -fop FILES_OPTION, --files-option FILES_OPTION Additional rsync options
如果您没有在脚本执行期间声明 SSH 密钥路径,系统将提示您在 shell 参数或 config.json
中输入给定用户的 SSH 密码以启用远程系统的 SSH 连接。
导入
您可以在项目中导入 Python 包并使用它们。
from file_sync_tool import sync if __name__ == "__main__": sync.Sync(config={}, args*)
发布指南
有关发布新版本的详细指南可在此处找到。
测试
为测试目的提供了一个 Docker 容器。请参阅此处。