winton-rbackup 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +15 -6
- data/gemspec.rb +1 -1
- data/lib/rbackup.rb +58 -33
- data/rbackup.gemspec +4 -4
- data/spec/fixtures/rbackup.yml +15 -4
- data/spec/rbackup_spec.rb +16 -5
- metadata +3 -3
data/README.markdown
CHANGED
@@ -15,12 +15,16 @@ Create ~/.rbackup.yml
|
|
15
15
|
---------------------
|
16
16
|
|
17
17
|
<pre>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
usb:
|
19
|
+
documents:
|
20
|
+
source: ~/Documents
|
21
|
+
destination: /Volumes/USB Key
|
22
|
+
exclude:
|
23
|
+
- Software
|
24
|
+
- Virtual Machines.localized
|
25
|
+
pictures:
|
26
|
+
source: ~/Pictures
|
27
|
+
destination: /Volumes/USB Key
|
24
28
|
</pre>
|
25
29
|
|
26
30
|
Backup
|
@@ -28,4 +32,9 @@ Backup
|
|
28
32
|
|
29
33
|
<pre>
|
30
34
|
rbackup documents
|
35
|
+
// backs up documents
|
36
|
+
rbackup usb
|
37
|
+
// backs up documents and pictures
|
38
|
+
rbackup
|
39
|
+
// backs up all profiles
|
31
40
|
</pre>
|
data/gemspec.rb
CHANGED
data/lib/rbackup.rb
CHANGED
@@ -13,14 +13,11 @@ class RBackup
|
|
13
13
|
attr_accessor :profiles, :yaml
|
14
14
|
|
15
15
|
def initialize(*args)
|
16
|
-
|
17
|
-
|
18
|
-
if @profiles.empty?
|
19
|
-
@profiles = @yaml.keys
|
20
|
-
end
|
16
|
+
get_yaml
|
17
|
+
get_profiles(args, @yaml)
|
21
18
|
end
|
22
19
|
|
23
|
-
def
|
20
|
+
def get_yaml
|
24
21
|
if $TESTING
|
25
22
|
config = SPEC + '/fixtures/rbackup.yml'
|
26
23
|
else
|
@@ -45,37 +42,65 @@ class RBackup
|
|
45
42
|
paths.collect { |path| path.gsub(' ', '\ ') }.join(' ')
|
46
43
|
end
|
47
44
|
|
48
|
-
def
|
49
|
-
@profiles
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
def get_profiles(input, hash, force=false)
|
46
|
+
@profiles ||= []
|
47
|
+
hash.each do |key, value|
|
48
|
+
next unless value.respond_to?(:keys)
|
49
|
+
is_profile = value['source'] && value['destination']
|
50
|
+
if input.include?(key) || input.empty? || force
|
51
|
+
if is_profile
|
52
|
+
@profiles << value
|
53
|
+
else
|
54
|
+
get_profiles(input, value, true)
|
55
|
+
end
|
56
|
+
elsif !is_profile
|
57
|
+
get_profiles(input, value, force)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def rsync(profile)
|
63
|
+
destination = profile['destination']
|
64
|
+
source = profile['source'].to_a
|
54
65
|
|
55
|
-
|
66
|
+
FileUtils.mkdir_p destination
|
56
67
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
68
|
+
options = "--numeric-ids -axzSv"
|
69
|
+
# --numeric-ids don't map uid/gid values by user/group name
|
70
|
+
# -a, --archive recursion and preserve almost everything (-rlptgoD)
|
71
|
+
# -x, --one-file-system don't cross filesystem boundaries
|
72
|
+
# -z, --compress compress file data during the transfer
|
73
|
+
# -S, --sparse handle sparse files efficiently
|
74
|
+
# -v, --verbose verbose
|
75
|
+
|
76
|
+
if destination.include?('@') || source.include?('@')
|
77
|
+
options += ' -e ssh'
|
78
|
+
# -e, --rsh=COMMAND specify the remote shell to use
|
79
|
+
else
|
80
|
+
options += 'E'
|
81
|
+
# -E, --extended-attributes copy extended attributes, resource forks
|
82
|
+
end
|
65
83
|
|
66
|
-
|
67
|
-
|
84
|
+
if profile['exclude']
|
85
|
+
exclude = profile['exclude'].to_a
|
86
|
+
exclude = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
|
87
|
+
# --exclude=PATTERN use one of these for each file you want to exclude
|
88
|
+
else
|
89
|
+
exclude = nil
|
90
|
+
end
|
68
91
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
92
|
+
cmd = "rsync #{options} #{exclude} #{esc(source)} #{esc(destination)}"
|
93
|
+
if $TESTING
|
94
|
+
`#{cmd}`
|
95
|
+
else
|
96
|
+
puts "Executing: #{cmd}"
|
97
|
+
system(cmd)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def run
|
102
|
+
@profiles.each do |profile|
|
103
|
+
rsync(profile)
|
79
104
|
end
|
80
105
|
end
|
81
106
|
end
|
data/rbackup.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rbackup}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Winton Welsh"]
|
9
|
-
s.date = %q{2009-09-
|
9
|
+
s.date = %q{2009-09-24}
|
10
10
|
s.default_executable = %q{rbackup}
|
11
11
|
s.email = %q{mail@wintoni.us}
|
12
12
|
s.executables = ["rbackup"]
|
@@ -14,12 +14,12 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files = ["bin", "bin/rbackup", "gemspec.rb", "lib", "lib/rbackup.rb", "MIT-LICENSE", "Rakefile", "rbackup.gemspec", "README.markdown", "spec", "spec/fixtures", "spec/fixtures/destination", "spec/fixtures/rbackup.yml", "spec/fixtures/source", "spec/fixtures/source/1.txt", "spec/fixtures/source/2.txt", "spec/fixtures/source/3.txt", "spec/rbackup_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
|
15
15
|
s.homepage = %q{http://github.com/winton/rbackup}
|
16
16
|
s.require_paths = ["lib"]
|
17
|
-
s.rubygems_version = %q{1.3.
|
17
|
+
s.rubygems_version = %q{1.3.5}
|
18
18
|
s.summary = %q{Backup your stuff with Ruby and Rsync}
|
19
19
|
|
20
20
|
if s.respond_to? :specification_version then
|
21
21
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
-
s.specification_version =
|
22
|
+
s.specification_version = 3
|
23
23
|
|
24
24
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
25
25
|
else
|
data/spec/fixtures/rbackup.yml
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
profile_1:
|
2
2
|
source: SPEC/fixtures/source/*
|
3
3
|
destination: SPEC/fixtures/destination
|
4
|
-
exclude:
|
4
|
+
exclude: 1.txt
|
5
5
|
profile_2:
|
6
6
|
source: SPEC/fixtures/source/*
|
7
7
|
destination: SPEC/fixtures/destination
|
8
|
-
exclude:
|
9
|
-
|
10
|
-
|
8
|
+
exclude: 2.txt
|
9
|
+
profile_3:
|
10
|
+
profile_4:
|
11
|
+
source: SPEC/fixtures/source/*
|
12
|
+
destination: SPEC/fixtures/destination
|
13
|
+
exclude:
|
14
|
+
- 1.txt
|
15
|
+
- 2.txt
|
16
|
+
profile_5:
|
17
|
+
source: SPEC/fixtures/source/*
|
18
|
+
destination: SPEC/fixtures/destination
|
19
|
+
exclude:
|
20
|
+
- 1.txt
|
21
|
+
- 3.txt
|
data/spec/rbackup_spec.rb
CHANGED
@@ -10,18 +10,19 @@ describe RBackup do
|
|
10
10
|
it "should backup all profiles" do
|
11
11
|
RBackup.new.run
|
12
12
|
File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
|
13
|
-
File.exists?(SPEC + '/fixtures/destination/2.txt').should ==
|
13
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
|
14
14
|
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
15
15
|
File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
|
16
|
+
File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
|
16
17
|
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
17
18
|
end
|
18
19
|
|
19
20
|
it "should backup profile_1" do
|
20
21
|
RBackup.new('profile_1').run
|
21
|
-
File.exists?(SPEC + '/fixtures/destination/1.txt').should ==
|
22
|
-
File.exists?(SPEC + '/fixtures/destination/2.txt').should ==
|
22
|
+
File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
|
23
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
|
23
24
|
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
24
|
-
File.read(SPEC + '/fixtures/destination/
|
25
|
+
File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
|
25
26
|
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
26
27
|
end
|
27
28
|
|
@@ -29,7 +30,17 @@ describe RBackup do
|
|
29
30
|
RBackup.new('profile_2').run
|
30
31
|
File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
|
31
32
|
File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
|
32
|
-
File.exists?(SPEC + '/fixtures/destination/3.txt').should ==
|
33
|
+
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
33
34
|
File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
|
35
|
+
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should backup profile_3" do
|
39
|
+
RBackup.new('profile_3').run
|
40
|
+
File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
|
41
|
+
File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
|
42
|
+
File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
|
43
|
+
File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
|
44
|
+
File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
|
34
45
|
end
|
35
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winton-rbackup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Winton Welsh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-24 00:00:00 -07:00
|
13
13
|
default_executable: rbackup
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -67,7 +67,7 @@ requirements: []
|
|
67
67
|
rubyforge_project:
|
68
68
|
rubygems_version: 1.3.5
|
69
69
|
signing_key:
|
70
|
-
specification_version:
|
70
|
+
specification_version: 3
|
71
71
|
summary: Backup your stuff with Ruby and Rsync
|
72
72
|
test_files: []
|
73
73
|
|