rsync_wrap 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/rsync_wrap.rb +118 -0
  2. metadata +45 -0
data/lib/rsync_wrap.rb ADDED
@@ -0,0 +1,118 @@
1
+ # Wrapped class to access rsync functionality.
2
+ # Mostly wrote it to learn more about Ruby.
3
+ # Coded by Werner Gillmer <werner.gillmer@gmail.com>
4
+
5
+ require 'socket'
6
+ require 'ssh_test'
7
+
8
+ class RsyncWrap
9
+
10
+ # Supported parameters :
11
+ # transport = ssh or local
12
+ # server = ssh server
13
+ # username = ssh username
14
+ # keyfile = ssh key
15
+ # compress : true/false = the rsync -z option
16
+ # backup = backup, clone or sync : sync is --delete option of rsync
17
+ # clone is same as sync, except with clone remotedir and
18
+ # localdir is the same. Local transport not supported.
19
+ # progress : true/false = is rsync --progress
20
+ # stats : true/false = is rsync --stats
21
+ # quiet : true/false = rsync -q --no-motd
22
+ def initialize(params)
23
+
24
+ @rsyncCommand = []
25
+ @rsyncCommand.push("rsync -a")
26
+
27
+ # Verbose output
28
+ @verbose = params["verbose"] unless params["verbose"].nil?
29
+ if @verbose == true
30
+ @rsyncCommand.push('-v')
31
+ end
32
+
33
+ # Be SILENT!
34
+ @quiet = params["quiet"] unless params["quiet"].nil?
35
+ if @quiet == true
36
+ @rsyncCommand.push('-q --no-motd')
37
+ end
38
+
39
+ # Give stats on rsync transfer
40
+ @stats = params["stats"] unless params["stats"].nil?
41
+ if @stats == true
42
+ @rsyncCommand.push('--stats')
43
+ end
44
+
45
+ # Give progress indicator
46
+ @progress = params["progress"] unless params["progress"].nil?
47
+ if @progress == true
48
+ @rsyncCommand.push('--progress')
49
+ end
50
+
51
+ # Copy symlinks as symlinks
52
+ @symlinks = params["symlinks"] unless params["symlinks"].nil?
53
+ if @symlinks == true
54
+ @rsyncCommand.push('-l')
55
+ end
56
+
57
+ # Compress the network stream
58
+ @compress = params["compress"] unless params["compress"].nil?
59
+ if @compress == true
60
+ @rsyncCommand.push('-z')
61
+ end
62
+
63
+ # Sync or backup
64
+ @backup = params["backup"] unless params["backup"].nil?
65
+ if @backup == 'sync' || @backup == 'clone'
66
+ @rsyncCommand.push('--delete')
67
+ end
68
+
69
+ # SSH varibles
70
+ @transport = params["transport"] unless params["transport"].nil?
71
+ @server = params["server"] unless params["server"].nil?
72
+ @username = params["username"] unless params["username"].nil?
73
+ @keyfile = params["keyfile"] unless params["keyfile"].nil?
74
+
75
+ end
76
+
77
+ def rsync(localDir,remoteDir)
78
+
79
+ # Handle directories
80
+ if File.directory?(localDir)
81
+ @rsyncCommand.push(localDir)
82
+ else
83
+ puts "ERROR : #{localDir} not found"
84
+ Process.exit
85
+ end
86
+
87
+ # Build up ssh connection string
88
+ if @transport == 'ssh'
89
+ # Check for clone functionality
90
+ if @backup == 'clone'
91
+ dirname, basename = File.split(localDir)
92
+ remoteDir = dirname
93
+ end
94
+ if @server.nil?
95
+ puts "ERROR: server cannot be empty on ssh transport"
96
+ Process.exit
97
+ else
98
+ ssh = SSHTest.new
99
+ if ssh.test(@server,@username,@keyfile) == false
100
+ puts "ERROR on ssh connection"
101
+ Process.exit
102
+ end
103
+ end
104
+ sshConn = "-e \"ssh -i #{@keyfile}\" #{@username}@#{@server}:#{remoteDir}"
105
+ @rsyncCommand.push(sshConn)
106
+ end
107
+
108
+ # Local dir push
109
+ if @transport == 'local'
110
+ @rsyncCommand.push(remoteDir)
111
+ end
112
+
113
+ # Run the rsync command
114
+ rCommand = @rsyncCommand.join(' ')
115
+ system rCommand
116
+ # puts rCommand
117
+ end
118
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsync_wrap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Werner Gillmer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-30 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Rsync wrapper library for rsync functionality
15
+ email: werner.gillmer@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/rsync_wrap.rb
21
+ homepage: http://github.com/daemonza/RsyncWrap
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.15
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Rsync wrapper library
45
+ test_files: []