robinsp-backitup 0.0.1 → 0.0.2
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 +5 -1
- data/README.rdoc +37 -0
- data/Rakefile +2 -2
- data/backitup.gemspec +7 -7
- data/lib/back_it_up/config.rb +71 -27
- data/lib/back_it_up/file_list.rb +19 -0
- data/lib/back_it_up/file_packager.rb +15 -9
- data/lib/back_it_up.rb +1 -0
- data/sample.backitup +11 -0
- data/spec/config_spec.rb +35 -0
- data/spec/file_list_spec.rb +21 -0
- data/spec/file_packager_spec.rb +12 -10
- metadata +13 -5
data/Manifest
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
bin/backitup
|
2
|
+
sample.backitup
|
2
3
|
spec/test-config.backitup
|
3
4
|
spec/file_packager_spec.rb
|
4
5
|
spec/config_spec.rb
|
5
6
|
spec/runner_spec.rb
|
7
|
+
spec/file_list_spec.rb
|
6
8
|
spec/spec.opts
|
7
9
|
spec/spec_helper.rb
|
8
10
|
Rakefile
|
9
|
-
Manifest
|
10
11
|
lib/back_it_up.rb
|
11
12
|
lib/back_it_up/config.rb
|
13
|
+
lib/back_it_up/file_list.rb
|
12
14
|
lib/back_it_up/file_packager.rb
|
13
15
|
lib/back_it_up/command.rb
|
14
16
|
lib/back_it_up/runner.rb
|
17
|
+
README.rdoc
|
18
|
+
Manifest
|
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= BackItUp
|
2
|
+
|
3
|
+
<em>This is still in the workings and right now it is only an advanced zip file creator.</em>
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
Add GitHub to your gem sources if you haven't already:
|
8
|
+
|
9
|
+
$ sudo gem sources -a http://gems.github.com
|
10
|
+
|
11
|
+
Install the gem:
|
12
|
+
|
13
|
+
$ sudo gem install robinsp-backitup
|
14
|
+
|
15
|
+
This should have installed the _backitup_ command. Running
|
16
|
+
|
17
|
+
$ backitup
|
18
|
+
|
19
|
+
...should print the usage instructions if everything is set up ok.
|
20
|
+
|
21
|
+
== Usage
|
22
|
+
|
23
|
+
Create a backup script looking something like this
|
24
|
+
|
25
|
+
# sample.backitup
|
26
|
+
backup do
|
27
|
+
file '/home/robin/backup.this.file'
|
28
|
+
|
29
|
+
dir "~/Desktop/drop-in-me-for-backup"
|
30
|
+
|
31
|
+
destination_file "/tmp/backupfile"
|
32
|
+
end
|
33
|
+
|
34
|
+
Run *backitup* with your script file as argument
|
35
|
+
|
36
|
+
$ backitup sample.backitup
|
37
|
+
|
data/Rakefile
CHANGED
@@ -2,8 +2,8 @@ require 'spec'
|
|
2
2
|
require 'spec/rake/spectask'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('backitup', '0.0.
|
6
|
-
p.description = "Simple backup"
|
5
|
+
Echoe.new('backitup', '0.0.2') do |p|
|
6
|
+
p.description = "Simple backup tool"
|
7
7
|
p.url = "http://github.com/robinsp/backitup"
|
8
8
|
p.author = "Robin Spainhour"
|
9
9
|
p.email = "robin@robinspainhour.com"
|
data/backitup.gemspec
CHANGED
@@ -2,24 +2,24 @@
|
|
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.2"
|
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-28}
|
10
10
|
s.default_executable = %q{backitup}
|
11
|
-
s.description = %q{Simple backup}
|
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 = ["bin/backitup", "lib/back_it_up.rb", "lib/back_it_up/config.rb", "lib/back_it_up/file_packager.rb", "lib/back_it_up/command.rb", "lib/back_it_up/runner.rb"]
|
15
|
-
s.files = ["bin/backitup", "spec/test-config.backitup", "spec/file_packager_spec.rb", "spec/config_spec.rb", "spec/runner_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Rakefile", "
|
14
|
+
s.extra_rdoc_files = ["bin/backitup", "lib/back_it_up.rb", "lib/back_it_up/config.rb", "lib/back_it_up/file_list.rb", "lib/back_it_up/file_packager.rb", "lib/back_it_up/command.rb", "lib/back_it_up/runner.rb", "README.rdoc"]
|
15
|
+
s.files = ["bin/backitup", "sample.backitup", "spec/test-config.backitup", "spec/file_packager_spec.rb", "spec/config_spec.rb", "spec/runner_spec.rb", "spec/file_list_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Rakefile", "lib/back_it_up.rb", "lib/back_it_up/config.rb", "lib/back_it_up/file_list.rb", "lib/back_it_up/file_packager.rb", "lib/back_it_up/command.rb", "lib/back_it_up/runner.rb", "README.rdoc", "Manifest", "backitup.gemspec"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/robinsp/backitup}
|
18
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Backitup"]
|
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
21
|
s.rubygems_version = %q{1.3.2}
|
22
|
-
s.summary = %q{Simple backup}
|
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
|
data/lib/back_it_up/config.rb
CHANGED
@@ -1,23 +1,62 @@
|
|
1
1
|
module BackItUp
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
# The backup script should look something like this
|
4
|
+
#
|
5
|
+
# # sample.backitup
|
6
|
+
#
|
7
|
+
# backup do
|
8
|
+
#
|
9
|
+
# file '/home/robin/backup.this.file'
|
10
|
+
#
|
11
|
+
# dir '~/Desktop/drop-in-me-for-backup'
|
12
|
+
#
|
13
|
+
# destination_file "/tmp/backupfile"
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# This will backup the file <tt>/home/robin/backup.this.file</tt> and all the files
|
17
|
+
# in the <tt>~/Desktop/drop-in-me-for-backup</tt> directory and its sub dirs, and
|
18
|
+
# place them in <tt>/tmp/backupfile_[date]_time.zip</tt>.
|
19
|
+
module ScriptDSL
|
4
20
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
21
|
+
# Starts off the backup script.
|
22
|
+
#
|
23
|
+
# Usage:
|
24
|
+
#
|
25
|
+
# backup do
|
26
|
+
# # add your files, dirs etc. here...
|
27
|
+
# end
|
28
|
+
def backup
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
|
32
|
+
# File or directory name to add to the backup set. The given file name is expanded before
|
33
|
+
# added to the backup set.
|
34
|
+
#
|
35
|
+
# It is safer to use single quotes (especially on Windows file systems) as the support
|
36
|
+
# for escape sequences is not as great as double-quoted strings.
|
37
|
+
#
|
38
|
+
# file '~/importantfile' # is safer
|
39
|
+
# file "~/anotherfile" # ...than this
|
40
|
+
#
|
41
|
+
def file(filename = nil)
|
42
|
+
unless (filename == "" || filename == nil)
|
43
|
+
full_name = File.expand_path(filename)
|
44
|
+
|
45
|
+
if File.exists?(full_name)
|
46
|
+
if File.directory? full_name
|
47
|
+
@dirs << full_name
|
48
|
+
else
|
49
|
+
@files << full_name
|
50
|
+
end
|
51
|
+
|
52
|
+
else
|
53
|
+
puts "WARNING: File #{filename} could not be found"
|
54
|
+
end
|
13
55
|
end
|
14
56
|
|
15
|
-
eval(file_content)
|
16
57
|
end
|
17
58
|
|
18
|
-
|
19
|
-
yield
|
20
|
-
end
|
59
|
+
alias_method :dir, :file
|
21
60
|
|
22
61
|
# Full path and name of the package file to create.
|
23
62
|
# A timestamp will be appended to the filename and the extension is
|
@@ -33,23 +72,28 @@ module BackItUp
|
|
33
72
|
@dest_filename = filename
|
34
73
|
end
|
35
74
|
|
36
|
-
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
class Config
|
79
|
+
include ScriptDSL
|
80
|
+
attr_reader :files, :dirs, :dest_filename
|
81
|
+
|
82
|
+
def initialize(file_handle)
|
83
|
+
@files = []
|
84
|
+
@dirs = []
|
85
|
+
|
86
|
+
file_content = ""
|
37
87
|
|
38
|
-
|
39
|
-
|
40
|
-
if File.directory? filename
|
41
|
-
@dirs << filename
|
42
|
-
else
|
43
|
-
@files << filename
|
44
|
-
end
|
45
|
-
|
46
|
-
else
|
47
|
-
puts "WARNING: File #{filename} could not be found"
|
48
|
-
end
|
88
|
+
while l = file_handle.gets do
|
89
|
+
file_content << l
|
49
90
|
end
|
50
91
|
|
92
|
+
eval(file_content)
|
51
93
|
end
|
52
94
|
|
53
|
-
|
95
|
+
def each_file
|
96
|
+
FileList.new(@files, @dirs).files.each {|filename| yield filename }
|
97
|
+
end
|
54
98
|
end
|
55
99
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'find'
|
2
|
+
|
3
|
+
module BackItUp
|
4
|
+
class FileList
|
5
|
+
attr_reader :files
|
6
|
+
|
7
|
+
def initialize(files, dirs)
|
8
|
+
@files = []
|
9
|
+
files.each {|f| @files << f }
|
10
|
+
|
11
|
+
dirs.each do |d|
|
12
|
+
Find.find(d) do |f|
|
13
|
+
next if File.directory?(f)
|
14
|
+
@files << f
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -12,25 +12,31 @@ module BackItUp
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def package
|
15
|
-
target_filename = create_target_filename
|
16
|
-
|
17
|
-
prefix = File.basename(target_filename, ".zip")
|
18
|
-
|
19
15
|
Zip::ZipFile.open(target_filename, Zip::ZipFile::CREATE) do |zip|
|
20
|
-
@config.
|
21
|
-
zip.add("./#{prefix}#{filename}", filename)
|
22
|
-
end
|
16
|
+
@config.each_file { |filename| zip.add( zip_entry_name(filename), filename ) }
|
23
17
|
end
|
24
18
|
|
25
19
|
@produced_file = target_filename
|
26
20
|
end
|
27
21
|
|
28
22
|
protected
|
29
|
-
def
|
30
|
-
@config.dest_filename + "_#{timestamp}" + ".zip"
|
23
|
+
def target_filename
|
24
|
+
@target_filename ||= @config.dest_filename + "_#{timestamp}" + ".zip"
|
31
25
|
end
|
32
26
|
|
33
27
|
private
|
28
|
+
def zip_entry_name(filename)
|
29
|
+
zip_entry_prefix + replace_win_drive_letter_in(filename)
|
30
|
+
end
|
31
|
+
|
32
|
+
def replace_win_drive_letter_in(filename)
|
33
|
+
filename.gsub(/^(.):/, '/\1_drive')
|
34
|
+
end
|
35
|
+
|
36
|
+
def zip_entry_prefix
|
37
|
+
@prefix ||= File.basename(target_filename, ".zip")
|
38
|
+
end
|
39
|
+
|
34
40
|
def timestamp
|
35
41
|
Time.now.strftime("%Y%m%d_%H%M%S")
|
36
42
|
end
|
data/lib/back_it_up.rb
CHANGED
data/sample.backitup
ADDED
data/spec/config_spec.rb
CHANGED
@@ -16,6 +16,7 @@ describe BackItUp::Config do
|
|
16
16
|
BackItUp::Config.new(File.open(test_file))
|
17
17
|
end
|
18
18
|
|
19
|
+
|
19
20
|
describe "" do
|
20
21
|
before do
|
21
22
|
mock_file = mock('mock-file')
|
@@ -31,6 +32,32 @@ describe BackItUp::Config do
|
|
31
32
|
@config.dirs.should == []
|
32
33
|
end
|
33
34
|
|
35
|
+
describe "each_file()" do
|
36
|
+
before do
|
37
|
+
@mock_file_list = mock("FileList")
|
38
|
+
@mock_file_list.stubs(:files).returns([])
|
39
|
+
BackItUp::FileList.stubs(:new).returns(@mock_file_list)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create FileList" do
|
43
|
+
BackItUp::FileList.expects(:new).with(@config.files, @config.dirs).returns(@mock_file_list)
|
44
|
+
@config.each_file
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should yield all files in FileList" do
|
48
|
+
expected_files = ["file_one", "file_two", "file_three"]
|
49
|
+
|
50
|
+
@mock_file_list.expects(:files).returns(expected_files)
|
51
|
+
|
52
|
+
result = []
|
53
|
+
@config.each_file do |f|
|
54
|
+
result << f
|
55
|
+
end
|
56
|
+
|
57
|
+
result.should == expected_files
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
34
61
|
describe "destination_file()" do
|
35
62
|
|
36
63
|
it "should save the filename to dest_filename attribute" do
|
@@ -68,6 +95,13 @@ describe BackItUp::Config do
|
|
68
95
|
@config.file(file_name)
|
69
96
|
end
|
70
97
|
|
98
|
+
it "should expand paths" do
|
99
|
+
File.stubs(:exists?).returns(true)
|
100
|
+
File.expects(:expand_path).with("filename").returns("expanded_filename")
|
101
|
+
@config.file("filename")
|
102
|
+
@config.files.pop.should == "expanded_filename"
|
103
|
+
end
|
104
|
+
|
71
105
|
it "should not add non-existning files to files attribute" do
|
72
106
|
file_name = "should-not-exist"
|
73
107
|
@config.file(file_name)
|
@@ -79,6 +113,7 @@ describe BackItUp::Config do
|
|
79
113
|
end
|
80
114
|
|
81
115
|
it "should check if file exists" do
|
116
|
+
File.stubs(:expand_path).with("filename").returns("filename")
|
82
117
|
File.expects(:exists?).with("filename").returns(false)
|
83
118
|
@config.file("filename")
|
84
119
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe BackItUp::FileList do
|
4
|
+
|
5
|
+
it "should add files passed to initialize to files attribute" do
|
6
|
+
expected_files = %w{one two three}
|
7
|
+
list = BackItUp::FileList.new(expected_files, [] )
|
8
|
+
list.files.should == expected_files
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should find all files in dirs passed to initilizer and add to files attribute" do
|
12
|
+
dirs = %w{dir_one dir_two dir_three}
|
13
|
+
Find.expects(:find).times(3).with { |d| dirs.include? d }.yields("one").then.yields("two").then.yields("three")
|
14
|
+
File.expects(:directory?).times(3).returns(false)
|
15
|
+
|
16
|
+
list = BackItUp::FileList.new([], dirs)
|
17
|
+
|
18
|
+
list.files.should == %w{one two three}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/file_packager_spec.rb
CHANGED
@@ -14,19 +14,18 @@ describe BackItUp::FilePackager do
|
|
14
14
|
describe "package()" do
|
15
15
|
before do
|
16
16
|
@first_file_to_add = "/etc/passwd"
|
17
|
-
@second_file_to_add = "/etc/httpd/apache.cfg"
|
18
17
|
|
19
18
|
@configured_dst_filename = "/backups/a-file-name"
|
20
|
-
mock_config = mock
|
21
|
-
mock_config.stubs(:is_a? => true)
|
22
|
-
mock_config.stubs(:dest_filename).returns(@configured_dst_filename)
|
23
|
-
mock_config.stubs(:
|
19
|
+
@mock_config = mock
|
20
|
+
@mock_config.stubs(:is_a? => true)
|
21
|
+
@mock_config.stubs(:dest_filename).returns(@configured_dst_filename)
|
22
|
+
@mock_config.stubs(:each_file).yields(@first_file_to_add)
|
24
23
|
|
25
24
|
@mock_zip = mock("mock-zip")
|
26
25
|
@mock_zip.stubs(:add)
|
27
26
|
Zip::ZipFile.stubs(:open).yields(@mock_zip)
|
28
27
|
|
29
|
-
@packager = BackItUp::FilePackager.new(mock_config)
|
28
|
+
@packager = BackItUp::FilePackager.new(@mock_config)
|
30
29
|
|
31
30
|
end
|
32
31
|
|
@@ -55,11 +54,14 @@ describe BackItUp::FilePackager do
|
|
55
54
|
end
|
56
55
|
|
57
56
|
it "should add files to the zip" do
|
58
|
-
prefix = "
|
59
|
-
|
57
|
+
prefix = "#{File.basename(@configured_dst_filename)}"
|
60
58
|
@mock_zip.expects(:add).with( regexp_matches(/^#{prefix}.*#{@first_file_to_add}$/), @first_file_to_add )
|
61
|
-
@
|
62
|
-
|
59
|
+
@packager.package
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should strip the drive letter for windows files added to zip" do
|
63
|
+
@mock_config.stubs(:each_file).yields("C:\temp\myfile")
|
64
|
+
@mock_zip.expects(:add).with( regexp_matches(/\/C_drive/), regexp_matches(/.*/) )
|
63
65
|
@packager.package
|
64
66
|
end
|
65
67
|
|
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.2
|
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-28 00:00:00 -07:00
|
13
13
|
default_executable: backitup
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
-
description: Simple backup
|
25
|
+
description: Simple backup tool
|
26
26
|
email: robin@robinspainhour.com
|
27
27
|
executables:
|
28
28
|
- backitup
|
@@ -32,24 +32,30 @@ extra_rdoc_files:
|
|
32
32
|
- bin/backitup
|
33
33
|
- lib/back_it_up.rb
|
34
34
|
- lib/back_it_up/config.rb
|
35
|
+
- lib/back_it_up/file_list.rb
|
35
36
|
- lib/back_it_up/file_packager.rb
|
36
37
|
- lib/back_it_up/command.rb
|
37
38
|
- lib/back_it_up/runner.rb
|
39
|
+
- README.rdoc
|
38
40
|
files:
|
39
41
|
- bin/backitup
|
42
|
+
- sample.backitup
|
40
43
|
- spec/test-config.backitup
|
41
44
|
- spec/file_packager_spec.rb
|
42
45
|
- spec/config_spec.rb
|
43
46
|
- spec/runner_spec.rb
|
47
|
+
- spec/file_list_spec.rb
|
44
48
|
- spec/spec.opts
|
45
49
|
- spec/spec_helper.rb
|
46
50
|
- Rakefile
|
47
|
-
- Manifest
|
48
51
|
- lib/back_it_up.rb
|
49
52
|
- lib/back_it_up/config.rb
|
53
|
+
- lib/back_it_up/file_list.rb
|
50
54
|
- lib/back_it_up/file_packager.rb
|
51
55
|
- lib/back_it_up/command.rb
|
52
56
|
- lib/back_it_up/runner.rb
|
57
|
+
- README.rdoc
|
58
|
+
- Manifest
|
53
59
|
- backitup.gemspec
|
54
60
|
has_rdoc: true
|
55
61
|
homepage: http://github.com/robinsp/backitup
|
@@ -59,6 +65,8 @@ rdoc_options:
|
|
59
65
|
- --inline-source
|
60
66
|
- --title
|
61
67
|
- Backitup
|
68
|
+
- --main
|
69
|
+
- README.rdoc
|
62
70
|
require_paths:
|
63
71
|
- lib
|
64
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -79,6 +87,6 @@ rubyforge_project: backitup
|
|
79
87
|
rubygems_version: 1.2.0
|
80
88
|
signing_key:
|
81
89
|
specification_version: 3
|
82
|
-
summary: Simple backup
|
90
|
+
summary: Simple backup tool
|
83
91
|
test_files: []
|
84
92
|
|