backup 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/lib/backup/archive.rb +20 -1
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +42 -5
- metadata +2 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/lib/backup/archive.rb
CHANGED
@@ -12,6 +12,10 @@ module Backup
|
|
12
12
|
# Stores an array of different paths/files to store
|
13
13
|
attr_accessor :paths
|
14
14
|
|
15
|
+
##
|
16
|
+
# Stores an array of different paths/files to exclude
|
17
|
+
attr_accessor :excludes
|
18
|
+
|
15
19
|
##
|
16
20
|
# Stores the path to the archive directory
|
17
21
|
attr_accessor :archive_path
|
@@ -21,6 +25,7 @@ module Backup
|
|
21
25
|
def initialize(name, &block)
|
22
26
|
@name = name.to_sym
|
23
27
|
@paths = Array.new
|
28
|
+
@excludes = Array.new
|
24
29
|
@archive_path = File.join(TMP_PATH, TRIGGER, 'archive')
|
25
30
|
|
26
31
|
instance_eval(&block)
|
@@ -32,13 +37,19 @@ module Backup
|
|
32
37
|
@paths << path
|
33
38
|
end
|
34
39
|
|
40
|
+
##
|
41
|
+
# Adds new paths to the @excludes instance variable array
|
42
|
+
def exclude(path)
|
43
|
+
@excludes << path
|
44
|
+
end
|
45
|
+
|
35
46
|
##
|
36
47
|
# Archives all the provided paths in to a single .tar file
|
37
48
|
# and places that .tar file in the folder which later will be packaged
|
38
49
|
def perform!
|
39
50
|
mkdir(archive_path)
|
40
51
|
Logger.message("#{ self.class } started packaging and archiving #{ paths.map { |path| "\"#{path}\""}.join(", ") }.")
|
41
|
-
run("#{ utility(:tar) } -c #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
|
52
|
+
run("#{ utility(:tar) } -c #{ paths_to_exclude } #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
|
42
53
|
end
|
43
54
|
|
44
55
|
private
|
@@ -50,5 +61,13 @@ module Backup
|
|
50
61
|
"'#{path}'"
|
51
62
|
end.join("\s")
|
52
63
|
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Returns a "tar-ready" string of all the specified excludes combined
|
67
|
+
def paths_to_exclude
|
68
|
+
if excludes.any?
|
69
|
+
"--exclude={" + excludes.map{ |e| "'#{e}'" }.join(",") + "}"
|
70
|
+
end
|
71
|
+
end
|
53
72
|
end
|
54
73
|
end
|
data/lib/backup/version.rb
CHANGED
data/spec/archive_spec.rb
CHANGED
@@ -9,6 +9,8 @@ describe Backup::Archive do
|
|
9
9
|
a.add '/home/rspecuser/somefile'
|
10
10
|
a.add '/home/rspecuser/logs/'
|
11
11
|
a.add '/home/rspecuser/dotfiles/'
|
12
|
+
a.exclude '/home/rspecuser/excludefile'
|
13
|
+
a.exclude '/home/rspecuser/excludedir/'
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -17,10 +19,19 @@ describe Backup::Archive do
|
|
17
19
|
archive.paths.count.should == 0
|
18
20
|
end
|
19
21
|
|
22
|
+
it 'should have no excludes' do
|
23
|
+
archive = Backup::Archive.new(:dummy_archive) { |a| }
|
24
|
+
archive.excludes.count.should == 0
|
25
|
+
end
|
26
|
+
|
20
27
|
it 'should have 3 paths' do
|
21
28
|
archive.paths.count.should == 3
|
22
29
|
end
|
23
30
|
|
31
|
+
it 'should have 2 excludes' do
|
32
|
+
archive.excludes.count.should == 2
|
33
|
+
end
|
34
|
+
|
24
35
|
it do
|
25
36
|
archive.name.should == :dummy_archive
|
26
37
|
end
|
@@ -32,17 +43,43 @@ describe Backup::Archive do
|
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
46
|
+
describe '#paths_to_exclude' do
|
47
|
+
it 'should be empty' do
|
48
|
+
archive = Backup::Archive.new(:dummy_archive) { |a| }
|
49
|
+
archive.send(:paths_to_exclude).should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should return a tar -c friendly string' do
|
53
|
+
archive.send(:paths_to_exclude).should ==
|
54
|
+
"--exclude={'/home/rspecuser/excludefile','/home/rspecuser/excludedir/'}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
35
58
|
describe '#perform!' do
|
36
59
|
before do
|
37
60
|
[:mkdir, :run, :utility].each { |method| archive.stubs(method) }
|
38
61
|
Backup::Logger.stubs(:message)
|
39
62
|
end
|
40
63
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
64
|
+
context 'when both paths were added and paths that should be excluded were added' do
|
65
|
+
it 'should render both the syntax for the paths that be included as well as excluded' do
|
66
|
+
archive.expects(:mkdir).with(File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive'))
|
67
|
+
archive.expects(:run).with("tar -c --exclude={'/home/rspecuser/excludefile','/home/rspecuser/excludedir/'} '/home/rspecuser/somefile' '/home/rspecuser/logs/' '/home/rspecuser/dotfiles/' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
|
68
|
+
archive.expects(:utility).with(:tar).returns(:tar)
|
69
|
+
archive.perform!
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when there are paths to add, and no exclude patterns were defined' do
|
74
|
+
it 'should only render syntax for the defined paths' do
|
75
|
+
archive = Backup::Archive.new(:dummy_archive) do |a|
|
76
|
+
a.add '/path/to/archive'
|
77
|
+
end
|
78
|
+
|
79
|
+
archive.stubs(:utility).returns(:tar)
|
80
|
+
archive.expects(:run).with("tar -c '/path/to/archive' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
|
81
|
+
archive.perform!
|
82
|
+
end
|
46
83
|
end
|
47
84
|
|
48
85
|
it 'should log the status' do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 3.0.
|
5
|
+
version: 3.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael van Rooijen
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-14 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|