Permalink
Browse files

Version 0.1.9

Adding --reverse option
  • Loading branch information...
1 parent fb7198b commit 4c0a3bb0bcb529249d834223850f59d02824667f @winton committed Feb 4, 2011
Showing with 94 additions and 50 deletions.
  1. +1 −1 bin/rbackup
  2. +1 −1 gemspec.rb
  3. +12 −4 lib/rbackup.rb
  4. +27 −0 spec/fixtures/rbackup_reverse.yml
  5. +53 −44 spec/rbackup_spec.rb
View
@@ -3,4 +3,4 @@
$:.push File.expand_path("#{File.dirname(__FILE__)}/../lib")
require 'rbackup'
-RBackup.new(*ARGV).run
+RBackup.new(ARGV.delete('--reverse'), *ARGV).run
View
@@ -16,5 +16,5 @@
s.name = GEM_NAME
s.platform = Gem::Platform::RUBY
s.require_path = "lib"
- s.version = "0.1.8"
+ s.version = "0.1.9"
end
View
@@ -15,7 +15,8 @@ class RBackup
attr_accessor :profiles, :yaml
- def initialize(*args)
+ def initialize(reverse, *args)
+ @reverse = reverse
get_yaml
get_profiles(args, @yaml)
end
@@ -38,8 +39,8 @@ def get_profiles(input, hash, force=false)
end
def get_yaml
- if $TESTING
- config = SPEC + '/fixtures/rbackup.yml'
+ if $rbackup_config
+ config = $rbackup_config
else
config = File.expand_path("~/.rbackup.yml")
end
@@ -66,7 +67,14 @@ def rsync(profile)
inc1ude = []
exclude = []
destination = profile['destination']
- source = [ profile['source'] ].flatten
+ source = profile['source']
+
+ if @reverse
+ last = source.split('/').last
+ source = source.split('/')[0..-2].join('/')
+ destination = [ destination, '/', last ].join('/')
+ destination, source = source, destination
+ end
options = "--numeric-ids --safe-links -axzSvL"
# --numeric-ids don't map uid/gid values by user/group name
@@ -0,0 +1,27 @@
+profile_1:
+ source: SPEC/fixtures/destination/*
+ destination: SPEC/fixtures/source
+ exclude: 1.txt
+profile_2:
+ source: SPEC/fixtures/destination/*
+ destination: SPEC/fixtures/source
+ exclude: 2.txt
+profile_3:
+ profile_4:
+ source: SPEC/fixtures/destination/*
+ destination: SPEC/fixtures/source
+ exclude:
+ - 1.txt
+ - 2.txt
+ profile_5:
+ source: SPEC/fixtures/destination/*
+ destination: SPEC/fixtures/source
+ exclude:
+ - 1.txt
+ - 3.txt
+ profile_6:
+ source: SPEC/fixtures/destination/*
+ destination: SPEC/fixtures/source
+ include:
+ - 2.txt
+ - 3.txt
View
@@ -1,55 +1,64 @@
require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
describe RBackup do
- before(:each) do
- Dir[SPEC + '/fixtures/destination/*'].each do |path|
- FileUtils.rm_rf(path)
+ [ :normal, :reverse ].each do |type|
+ before(:each) do
+ if type == :normal
+ $rbackup_config = SPEC + '/fixtures/rbackup.yml'
+ @reverse = false
+ else
+ $rbackup_config = SPEC + '/fixtures/rbackup_reverse.yml'
+ @reverse = true
+ end
+ Dir[SPEC + '/fixtures/destination/*'].each do |path|
+ FileUtils.rm_rf(path)
+ end
end
- end
- it "should backup all profiles" do
- RBackup.new.run
- File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
- File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
- File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
- File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
- File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
- File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
- end
+ it "should backup all profiles" do
+ RBackup.new(@reverse).run
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
+ File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
+ File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
+ end
- it "should backup profile_1" do
- RBackup.new('profile_1').run
- File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
- File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
- File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
- File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
- File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
- end
+ it "should backup profile_1" do
+ RBackup.new(@reverse, 'profile_1').run
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
+ File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
+ end
- it "should backup profile_2" do
- RBackup.new('profile_2').run
- File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
- File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
- File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
- File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
- File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
- end
+ it "should backup profile_2" do
+ RBackup.new(@reverse, 'profile_2').run
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
+ File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
+ end
- it "should backup profile_3" do
- RBackup.new('profile_3').run
- File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
- File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
- File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
- File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
- File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
- end
+ it "should backup profile_3" do
+ RBackup.new(@reverse, 'profile_3').run
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
+ File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
+ end
- it "should backup profile_6" do
- RBackup.new('profile_6').run
- File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
- File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
- File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
- File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
- File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
+ it "should backup profile_6" do
+ RBackup.new(@reverse, 'profile_6').run
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
+ File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
+ end
end
end

0 comments on commit 4c0a3bb

Please sign in to comment.