winton-rbackup 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2009 Winton Welsh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,31 @@
1
+ rbackup
2
+ =======
3
+
4
+ Backup your stuff with Ruby and Rsync.
5
+
6
+ Setup
7
+ -----
8
+
9
+ <pre>
10
+ gem sources -a http://gems.github.com
11
+ sudo gem install winton-rbackup
12
+ </pre>
13
+
14
+ Create ~/.rbackup.yml
15
+ ---------------------
16
+
17
+ <pre>
18
+ documents:
19
+ source: ~/Documents
20
+ destination: /Volumes/USB Key
21
+ exclude:
22
+ - Software
23
+ - Virtual Machines.localized
24
+ </pre>
25
+
26
+ Backup
27
+ ------
28
+
29
+ <pre>
30
+ rbackup documents
31
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/gempackagetask'
4
+ require 'spec/rake/spectask'
5
+ require 'gemspec'
6
+
7
+ desc "Generate gemspec"
8
+ task :gemspec do
9
+ File.open("#{Dir.pwd}/#{GEM_NAME}.gemspec", 'w') do |f|
10
+ f.write(GEM_SPEC.to_ruby)
11
+ end
12
+ end
13
+
14
+ desc "Install gem"
15
+ task :install do
16
+ Rake::Task['gem'].invoke
17
+ `sudo gem uninstall #{GEM_NAME} -x`
18
+ `sudo gem install pkg/#{GEM_NAME}*.gem`
19
+ `rm -Rf pkg`
20
+ end
21
+
22
+ desc "Package gem"
23
+ Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
24
+ pkg.gem_spec = GEM_SPEC
25
+ end
26
+
27
+ desc "Setup project"
28
+ task :setup do
29
+ name = File.basename(Dir.pwd)
30
+ `rm -Rf .git`
31
+ begin
32
+ dir = Dir['**/gem_template*']
33
+ from = dir.pop
34
+ if from
35
+ rb = from.include?('.rb')
36
+ to = File.dirname(from) + "/#{name}#{'.rb' if rb}"
37
+ FileUtils.mv(from, to)
38
+ end
39
+ end while dir.length > 0
40
+ Dir["**/*"].each do |path|
41
+ next if path.include?('Rakefile')
42
+ if File.file?(path)
43
+ `sed -i "" 's/gem_template/#{name}/g' #{path}`
44
+ end
45
+ end
46
+ `git init`
47
+ end
48
+
49
+ desc "Run specs"
50
+ Spec::Rake::SpecTask.new do |t|
51
+ t.rcov = true
52
+ t.spec_opts = ["--format", "specdoc", "--colour"]
53
+ t.spec_files = FileList["spec/**/*_spec.rb"]
54
+ end
data/bin/rbackup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push File.expand_path("#{File.dirname(__FILE__)}/../lib")
4
+ require 'rbackup'
5
+
6
+ RBackup.new(*ARGV).run
data/gemspec.rb ADDED
@@ -0,0 +1,20 @@
1
+ GEM_NAME = 'rbackup'
2
+ GEM_FILES = FileList['**/*'] - FileList[
3
+ 'coverage', 'coverage/**/*', 'pkg', 'pkg/**/*', 'spec/fixtures/destination/*'
4
+ ]
5
+ GEM_SPEC = Gem::Specification.new do |s|
6
+ # == CONFIGURE ==
7
+ s.author = "Winton Welsh"
8
+ s.email = "mail@wintoni.us"
9
+ s.homepage = "http://github.com/winton/#{GEM_NAME}"
10
+ s.summary = "Backup your stuff with Ruby and Rsync"
11
+ # == CONFIGURE ==
12
+ s.executables << GEM_NAME
13
+ s.extra_rdoc_files = [ "README.markdown" ]
14
+ s.files = GEM_FILES.to_a
15
+ s.has_rdoc = false
16
+ s.name = GEM_NAME
17
+ s.platform = Gem::Platform::RUBY
18
+ s.require_path = "lib"
19
+ s.version = "0.1.0"
20
+ end
data/lib/rbackup.rb ADDED
@@ -0,0 +1,61 @@
1
+ class RBackup
2
+
3
+ @@usage = <<-USAGE
4
+ Usage:
5
+ rbackup [YAML] PROFILE
6
+
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
+ PROFILE
14
+ The name of the profile listed in your YAML configuration.
15
+ USAGE
16
+
17
+ attr_accessor :config, :destination, :exclude, :profile, :source
18
+
19
+ 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.")
25
+ end
26
+ end
27
+
28
+ 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
37
+ else
38
+ error("YAML configuration not found.")
39
+ end
40
+ end
41
+
42
+ def error(e)
43
+ " Error:\n #{e}\n#{@@usage}"
44
+ exit
45
+ end
46
+
47
+ 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}`
60
+ end
61
+ end
data/rbackup.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rbackup}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Winton Welsh"]
9
+ s.date = %q{2009-09-07}
10
+ s.default_executable = %q{rbackup}
11
+ s.email = %q{mail@wintoni.us}
12
+ s.executables = ["rbackup"]
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"]
15
+ s.homepage = %q{http://github.com/winton/rbackup}
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = %q{1.3.1}
18
+ s.summary = %q{Backup your stuff with Ruby and Rsync}
19
+
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 2
23
+
24
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ profile_1:
2
+ source: SPEC/fixtures/source/*
3
+ destination: SPEC/fixtures/destination
4
+ exclude: 2.txt
@@ -0,0 +1 @@
1
+ 1
@@ -0,0 +1 @@
1
+ 2
@@ -0,0 +1,33 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
+
3
+ describe RBackup do
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
+ Dir[SPEC + '/fixtures/destination/*'].each do |path|
13
+ FileUtils.rm_rf(path)
14
+ end
15
+ # Debug
16
+ # debug @rb.destination
17
+ # debug @rb.exclude
18
+ # debug @rb.source
19
+ end
20
+
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/*" ]
25
+ end
26
+
27
+ it "should backup" do
28
+ @rb.run
29
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
30
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
31
+ File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
32
+ end
33
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,16 @@
1
+ $TESTING=true
2
+ SPEC = File.dirname(__FILE__)
3
+ $:.unshift File.expand_path("#{SPEC}/../lib")
4
+
5
+ require 'rbackup'
6
+ require 'pp'
7
+
8
+ Spec::Runner.configure do |config|
9
+ end
10
+
11
+ # For use with rspec textmate bundle
12
+ def debug(object)
13
+ puts "<pre>"
14
+ puts object.pretty_inspect.gsub('<', '&lt;').gsub('>', '&gt;')
15
+ puts "</pre>"
16
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: winton-rbackup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Winton Welsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-07 00:00:00 -07:00
13
+ default_executable: rbackup
14
+ dependencies: []
15
+
16
+ description:
17
+ email: mail@wintoni.us
18
+ executables:
19
+ - rbackup
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - bin
26
+ - bin/rbackup
27
+ - gemspec.rb
28
+ - lib
29
+ - lib/rbackup.rb
30
+ - MIT-LICENSE
31
+ - Rakefile
32
+ - rbackup.gemspec
33
+ - README.markdown
34
+ - spec
35
+ - spec/fixtures
36
+ - spec/fixtures/destination
37
+ - spec/fixtures/rbackup.yml
38
+ - spec/fixtures/source
39
+ - spec/fixtures/source/1.txt
40
+ - spec/fixtures/source/2.txt
41
+ - spec/rbackup_spec.rb
42
+ - spec/spec.opts
43
+ - spec/spec_helper.rb
44
+ has_rdoc: false
45
+ homepage: http://github.com/winton/rbackup
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Backup your stuff with Ruby and Rsync
70
+ test_files: []
71
+