Permalink
Browse files

Adding include option and spec

  • Loading branch information...
1 parent a245394 commit c738450534ded87ace931d2a8ab613e25acba5cb @winton committed Nov 28, 2009
Showing with 37 additions and 10 deletions.
  1. +2 −0 README.markdown
  2. +1 −1 gemspec.rb
  3. +17 −7 lib/rbackup.rb
  4. +2 −2 rbackup.gemspec
  5. +6 −0 spec/fixtures/rbackup.yml
  6. +9 −0 spec/rbackup_spec.rb
View
@@ -32,6 +32,8 @@ usb:
pictures:
source: ~/Pictures
destination: /Volumes/USB Key
+ include:
+ - Favorites
</pre>
Backup
View
@@ -16,5 +16,5 @@
s.name = GEM_NAME
s.platform = Gem::Platform::RUBY
s.require_path = "lib"
- s.version = "0.1.3"
+ s.version = "0.1.5"
end
View
@@ -60,11 +60,15 @@ def esc(paths)
end
def rsync(profile)
+ inc1ude = []
+ exclude = []
destination = profile['destination']
source = profile['source'].to_a
- options = "--numeric-ids --safe-links -axzSvL"
+ options = "--delete --numeric-ids --safe-links -axzSvL"
+ # --delete delete extraneous files from dest dirs
# --numeric-ids don't map uid/gid values by user/group name
+ # --safe-links ignore symlinks that point outside the tree
# -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
@@ -79,16 +83,22 @@ def rsync(profile)
# -E, --extended-attributes copy extended attributes, resource forks
FileUtils.mkdir_p destination
end
+
+ if profile['include']
+ exclude = %w(*) unless profile['exclude']
+ inc1ude = profile['include'].to_a
+ end
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
+ exclude += profile['exclude'].to_a
end
+
+ inc1ude = inc1ude.collect { |i| "--include='#{i}'" }.join(' ')
+ exclude = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
+ # --exclude=PATTERN use one of these for each file you want to exclude
+ # --include-from=FILE don't exclude patterns listed in FILE
- cmd = "rsync #{options} #{exclude} #{esc(source)} #{esc(destination)}"
+ cmd = "rsync #{options} #{inc1ude} #{exclude} #{esc(source)} #{esc(destination)}"
if $TESTING
`#{cmd}`
else
View
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{rbackup}
- s.version = "0.1.3"
+ s.version = "0.1.4"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Winton Welsh"]
- s.date = %q{2009-09-24}
+ s.date = %q{2009-10-05}
s.default_executable = %q{rbackup}
s.email = %q{mail@wintoni.us}
s.executables = ["rbackup"]
@@ -18,4 +18,10 @@ profile_3:
destination: SPEC/fixtures/destination
exclude:
- 1.txt
+ - 3.txt
+ profile_6:
+ source: SPEC/fixtures/source/*
+ destination: SPEC/fixtures/destination
+ include:
+ - 2.txt
- 3.txt
View
@@ -43,4 +43,13 @@
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'
+ end
end

0 comments on commit c738450

Please sign in to comment.