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

@ferares ferares commented Oct 10, 2018

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

ferares and 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

gerazov commented Apr 20, 2019

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

ferares commented Jan 24, 2020

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

ferares commented Jan 24, 2020

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

trammik commented Sep 13, 2021

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

    def rsync(self, source, target, exclude=(),  rsync_opts="", ssh_opts="",
              delete=False, strict_host_keys=True, upload=True):
        if isinstance(exclude, string_types):
            exclude = [exclude]
        # Double-backslash-escape
        replace_bs = lambda s: str(s).replace('"', '\\\\"')
        exclusions = " ".join((f'--exclude "{replace_bs(s)}"' for s in exclude))
        # Honor SSH key(s)
        keys = self.connect_kwargs.get("key_filename", [])
        if isinstance(keys, string_types):
            keys = [keys]
        key_string = "-i " + " -i ".join(keys) if keys else ""
        port_string = f"-p {self.port}"

        # Workaround for our old keys:
        ssh_opts += '-o "PubkeyAcceptedKeyTypes +ssh-dss"'
        # Strict host key checking
        disable_keys = "-o StrictHostKeyChecking=no"
        if not strict_host_keys and disable_keys not in ssh_opts:
            ssh_opts += " {}".format(disable_keys)
        # Remote shell (SSH) options
        rsh_parts = [key_string, port_string, ssh_opts]
        rsh_string = "--rsh='ssh {}'".format(" ".join(rsh_parts)) if any(rsh_parts) else ""
        # Set up options part of string
        options = f'{"--delete" if delete else ""}{exclusions} -pthrvz {rsync_opts} {rsh_string}'
        remote_prefix = f"{self.user}@{self.host}"
        if self.host.count(":") > 1:
            remote_prefix = f"[{remote_prefix}]"

        upload_direction = f"{source} {remote_prefix}:{target}" if upload else f"{remote_prefix}:{source} {target}"
        print(f'rsync {options} {upload_direction}')
        return self.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

    def rsync(self, source, target, exclude=(),  rsync_opts="", ssh_opts="",
              delete=False, strict_host_keys=True, upload=True):
        if isinstance(exclude, string_types):
            exclude = [exclude]
        # Double-backslash-escape
        replace_bs = lambda s: str(s).replace('"', '\\\\"')
        exclusions = " ".join((f'--exclude "{replace_bs(s)}"' for s in exclude))
        # Honor SSH key(s)
        keys = self.connect_kwargs.get("key_filename", [])
        if isinstance(keys, string_types):
            keys = [keys]
        key_string = "-i " + " -i ".join(keys) if keys else ""
        port_string = f"-p {self.port}"

        # Workaround for our old keys:
        ssh_opts += '-o "PubkeyAcceptedKeyTypes +ssh-dss"'
        # Strict host key checking
        disable_keys = "-o StrictHostKeyChecking=no"
        if not strict_host_keys and disable_keys not in ssh_opts:
            ssh_opts += " {}".format(disable_keys)
        # Remote shell (SSH) options
        rsh_parts = [key_string, port_string, ssh_opts]
        rsh_string = "--rsh='ssh {}'".format(" ".join(rsh_parts)) if any(rsh_parts) else ""
        # Set up options part of string
        options = f'{"--delete" if delete else ""}{exclusions} -pthrvz {rsync_opts} {rsh_string}'
        remote_prefix = f"{self.user}@{self.host}"
        if self.host.count(":") > 1:
            remote_prefix = f"[{remote_prefix}]"

        upload_direction = f"{source} {remote_prefix}:{target}" if upload else f"{remote_prefix}:{source} {target}"
        print(f'rsync {options} {upload_direction}')
        return self.local(f"rsync {options} {upload_direction}")

This was helpful, thank you.

Sign up for free to 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