winton-rbackup 0.1.0 → 0.1.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.
data/gemspec.rb CHANGED
@@ -16,5 +16,5 @@ GEM_SPEC = Gem::Specification.new do |s|
16
16
  s.name = GEM_NAME
17
17
  s.platform = Gem::Platform::RUBY
18
18
  s.require_path = "lib"
19
- s.version = "0.1.0"
19
+ s.version = "0.1.1"
20
20
  end
data/lib/rbackup.rb CHANGED
@@ -1,61 +1,81 @@
1
1
  class RBackup
2
2
 
3
3
  @@usage = <<-USAGE
4
+
4
5
  Usage:
5
- rbackup [YAML] PROFILE
6
+ rbackup [PROFILE]...
6
7
 
7
- YAML
8
- The path to your YAML configuration file.
9
-
10
- Default: ~/.rbackup.yml
11
- Example: mate #{File.expand_path(File.dirname(__FILE__) + '/../spec/fixtures/rbackup.yml')}
12
-
13
8
  PROFILE
14
9
  The name of the profile listed in your YAML configuration.
10
+
15
11
  USAGE
16
12
 
17
- attr_accessor :config, :destination, :exclude, :profile, :source
13
+ attr_accessor :profiles, :yaml
18
14
 
19
15
  def initialize(*args)
20
- if @profile = args.pop
21
- @config = args.pop || File.expand_path("~/.rbackup.yml")
22
- configure
23
- else
24
- error("You must specify a profile.")
16
+ @profiles = args
17
+ configure
18
+ if @profiles.empty?
19
+ @profiles = @yaml.keys
25
20
  end
26
21
  end
27
22
 
28
23
  def configure
29
- if File.exists?(@config)
30
- yaml = File.open(@config)
31
- yaml = YAML::load(yaml)
32
- yaml = yaml[profile]
33
- fix = lambda { |path| path.gsub ' ', '\ '}
34
- @destination = fix.call(yaml['destination'])
35
- @exclude = yaml['exclude'].to_a.collect &fix
36
- @source = yaml['source'].to_a.collect &fix
24
+ if $TESTING
25
+ config = SPEC + '/fixtures/rbackup.yml'
26
+ else
27
+ config = File.expand_path("~/.rbackup.yml")
28
+ end
29
+ if File.exists?(config)
30
+ @yaml = File.open(config)
31
+ @yaml = YAML::load(yaml)
37
32
  else
38
33
  error("YAML configuration not found.")
39
34
  end
40
35
  end
41
36
 
42
37
  def error(e)
43
- " Error:\n #{e}\n#{@@usage}"
38
+ puts "\n Error:\n #{e}\n#{@@usage}"
44
39
  exit
45
40
  end
46
41
 
42
+ def esc(paths)
43
+ paths = paths.to_a
44
+ paths.collect! { |path| path.gsub('SPEC', SPEC) } if $TESTING
45
+ paths.collect { |path| path.gsub(' ', '\ ') }.join(' ')
46
+ end
47
+
47
48
  def run
48
- options = "--numeric-ids -EaxzS"
49
- # --numeric-ids don't map uid/gid values by user/group name
50
- # -E, --extended-attributes copy extended attributes, resource forks
51
- # -a, --archive recursion and preserve almost everything (-rlptgoD)
52
- # -x, --one-file-system don't cross filesystem boundaries
53
- # -z, --compress compress file data during the transfer
54
- # -S, --sparse handle sparse files efficiently
55
-
56
- ex = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
57
- # --exclude=PATTERN use one of these for each file you want to exclude
58
-
59
- `rsync #{options} #{ex} #{source.join(' ')} #{destination}`
49
+ @profiles.each do |profile|
50
+ if config = yaml[profile]
51
+ destination = config['destination']
52
+ exclude = config['exclude'].to_a
53
+ source = config['source'].to_a
54
+
55
+ FileUtils.mkdir_p destination
56
+
57
+ options = "--numeric-ids -EaxzSv"
58
+ # --numeric-ids don't map uid/gid values by user/group name
59
+ # -E, --extended-attributes copy extended attributes, resource forks
60
+ # -a, --archive recursion and preserve almost everything (-rlptgoD)
61
+ # -x, --one-file-system don't cross filesystem boundaries
62
+ # -z, --compress compress file data during the transfer
63
+ # -S, --sparse handle sparse files efficiently
64
+ # -v, --verbose verbose
65
+
66
+ ex = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
67
+ # --exclude=PATTERN use one of these for each file you want to exclude
68
+
69
+ cmd = "rsync #{options} #{ex} #{esc(source)} #{esc(destination)}"
70
+ if $TESTING
71
+ `#{cmd}`
72
+ else
73
+ puts "Executing: #{cmd}"
74
+ system(cmd)
75
+ end
76
+ else
77
+ error("Profile #{profile} not found.")
78
+ end
79
+ end
60
80
  end
