Giter Site home page Giter Site logo

jbussdieker / ruby-rsync Goto Github PK

View Code? Open in Web Editor NEW
58.0 3.0 20.0 35 KB

Ruby/Rsync is a Ruby library that can syncronize files between remote hosts by wrapping a call to the rsync binary.

License: MIT License

Ruby 100.00%
ruby rsync ruby-library syncronize-files

ruby-rsync's Introduction

Rsync

Build Status Code Climate Gem Version Coverage Status Dependency Status

Ruby/Rsync is a Ruby library that can syncronize files between remote hosts by wrapping a call to the rsync binary.

Usage

Minimal example

require "rsync"

result = Rsync.run("/path/to/src", "/path/to/dest")

Complete example

require "rsync"

Rsync.run("/path/to/src", "/path/to/dest") do |result|
  if result.success?
    result.changes.each do |change|
      puts "#{change.filename} (#{change.summary})"
    end
  else
    puts result.error
  end
end

ruby-rsync's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ruby-rsync's Issues

Raw results parser is sensitive to protocol changes

It looks like this gem is only compatible with the default out-format of rsync protocol version 30. Based on some small testing samples I noticed that the protocol seems to change slightly with every version.

(Mac OSX Mavericks) rsync version 2.6.9 protocol version 29

The "%i" escape has a cryptic output that is 9 letters long. The general format is like the string YXcstpogz, where Y is replaced by the type of update being done, X is replaced by the file-type, and the other letters represent attributes that may be output if they are being modified.

(CentOS 6.5) rsync version 3.0.9 protocol version 30

The โ€œ%iโ€ escape has a cryptic output that is 11 letters long. The general format is like the string YXcstpoguax, where Y is replaced by the type of update being done, X is replaced by the file-type, and the other letters represent attributes that may be output if they are being modified.

(Mac OSX Mavericks - brew) rsync version 3.1.1 protocol version 31

The "%i" escape has a cryptic output that is 11 letters long. The general format is like the string YXcstpoguax, where Y is replaced by the type of update being done, X is replaced by the file-type, and the other letters represent attributes that may be output if they are being modified.

And despite what the man page says, it's 12 characters. ">f++++++++++ bar.txt"

This makes the library extremely sensitive to changes to the rsync version. It would be nice if one could either specify or the library to substitute its parser algorithm based on the installed version of rsync.

Make stats information about the rsync process available.

I'm not sure if these information are accessible but will it be possible to retrieve these information for every rsync?
2018/05/22 01:01:21 [4740] Total transferred file size: 1971325 bytes
2018/05/22 01:01:21 [4740] Literal data: 1869259 bytes
2018/05/22 01:01:21 [4740] Matched data: 102066 bytes
2018/05/22 01:01:21 [4740] File list size: 46225
2018/05/22 01:01:21 [4740] File list generation time: 1.094 seconds
2018/05/22 01:01:21 [4740] File list transfer time: 0.000 seconds
2018/05/22 01:01:21 [4740] Total bytes sent: 4821
2018/05/22 01:01:21 [4740] Total bytes received: 535033
2018/05/22 01:01:21 [4740] sent 4821 bytes received 535033 bytes 63512.24 bytes/sec
2018/05/22 01:01:21 [4740] total size is 51072714 speedup is 94.60

changed method always returns true

The changed? method returns true if and only if update_type is not equal to :no_change:

def changed?
  if update_type == :no_change
    false
  else
    true
  end
end

However, update_type can never be that value:

def update_type
  case raw_update_type
    when '<'
      :sent
    when '>'
      :recv
    when 'c'
      :change
    when 'h'
      :hard_link
    when '.'
      :no_update
    when '*'
      :message
  end
end

I suspect it should be if update_type == :no_update as :no_change appears to apply only to changes to attributes.

Error in rsync protocol data stream

Hey, I'm on El Capitan and when trying to do a simple rsync call:
Rsync.run(file.full_path, ::File.expand_path("#{dir}/#{file.path}"))

I'm getting this error. If I run it manually, it works. Any tips?

not able to get this to work with rsync 3.1.0

Hello,

I was attempting to use this gem yesterday but found that it doesn't seem to work with rsync 3.1.0. The error I get from rsync is that I am using an invalid parameter.

Piece of code I tried to use:

Rsync.run('source', 'destination',['a', 'v', 'z', '--log-file=/some/og/file.log']) do |result|
email_error if result.error
end

Am I not specifying something correctly? or does something need to be updated to address some changes in rsync 3.1.0?

Not able to use SFTP

Rsync.run("/home/user/folder", "sftp://[email protected]:/home/user/")
=># <Rsync::Result:0x00000000f02c10 @raw="ssh: Could not resolve hostname sftp: Name or service not known\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]\n", @ExitCode=255>

Enhance: Run as another user through sudo

Hi,

I have the need to impersonate the execution of the command to achieve a password-less connection to the remote server with a user other than the current one.

To make it, I count on sudo to do the work and use in my sources the following piece of code as a quick workaround:

module Rsync

  class << self
    attr_accessor :sudo_as
  end

  class Command
    def self.run(*args)
      cmd = "rsync --itemize-changes #{args.join(" ")}"
      cmd.insert(0, "sudo -u #{Rsync.sudo_as} ") if Rsync.sudo_as
      output = run_command(cmd)
      Result.new(output, $?.exitstatus)
    end
  end
end

Don't know if it's a good way to do it, but I hope will be of any help for a future enhancement.

Regards,

Expose Result.exitcode attribute

Hi,

It would be nice for integration with monitoring tools, to expose the @exitcode instance value of the Result class as a public attribute as part of the formal API.

Regards,

Add more contributors to project

This project is used widely but is dead. Please add more contributors so that issues can be addressed and PR can be accepted.

Make raw results accessible

hi,
I'm working on project using Rsync as server and ruby-rsync is accessing this server.
On server there could be many modules and I need to list and parse them.

So I can do something like this:

test = Rsync.run("rsync://domain.domain", "")
=> #<Rsync::Result:0x000000014c3f28
 @exitcode=0,
 @raw="zabbix         \tzabbix config directory)\netc            \tmain config directory\n">

But in Result class, there is no attr_reader fo raw ouput. Also it would be nice to have some parser, which will ouput hash with separated name and comment.
When running this list command, in arguments there should be only source, no destination. I'm suggesting to make destination optional, but I know, it will brake something.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.