Skip to content

Add from_local option to transfers.rsync - #29

Open
ferares wants to merge 2 commits into
fabric:masterfrom
ferares:patch-1
Open

Add from_local option to transfers.rsync#29
ferares wants to merge 2 commits into
fabric:masterfrom
ferares:patch-1

Conversation

@ferares

Copy link
Copy Markdown

'from_local' option indicates if the copy should be done from remote to local, the default is from local to remote.

closes#26

feraresand others added 2 commits October 10, 2018 14:29
'from_local' option indicates if the copy should be done from remote to local, the default is from local to remote.
The 'from_local' option had the opposite behavior to what it is supposed to do.
@abingham

Copy link
Copy Markdown

Could this be merged in? I could really use this as well.

@gerazov

Copy link
Copy Markdown

yeah, please merge 😄

@WildWeazel

Copy link
Copy Markdown

Another vote for merge please, this feature is essential

@MacHu-GWU

Copy link
Copy Markdown

#38 Ops, I just found this PR. I issued another one for the same feature.

@ferares

Copy link
Copy Markdown
Author

@MacHu-GWU I made this back on 2018, the project is clearly and sadly inactive :(

@MacHu-GWU

Copy link
Copy Markdown

@ferares Is the author still active on GitHub? It is always good to have group of people maintaining open source project.

@ferares

Copy link
Copy Markdown
Author

@ferares Is the author still active on GitHub? It is always good to have group of people maintaining open source project.

Yeah he is @bitprophet

@trammik

Copy link
Copy Markdown

If someone is interested, here a working snippet for rsync over Fabric's method local

Simply add this to your own inherited from Connection class

defrsync(self, source, target, exclude=(), rsync_opts="", ssh_opts="",
delete=False, strict_host_keys=True, upload=True):
ifisinstance(exclude, string_types):
exclude= [exclude]
# Double-backslash-escapereplace_bs=lambdas: str(s).replace('"', '\\\\"')
exclusions=" ".join((f'--exclude "{replace_bs(s)}"'forsinexclude))
# Honor SSH key(s)keys=self.connect_kwargs.get("key_filename", [])
ifisinstance(keys, string_types):
keys= [keys]
key_string="-i "+" -i ".join(keys) ifkeyselse""port_string=f"-p {self.port}"# Workaround for our old keys:ssh_opts+='-o "PubkeyAcceptedKeyTypes +ssh-dss"'# Strict host key checkingdisable_keys="-o StrictHostKeyChecking=no"ifnotstrict_host_keysanddisable_keysnotinssh_opts:
ssh_opts+=" {}".format(disable_keys)
# Remote shell (SSH) optionsrsh_parts= [key_string, port_string, ssh_opts]
rsh_string="--rsh='ssh {}'".format(" ".join(rsh_parts)) ifany(rsh_parts) else""# Set up options part of stringoptions=f'{"--delete"ifdeleteelse""}{exclusions} -pthrvz {rsync_opts}{rsh_string}'remote_prefix=f"{self.user}@{self.host}"ifself.host.count(":") >1:
remote_prefix=f"[{remote_prefix}]"upload_direction=f"{source}{remote_prefix}:{target}"ifuploadelsef"{remote_prefix}:{source}{target}"print(f'rsync {options}{upload_direction}')
returnself.local(f"rsync {options}{upload_direction}")

@lvotapka

Copy link
Copy Markdown

If someone is interested, here a working snippet for rsync over Fabric's method local

Simply add this to your own inherited from Connection class

defrsync(self, source, target, exclude=(), rsync_opts="", ssh_opts="",
delete=False, strict_host_keys=True, upload=True):
ifisinstance(exclude, string_types):
exclude= [exclude]
# Double-backslash-escapereplace_bs=lambdas: str(s).replace('"', '\\\\"')
exclusions=" ".join((f'--exclude "{replace_bs(s)}"'forsinexclude))
# Honor SSH key(s)keys=self.connect_kwargs.get("key_filename", [])
ifisinstance(keys, string_types):
keys= [keys]
key_string="-i "+" -i ".join(keys) ifkeyselse""port_string=f"-p {self.port}"# Workaround for our old keys:ssh_opts+='-o "PubkeyAcceptedKeyTypes +ssh-dss"'# Strict host key checkingdisable_keys="-o StrictHostKeyChecking=no"ifnotstrict_host_keysanddisable_keysnotinssh_opts:
ssh_opts+=" {}".format(disable_keys)
# Remote shell (SSH) optionsrsh_parts= [key_string, port_string, ssh_opts]
rsh_string="--rsh='ssh {}'".format(" ".join(rsh_parts)) ifany(rsh_parts) else""# Set up options part of stringoptions=f'{"--delete"ifdeleteelse""}{exclusions} -pthrvz {rsync_opts}{rsh_string}'remote_prefix=f"{self.user}@{self.host}"ifself.host.count(":") >1:
remote_prefix=f"[{remote_prefix}]"upload_direction=f"{source}{remote_prefix}:{target}"ifuploadelsef"{remote_prefix}:{source}{target}"print(f'rsync {options}{upload_direction}')
returnself.local(f"rsync {options}{upload_direction}")

This was helpful, thank you.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transfers.rsync don't support rsync from remote to local

7 participants

@ferares@abingham@gerazov@WildWeazel@MacHu-GWU@trammik@lvotapka