高级目录树同步工具
dirsync的Python项目详细描述
版权所有2014-2019 Thomas Khyn 2003-2015年Anand B Pillai
高级目录树同步工具
基于Anand B Pillai的Python robocopier
如果你喜欢Dirsync并且想办法感谢我和/或鼓励我 未来发展,这是我的BTC或BCH捐赠地址: 1EwENyR8RV6tMc1hsLTkPURtn5wJgaBfG9。
用法
从命令行:
dirsync <sourcedir> <targetdir> [options]
来自python:
from dirsync import sync sync(sourcedir, targetdir, action, **options)
主要选项
必须在下列选项中选择一个
--diff, -d | Only report difference between sourcedir and targetdir |
--sync, -s | Synchronize content between sourcedir and targetdir |
--update, -u | Update existing content between sourcedir and targetdir |
如果您大部分时间使用上述选项之一(例如sync),则 可以考虑在解析的Configuration file中定义action选项 通过dirsync。
其他选项
--verbose, -v | Provide verbose output |
--purge, -p | Purge files when synchronizing (does not purge by default) |
--force, -f | Force copying of files, by trying to change file permissions |
--twoway, -2 | Update files in source directory from target directory (only updates target from source by default) |
--create, -c | Create target directory if it does not exist (By default, target directory should exist.) |
--ctime | Also takes into account the source file’s creation time (Windows) or the source file’s last metadata change (Unix) |
--content | Takes into account ONLY content of files. Synchronize ONLY different files. At two-way synchronization source files content have priority if destination and source are existed |
--ignore, -x patterns | |
Regex patterns to ignore | |
--only, -o patterns | |
Regex patterns to include (exclude every other) | |
--exclude, -e patterns | |
Regex patterns to exclude | |
--include, -i patterns | |
Regex patterns to include (with precedence over excludes) |
配置文件
注意
配置文件仅在使用命令行时使用,并被忽略 当从python中调用dirsync时。
如果您想一直使用预定义的选项,或者如果您需要特定的 选项当“dirsync”特定源目录时,dirsync查找 两个配置文件,按顺序或优先级排列(最后一个优先):
~/.dirsync source/directory/.dirsync
注意
第一次自动创建~/.dirsync配置文件 从命令行运行dirsync。默认情况下,它启用sync模式。
警告
任何source/directory/.dirsync文件都自动从 要比较的文件。必须显式包含使用--include 如果你想让它被比较所覆盖,请选择它。
命令行选项总是覆盖 配置文件。
配置文件必须有一个defaults节,选项如下 如上所述。唯一的例外是选项action,它可以 取3个值diff、sync或update。
配置文件示例:
[defaults] action = sync create = True
自定义记录器
从python中,您可能不希望将输出发送到stdout。为此, 您只需通过的logger关键字参数传递自定义记录器 sync函数:
sync(sourcedir, targetdir, action, logger=my_logger, **options)