折腾:
【未解决】Fabric 2中如何实现Fabric 1中的rsync_project去实现同步代码以实现项目代码部署
期间,之前是看到别人给的fabric1的示例代码:
def rsync(): rsync_project( ... exclude=(".*", "*.pyc", 'logs', '*.log', 'tmp', 'cach', 'model', 'models'), delete=('processData/')
中间有delete参数,传递的是一个路径
后来看到
中有解释:
- delete:用于设置 rsync 的 –delete 选项的参数。其值为 True 将会在远程删除本地已不存在的文件。默认值为 False。
在看到rsync的help中的解释是:
--del an alias for --delete-during --delete delete extraneous files from destination dirs --delete-before receiver deletes before transfer (default) --delete-during receiver deletes during transfer, not before --delete-after receiver deletes after transfer, not before --delete-excluded also delete excluded files from destination dirs --ignore-errors delete even if there are I/O errors --force force deletion of directories even if not empty --max-delete=NUM don't delete more than NUM files
但是后来看到别人:
中delete传入的是True,表示delete是bool类型:
rsync_project( local_dir=src, remote_dir=dest, delete=True, extra_opts=' '.join(extra_opts), ssh_opts='-oStrictHostKeyChecking=no' )
delete=True,而不是路径
-》感觉是,是否要删除?
-》感觉应该还是听:
–delete delete extraneous files from destination dirs
的,说的是:删除文件夹,而不是bool变量
然后也注意到:
中的delete是:
patchwork.transfers.rsync(c, source, target, exclude=(), delete=False, strict_host_keys=True, rsync_opts='', ssh_opts='') Convenient wrapper around your friendly local rsync. rsync [--delete] [--exclude exclude[0][, --exclude[1][, ...]]] \ -pthrvz [rsync_opts] <source> <host_string>:<target> * delete (bool) – A boolean controlling whether rsync’s --deleteoption is used. If True, instructs rsync to remove remote files that no longer exist locally. Defaults to False.
是布尔值,而不是此处(Mac本地或远端CentOS中)命令行中rsync的delete:
Downloads uname -a Darwin licrifandeMacBook-Pro.local 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64 ➜ Downloads which rsync /usr/bin/rsync ➜ Downloads rsync --help | grep delete --del an alias for --delete-during --delete delete extraneous files from destination dirs --delete-before receiver deletes before transfer (default) --delete-during receiver deletes during transfer, not before --delete-after receiver deletes after transfer, not before --delete-excluded also delete excluded files from destination dirs --ignore-errors delete even if there are I/O errors --max-delete=NUM don't delete more than NUM files ➜ Downloads
和:
[root@xxx-general-01 ~]# uname -a Linux xxx-general-01 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux [root@xxx-general-01 ~]# which rsync /usr/bin/rsync [root@xxx-general-01 ~]# rsync --version rsync version 3.0.9 protocol version 30 Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others. Web site: http://rsync.samba.org/ Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace, append, ACLs, xattrs, iconv, symtimes rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public Licence for details. [root@xxx-general-01 ~]# rsync --help | grep delete --del an alias for --delete-during --delete delete extraneous files from destination dirs --delete-before receiver deletes before transfer, not during --delete-during receiver deletes during the transfer --delete-delay find deletions during, delete after --delete-after receiver deletes after transfer, not during --delete-excluded also delete excluded files from destination dirs --ignore-errors delete even if there are I/O errors --max-delete=NUM don't delete more than NUM files
然后后来才看懂:
--delete delete extraneous files from destination dirs
指的就是:
从目标文件夹中删除额外的文件
-》而加上了
–delete
就会触发执行,不传递次此参数,就不会去delete
且动作时机是:
rsync执行完毕后,才会决定是否去delete
具体delete的文件,是:
中说的:
“在远程删除本地已不存在的文件”
然后对应的之前fabric1的rsync_project,对应映射到的rsync的命令:
rsync [--delete] [--exclude exclude[0][, --exclude[1][, ...]]] \ [default_opts] [extra_opts] <local_dir> <host_string>:<remote_dir>
中的
[–delete]
就表示:可选参数,后面没有目录/文件夹
所以是bool类型的
【总结】
所以此处确认了:
rsync命令(或第三方工具,比如基于Fabric的patchwork)的参数:delete,是bool布尔类型:
(Python代码中)调用时传递的是True或False
->含义是:
“delete (bool) – A boolean controlling whether rsync’s –deleteoption is used. If True, instructs rsync to remove remote files that no longer exist locally. Defaults to False.
delete:用于设置 rsync 的 –delete 选项的参数。其值为 True 将会在远程删除本地已不存在的文件。默认值为 False。”
另外,再去理解另外几个delete相关的参数,就清楚含义了:
- –delete delete extraneous files from destination dirs
- –delete-before receiver deletes before transfer (default)
- 接受者,一般是远端服务器中,在接收传输(进入的)文件之前,就去删除(额外的?)文件
- –delete-during receiver deletes during transfer, not before
- 同理类似的,在传输期间删除,而不是传输之前就删除
- –delete-after receiver deletes after transfer, not before
- 同理类似的,在传输之后删除,而不是传输之前就删除
- –delete-excluded also delete excluded files from destination dirs
- 对应着exclued参数:
- –exclude=PATTERN exclude files matching PATTERN
- –exclude-from=FILE read exclude patterns from FILE
- 在接受者(服务器端),删除发送者(Mac本地)中被排除掉的那些文件
- 比如Mac本地排除了*.log,*.pyc等文件时,服务器端也删除掉对应的文件
转载请注明:在路上 » 【已解决】rsync中delete参数的含义和调用方式