61
81
  end
data/rbackup.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rbackup}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
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"]
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.email = %q{mail@wintoni.us}
12
12
  s.executables = ["rbackup"]
13
13
  s.extra_rdoc_files = ["README.markdown"]
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/rbackup_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
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
17
  s.rubygems_version = %q{1.3.1}
@@ -1,4 +1,10 @@
1
1
  profile_1:
2
2
  source: SPEC/fixtures/source/*
3
3
  destination: SPEC/fixtures/destination
4
- exclude: 2.txt
4
+ exclude: 2.txt
5
+ profile_2:
6
+ source: SPEC/fixtures/source/*
7
+ destination: SPEC/fixtures/destination
8
+ exclude:
9
+ - 2.txt
10
+ - 3.txt
@@ -0,0 +1 @@
1
+ 3
data/spec/rbackup_spec.rb CHANGED
@@ -2,32 +2,34 @@ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
2
 
3
3
  describe RBackup do
4
4
  before(:each) do
5
- @rb = RBackup.new(SPEC + '/fixtures/rbackup.yml', 'profile_1')
6
- # Replace SPEC in config paths
7
- replace = lambda { |s| s.gsub('SPEC', SPEC) }
8
- @rb.destination = replace.call(@rb.destination)
9
- @rb.exclude = @rb.exclude.collect &replace
10
- @rb.source = @rb.source.collect &replace
11
- # Empty destination folder
12
5
  Dir[SPEC + '/fixtures/destination/*'].each do |path|
13
6
  FileUtils.rm_rf(path)
14
7
  end
15
- # Debug
16
- # debug @rb.destination
17
- # debug @rb.exclude
18
- # debug @rb.source
19
8
  end
20
9
 
21
- it "should load the YAML configuration" do
22
- @rb.destination.should == "#{SPEC}/fixtures/destination"
23
- @rb.exclude.should == [ "2.txt" ]
24
- @rb.source.should == [ "#{SPEC}/fixtures/source/*" ]
10
+ it "should backup all profiles" do
11
+ RBackup.new.run
12
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
13
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
14
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
15
+ File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
16
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
17
+ end
18
+
19
+ it "should backup profile_1" do
20
+ RBackup.new('profile_1').run
21
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
22
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
23
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
24
+ File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
25
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
25
26
  end
26
27
 
27
- it "should backup" do
28
- @rb.run
28
+ it "should backup profile_2" do
29
+ RBackup.new('profile_2').run
29
30
  File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
30
31
  File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
32
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == false
31
33
  File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
32
34
  end
33
35
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh
@@ -38,11 +38,13 @@ files:
38
38
  - spec/fixtures/source
39
39
  - spec/fixtures/source/1.txt
40
40
  - spec/fixtures/source/2.txt
41
+ - spec/fixtures/source/3.txt
41
42
  - spec/rbackup_spec.rb
42
43
  - spec/spec.opts
43
44
  - spec/spec_helper.rb
44
45
  has_rdoc: false
45
46
  homepage: http://github.com/winton/rbackup
47
+ licenses:
46
48
  post_install_message:
47
49
  rdoc_options: []
48
50
 
@@ -63,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
65
  requirements: []
64
66
 
65
67
  rubyforge_project:
66
- rubygems_version: 1.2.0
68
+ rubygems_version: 1.3.5
67
69
  signing_key:
68
70
  specification_version: 2
69
71
  summary: Backup your stuff with Ruby and Rsync