Permalink
Browse files

Version 0.1.2

  • Loading branch information...
1 parent 5d5d0e9 commit cf81d5156573fc51c8d81a8fe03c7399995824e1 @winton committed Sep 24, 2009
Showing with 109 additions and 53 deletions.
  1. +15 −6 README.markdown
  2. +1 −1 gemspec.rb
  3. +58 −33 lib/rbackup.rb
  4. +4 −4 rbackup.gemspec
  5. +15 −4 spec/fixtures/rbackup.yml
  6. +16 −5 spec/rbackup_spec.rb
View
@@ -15,17 +15,26 @@ Create ~/.rbackup.yml
---------------------
<pre>
-documents:
- source: ~/Documents
- destination: /Volumes/USB Key
- exclude:
- - Software
- - Virtual Machines.localized
+usb:
+ documents:
+ source: ~/Documents
+ destination: /Volumes/USB Key
+ exclude:
+ - Software
+ - Virtual Machines.localized
+ pictures:
+ source: ~/Pictures
+ destination: /Volumes/USB Key
</pre>
Backup
------
<pre>
rbackup documents
+ // backs up documents
+rbackup usb
+ // backs up documents and pictures
+rbackup
+ // backs up all profiles
</pre>
View
@@ -16,5 +16,5 @@
s.name = GEM_NAME
s.platform = Gem::Platform::RUBY
s.require_path = "lib"
- s.version = "0.1.1"
+ s.version = "0.1.2"
end
View
@@ -13,14 +13,11 @@ class RBackup
attr_accessor :profiles, :yaml
def initialize(*args)
- @profiles = args
- configure
- if @profiles.empty?
- @profiles = @yaml.keys
- end
+ get_yaml
+ get_profiles(args, @yaml)
end
- def configure
+ def get_yaml
if $TESTING
config = SPEC + '/fixtures/rbackup.yml'
else
@@ -45,37 +42,65 @@ def esc(paths)
paths.collect { |path| path.gsub(' ', '\ ') }.join(' ')
end
- def run
- @profiles.each do |profile|
- if config = yaml[profile]
- destination = config['destination']
- exclude = config['exclude'].to_a
- source = config['source'].to_a
+ def get_profiles(input, hash, force=false)
+ @profiles ||= []
+ hash.each do |key, value|
+ next unless value.respond_to?(:keys)
+ is_profile = value['source'] && value['destination']
+ if input.include?(key) || input.empty? || force
+ if is_profile
+ @profiles << value
+ else
+ get_profiles(input, value, true)
+ end
+ elsif !is_profile
+ get_profiles(input, value, force)
+ end
+ end
+ end
+
+ def rsync(profile)
+ destination = profile['destination']
+ source = profile['source'].to_a
- FileUtils.mkdir_p destination
+ FileUtils.mkdir_p destination
- options = "--numeric-ids -EaxzSv"
- # --numeric-ids don't map uid/gid values by user/group name
- # -E, --extended-attributes copy extended attributes, resource forks
- # -a, --archive recursion and preserve almost everything (-rlptgoD)
- # -x, --one-file-system don't cross filesystem boundaries
- # -z, --compress compress file data during the transfer
- # -S, --sparse handle sparse files efficiently
- # -v, --verbose verbose
+ options = "--numeric-ids -axzSv"
+ # --numeric-ids don't map uid/gid values by user/group name
+ # -a, --archive recursion and preserve almost everything (-rlptgoD)
+ # -x, --one-file-system don't cross filesystem boundaries
+ # -z, --compress compress file data during the transfer
+ # -S, --sparse handle sparse files efficiently
+ # -v, --verbose verbose
+
+ if destination.include?('@') || source.include?('@')
+ options += ' -e ssh'
+ # -e, --rsh=COMMAND specify the remote shell to use
+ else
+ options += 'E'
+ # -E, --extended-attributes copy extended attributes, resource forks
+ end
- ex = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
- # --exclude=PATTERN use one of these for each file you want to exclude
+ if profile['exclude']
+ exclude = profile['exclude'].to_a
+ exclude = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
+ # --exclude=PATTERN use one of these for each file you want to exclude
+ else
+ exclude = nil
+ end
- cmd = "rsync #{options} #{ex} #{esc(source)} #{esc(destination)}"
- if $TESTING
- `#{cmd}`
- else
- puts "Executing: #{cmd}"
- system(cmd)
- end
- else
- error("Profile #{profile} not found.")
- end
+ cmd = "rsync #{options} #{exclude} #{esc(source)} #{esc(destination)}"
+ if $TESTING
+ `#{cmd}`
+ else
+ puts "Executing: #{cmd}"
+ system(cmd)
+ end
+ end
+
+ def run
+ @profiles.each do |profile|
+ rsync(profile)
end
end
end
View
@@ -2,24 +2,24 @@
Gem::Specification.new do |s|
s.name = %q{rbackup}
- s.version = "0.1.1"
+ s.version = "0.1.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Winton Welsh"]
- s.date = %q{2009-09-07}
+ s.date = %q{2009-09-24}
s.default_executable = %q{rbackup}
s.email = %q{mail@wintoni.us}
s.executables = ["rbackup"]
s.extra_rdoc_files = ["README.markdown"]
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"]
s.homepage = %q{http://github.com/winton/rbackup}
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.1}
+ s.rubygems_version = %q{1.3.5}
s.summary = %q{Backup your stuff with Ruby and Rsync}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 2
+ s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
else
@@ -1,10 +1,21 @@
profile_1:
source: SPEC/fixtures/source/*
destination: SPEC/fixtures/destination
- exclude: 2.txt
+ exclude: 1.txt
profile_2:
source: SPEC/fixtures/source/*
destination: SPEC/fixtures/destination
- exclude:
- - 2.txt
- - 3.txt
+ exclude: 2.txt
+profile_3:
+ profile_4:
+ source: SPEC/fixtures/source/*
+ destination: SPEC/fixtures/destination
+ exclude:
+ - 1.txt
+ - 2.txt
+ profile_5:
+ source: SPEC/fixtures/source/*
+ destination: SPEC/fixtures/destination
+ exclude:
+ - 1.txt
+ - 3.txt
View
@@ -10,26 +10,37 @@
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 == false
+ 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 == true
- File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
+ 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/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_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 == 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
end

0 comments on commit cf81d51

Please sign in to comment.