robinsp-backitup 0.0.2 → 0.0.3
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.
- data/Manifest +13 -11
- data/README.rdoc +4 -1
- data/Rakefile +1 -1
- data/backitup.gemspec +6 -6
- data/lib/back_it_up.rb +13 -0
- data/lib/back_it_up/config.rb +13 -1
- data/lib/back_it_up/ftp.rb +18 -0
- data/lib/back_it_up/runner.rb +8 -1
- data/sample.backitup +2 -4
- data/spec/config_spec.rb +27 -0
- data/spec/ftp_spec.rb +51 -0
- data/spec/runner_spec.rb +10 -1
- metadata +20 -17
data/Manifest
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
bin/backitup
|
2
1
|
sample.backitup
|
3
|
-
spec/test-config.backitup
|
4
|
-
spec/file_packager_spec.rb
|
5
|
-
spec/config_spec.rb
|
6
|
-
spec/runner_spec.rb
|
7
|
-
spec/file_list_spec.rb
|
8
|
-
spec/spec.opts
|
9
|
-
spec/spec_helper.rb
|
10
|
-
Rakefile
|
11
2
|
lib/back_it_up.rb
|
12
3
|
lib/back_it_up/config.rb
|
4
|
+
lib/back_it_up/runner.rb
|
5
|
+
lib/back_it_up/command.rb
|
6
|
+
lib/back_it_up/ftp.rb
|
13
7
|
lib/back_it_up/file_list.rb
|
14
8
|
lib/back_it_up/file_packager.rb
|
15
|
-
lib/back_it_up/command.rb
|
16
|
-
lib/back_it_up/runner.rb
|
17
9
|
README.rdoc
|
10
|
+
Rakefile
|
11
|
+
spec/test-config.backitup
|
12
|
+
spec/file_list_spec.rb
|
13
|
+
spec/spec_helper.rb
|
14
|
+
spec/runner_spec.rb
|
15
|
+
spec/spec.opts
|
16
|
+
spec/file_packager_spec.rb
|
17
|
+
spec/ftp_spec.rb
|
18
|
+
spec/config_spec.rb
|
19
|
+
bin/backitup
|
18
20
|
Manifest
|
data/README.rdoc
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
= BackItUp
|
2
2
|
|
3
|
-
|
3
|
+
Simple tool to easily configure the files and directories to copy to a local zip file
|
4
|
+
and FTP (optional) to a remote host.
|
4
5
|
|
5
6
|
== Install
|
6
7
|
|
@@ -29,6 +30,8 @@ Create a backup script looking something like this
|
|
29
30
|
dir "~/Desktop/drop-in-me-for-backup"
|
30
31
|
|
31
32
|
destination_file "/tmp/backupfile"
|
33
|
+
|
34
|
+
ftp 'host.domain.com', 'username', 'password', :remote_dir => 'backups'
|
32
35
|
end
|
33
36
|
|
34
37
|
Run *backitup* with your script file as argument
|
data/Rakefile
CHANGED
data/backitup.gemspec
CHANGED
@@ -2,28 +2,28 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{backitup}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Robin Spainhour"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-29}
|
10
10
|
s.default_executable = %q{backitup}
|
11
11
|
s.description = %q{Simple backup tool}
|
12
12
|
s.email = %q{robin@robinspainhour.com}
|
13
13
|
s.executables = ["backitup"]
|
14
|
-
s.extra_rdoc_files = ["
|
15
|
-
s.files = ["
|
14
|
+
s.extra_rdoc_files = ["lib/back_it_up.rb", "lib/back_it_up/config.rb", "lib/back_it_up/runner.rb", "lib/back_it_up/command.rb", "lib/back_it_up/ftp.rb", "lib/back_it_up/file_list.rb", "lib/back_it_up/file_packager.rb", "README.rdoc", "bin/backitup"]
|
15
|
+
s.files = ["sample.backitup", "lib/back_it_up.rb", "lib/back_it_up/config.rb", "lib/back_it_up/runner.rb", "lib/back_it_up/command.rb", "lib/back_it_up/ftp.rb", "lib/back_it_up/file_list.rb", "lib/back_it_up/file_packager.rb", "README.rdoc", "Rakefile", "spec/test-config.backitup", "spec/file_list_spec.rb", "spec/spec_helper.rb", "spec/runner_spec.rb", "spec/spec.opts", "spec/file_packager_spec.rb", "spec/ftp_spec.rb", "spec/config_spec.rb", "bin/backitup", "Manifest", "backitup.gemspec"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/robinsp/backitup}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Backitup", "--main", "README.rdoc"]
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
s.rubyforge_project = %q{backitup}
|
21
|
-
s.rubygems_version = %q{1.3.
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
22
|
s.summary = %q{Simple backup tool}
|
23
23
|
|
24
24
|
if s.respond_to? :specification_version then
|
25
25
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
-
s.specification_version =
|
26
|
+
s.specification_version = 2
|
27
27
|
|
28
28
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
29
|
s.add_runtime_dependency(%q<rubyzip>, [">= 0"])
|
data/lib/back_it_up.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
|
+
class NilClass
|
2
|
+
def blank?
|
3
|
+
true
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class String
|
8
|
+
def blank?
|
9
|
+
(self == nil || self == "")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
1
13
|
require 'back_it_up/runner'
|
2
14
|
require 'back_it_up/config'
|
3
15
|
require 'back_it_up/file_packager'
|
4
16
|
require 'back_it_up/file_list'
|
17
|
+
require 'back_it_up/ftp'
|
data/lib/back_it_up/config.rb
CHANGED
@@ -17,6 +17,18 @@ module BackItUp
|
|
17
17
|
# in the <tt>~/Desktop/drop-in-me-for-backup</tt> directory and its sub dirs, and
|
18
18
|
# place them in <tt>/tmp/backupfile_[date]_time.zip</tt>.
|
19
19
|
module ScriptDSL
|
20
|
+
INVALID_FTP_ARG_MSG = "Invalid arguments for ftp"
|
21
|
+
|
22
|
+
# After packaging backup set send the file to this server.
|
23
|
+
#
|
24
|
+
# Options:
|
25
|
+
# <tt>:remote_dir</tt> Remote directory on FTP host
|
26
|
+
#
|
27
|
+
def ftp(host, user, passwd, options = {} )
|
28
|
+
raise INVALID_FTP_ARG_MSG if host.blank? || user.blank? || passwd.blank?
|
29
|
+
|
30
|
+
@ftp_options = options.merge( {:user => user, :host => host, :passwd => passwd } )
|
31
|
+
end
|
20
32
|
|
21
33
|
# Starts off the backup script.
|
22
34
|
#
|
@@ -77,7 +89,7 @@ module BackItUp
|
|
77
89
|
|
78
90
|
class Config
|
79
91
|
include ScriptDSL
|
80
|
-
attr_reader :files, :dirs, :dest_filename
|
92
|
+
attr_reader :files, :dirs, :dest_filename, :ftp_options
|
81
93
|
|
82
94
|
def initialize(file_handle)
|
83
95
|
@files = []
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
|
3
|
+
module BackItUp
|
4
|
+
class Ftp
|
5
|
+
def initialize(options)
|
6
|
+
raise "No options" if options == nil || options.empty?
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def transfer(filename)
|
11
|
+
Net::FTP.open(@options[:host]) do |ftp|
|
12
|
+
ftp.login(@options[:user], @options[:passwd] )
|
13
|
+
ftp.chdir(@options[:remote_dir]) if @options[:remote_dir]
|
14
|
+
ftp.putbinaryfile(filename)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/back_it_up/runner.rb
CHANGED
@@ -5,7 +5,14 @@ module BackItUp
|
|
5
5
|
|
6
6
|
file = File.open(filename)
|
7
7
|
config = Config.new(file)
|
8
|
-
|
8
|
+
packaged_filename = FilePackager.new(config).package
|
9
|
+
puts "Wrote backup to: #{ packaged_filename }."
|
10
|
+
|
11
|
+
if config.ftp_options
|
12
|
+
BackItUp::Ftp.new(config.ftp_options).transfer(packaged_filename)
|
13
|
+
puts "Tranferred to FTP host."
|
14
|
+
end
|
15
|
+
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
data/sample.backitup
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -134,6 +134,33 @@ describe BackItUp::Config do
|
|
134
134
|
@config.dirs.pop.should == @valid_file
|
135
135
|
end
|
136
136
|
end
|
137
|
+
|
138
|
+
describe "ftp()" do
|
139
|
+
it "should require host" do
|
140
|
+
lambda{ @config.ftp("", "string", "string") }.should raise_error(BackItUp::ScriptDSL::INVALID_FTP_ARG_MSG)
|
141
|
+
end
|
142
|
+
it "should require username" do
|
143
|
+
lambda{ @config.ftp("string", "", "string") }.should raise_error(BackItUp::ScriptDSL::INVALID_FTP_ARG_MSG)
|
144
|
+
end
|
145
|
+
it "should require password" do
|
146
|
+
lambda{ @config.ftp("string", "string", "") }.should raise_error(BackItUp::ScriptDSL::INVALID_FTP_ARG_MSG)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should save args to ftp_options attribute" do
|
150
|
+
@config.ftp("host", "user", "passwd")
|
151
|
+
@config.ftp_options.should == {:user => "user", :passwd => "passwd", :host => "host"}
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should save options when given" do
|
155
|
+
@config.ftp("host", "user", "passwd", :an_option => "the_option")
|
156
|
+
@config.ftp_options.should == {:user => "user", :passwd => "passwd", :host => "host", :an_option => "the_option"}
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should not override host, user and passwd args when these are given in options" do
|
160
|
+
@config.ftp("host", "user", "passwd", :user => "user1", :passwd => "passwd1", :host => "host1")
|
161
|
+
@config.ftp_options.should == {:user => "user", :passwd => "passwd", :host => "host"}
|
162
|
+
end
|
163
|
+
end
|
137
164
|
end
|
138
165
|
|
139
166
|
end
|
data/spec/ftp_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe BackItUp::Ftp do
|
4
|
+
before do
|
5
|
+
@user = "username"
|
6
|
+
@passwd = "password"
|
7
|
+
@host = "hostname"
|
8
|
+
|
9
|
+
@options = {:user => @user, :host => @host, :passwd => @passwd}
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "constructor" do
|
13
|
+
it "should require options" do
|
14
|
+
lambda {BackItUp::Ftp.new(nil) }.should raise_error
|
15
|
+
lambda {BackItUp::Ftp.new({}) }.should raise_error
|
16
|
+
lambda {BackItUp::Ftp.new(@options) }.should_not raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "transfer()" do
|
21
|
+
before do
|
22
|
+
@filename = "thefilename"
|
23
|
+
@mock_ftp = stub("mock-ftp", :login => "", :putbinaryfile => "")
|
24
|
+
|
25
|
+
Net::FTP.stubs(:open).with(@host).yields(@mock_ftp)
|
26
|
+
@ftp = BackItUp::Ftp.new(@options)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should open host" do
|
30
|
+
Net::FTP.expects(:open).with(@host)
|
31
|
+
@ftp.transfer(@filename)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should login" do
|
35
|
+
@mock_ftp.expects(:login).with(@user, @passwd)
|
36
|
+
@ftp.transfer(@filename)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should put binary file" do
|
40
|
+
@mock_ftp.expects(:putbinaryfile).with(@filename)
|
41
|
+
@ftp.transfer(@filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should change directory if option is set" do
|
45
|
+
dirname = "remote-directory"
|
46
|
+
@mock_ftp.expects(:chdir).with(dirname)
|
47
|
+
ftp = BackItUp::Ftp.new( @options.merge(:remote_dir => dirname) )
|
48
|
+
ftp.transfer(@filename)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/runner_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe BackItUp::Runner do
|
|
17
17
|
@file = mock('fake file handle')
|
18
18
|
File.stubs(:open).with(@filename).returns(@file)
|
19
19
|
|
20
|
-
@mock_config =
|
20
|
+
@mock_config = stub('mock-config', :ftp_options => nil)
|
21
21
|
BackItUp::Config.stubs(:new).returns(@mock_config)
|
22
22
|
|
23
23
|
@mock_packager
|
@@ -46,6 +46,15 @@ describe BackItUp::Runner do
|
|
46
46
|
BackItUp::Runner.new(@filename)
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should transfer packaged file if ftp is configured" do
|
50
|
+
ftp_config = {:ftp => "config"}
|
51
|
+
@mock_config.stubs(:ftp_options).returns(ftp_config)
|
52
|
+
ftp = mock('ftp')
|
53
|
+
BackItUp::Ftp.expects(:new).with(ftp_config).returns(ftp)
|
54
|
+
ftp.expects(:transfer).with(@package_result_filename)
|
55
|
+
BackItUp::Runner.new(@filename)
|
56
|
+
end
|
57
|
+
|
49
58
|
end
|
50
59
|
|
51
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robinsp-backitup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin Spainhour
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-29 00:00:00 -07:00
|
13
13
|
default_executable: backitup
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -29,32 +29,35 @@ executables:
|
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
|
-
- bin/backitup
|
33
32
|
- lib/back_it_up.rb
|
34
33
|
- lib/back_it_up/config.rb
|
34
|
+
- lib/back_it_up/runner.rb
|
35
|
+
- lib/back_it_up/command.rb
|
36
|
+
- lib/back_it_up/ftp.rb
|
35
37
|
- lib/back_it_up/file_list.rb
|
36
38
|
- lib/back_it_up/file_packager.rb
|
37
|
-
- lib/back_it_up/command.rb
|
38
|
-
- lib/back_it_up/runner.rb
|
39
39
|
- README.rdoc
|
40
|
-
files:
|
41
40
|
- bin/backitup
|
41
|
+
files:
|
42
42
|
- sample.backitup
|
43
|
-
- spec/test-config.backitup
|
44
|
-
- spec/file_packager_spec.rb
|
45
|
-
- spec/config_spec.rb
|
46
|
-
- spec/runner_spec.rb
|
47
|
-
- spec/file_list_spec.rb
|
48
|
-
- spec/spec.opts
|
49
|
-
- spec/spec_helper.rb
|
50
|
-
- Rakefile
|
51
43
|
- lib/back_it_up.rb
|
52
44
|
- lib/back_it_up/config.rb
|
45
|
+
- lib/back_it_up/runner.rb
|
46
|
+
- lib/back_it_up/command.rb
|
47
|
+
- lib/back_it_up/ftp.rb
|
53
48
|
- lib/back_it_up/file_list.rb
|
54
49
|
- lib/back_it_up/file_packager.rb
|
55
|
-
- lib/back_it_up/command.rb
|
56
|
-
- lib/back_it_up/runner.rb
|
57
50
|
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- spec/test-config.backitup
|
53
|
+
- spec/file_list_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/runner_spec.rb
|
56
|
+
- spec/spec.opts
|
57
|
+
- spec/file_packager_spec.rb
|
58
|
+
- spec/ftp_spec.rb
|
59
|
+
- spec/config_spec.rb
|
60
|
+
- bin/backitup
|
58
61
|
- Manifest
|
59
62
|
- backitup.gemspec
|
60
63
|
has_rdoc: true
|
@@ -86,7 +89,7 @@ requirements: []
|
|
86
89
|
rubyforge_project: backitup
|
87
90
|
rubygems_version: 1.2.0
|
88
91
|
signing_key:
|
89
|
-
specification_version:
|
92
|
+
specification_version: 2
|
90
93
|
summary: Simple backup tool
|
91
94
|
test_files: []
|
92
95
|
|