rbackup 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
@@ -0,0 +1,49 @@
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
+ site:
19
+ server:
20
+ source: /Users/me/site
21
+ destination: deploy@server:/var/www
22
+ exclude:
23
+ - .git
24
+ - /site/config/database.yml
25
+ usb:
26
+ documents:
27
+ source: ~/Documents
28
+ destination: /Volumes/USB Key
29
+ exclude:
30
+ - Software
31
+ - Virtual Machines.localized
32
+ pictures:
33
+ source: ~/Pictures
34
+ destination: /Volumes/USB Key
35
+ </pre>
36
+
37
+ Backup
38
+ ------
39
+
40
+ <pre>
41
+ rbackup site
42
+ // deploys your site
43
+ rbackup usb
44
+ // back up documents and pictures
45
+ rbackup documents
46
+ // back up documents only
47
+ rbackup
48
+ // back up and deploy everything
49
+ </pre>
@@ -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
@@ -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
@@ -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.4"
20
+ end
@@ -0,0 +1,107 @@
1
+ class RBackup
2
+
3
+ @@usage = <<-USAGE
4
+
5
+ Usage:
6
+ rbackup [PROFILE]...
7
+
8
+ PROFILE
9
+ The name of the profile listed in your YAML configuration.
10
+
11
+ USAGE
12
+
13
+ attr_accessor :profiles, :yaml
14
+
15
+ def initialize(*args)
16
+ get_yaml
17
+ get_profiles(args, @yaml)
18
+ end
19
+
20
+ def get_profiles(input, hash, force=false)
21
+ @profiles ||= []
22
+ hash.each do |key, value|
23
+ next unless value.respond_to?(:keys)
24
+ is_profile = value['source'] && value['destination']
25
+ if input.include?(key) || input.empty? || force
26
+ if is_profile
27
+ @profiles << value
28
+ else
29
+ get_profiles(input, value, true)
30
+ end
31
+ elsif !is_profile
32
+ get_profiles(input, value, force)
33
+ end
34
+ end
35
+ end
36
+
37
+ def get_yaml
38
+ if $TESTING
39
+ config = SPEC + '/fixtures/rbackup.yml'
40
+ else
41
+ config = File.expand_path("~/.rbackup.yml")
42
+ end
43
+ if File.exists?(config)
44
+ @yaml = File.open(config)
45
+ @yaml = YAML::load(yaml)
46
+ else
47
+ error("YAML configuration not found.")
48
+ end
49
+ end
50
+
51
+ def error(e)
52
+ puts "\n Error:\n #{e}\n#{@@usage}"
53
+ exit
54
+ end
55
+
56
+ def esc(paths)
57
+ paths = paths.to_a
58
+ paths.collect! { |path| path.gsub('SPEC', SPEC) } if $TESTING
59
+ paths.collect { |path| path.gsub(' ', '\ ') }.join(' ')
60
+ end
61
+
62
+ def rsync(profile)
63
+ destination = profile['destination']
64
+ source = profile['source'].to_a
65
+
66
+ options = "--delete --numeric-ids --safe-links -axzSvL"
67
+ # --delete delete extraneous files from dest dirs
68
+ # --numeric-ids don't map uid/gid values by user/group name
69
+ # --safe-links ignore symlinks that point outside the tree
70
+ # -a, --archive recursion and preserve almost everything (-rlptgoD)
71
+ # -x, --one-file-system don't cross filesystem boundaries
72
+ # -z, --compress compress file data during the transfer
73
+ # -S, --sparse handle sparse files efficiently
74
+ # -v, --verbose verbose
75
+
76
+ if destination.include?(':') || source.include?(':')
77
+ options += ' -e ssh'
78
+ # -e, --rsh=COMMAND specify the remote shell to use
79
+ else
80
+ options += 'E'
81
+ # -E, --extended-attributes copy extended attributes, resource forks
82
+ FileUtils.mkdir_p destination
83
+ end
84
+
85
+ if profile['exclude']
86
+ exclude = profile['exclude'].to_a
87
+ exclude = exclude.collect { |e| "--exclude='#{e}'" }.join(' ')
88
+ # --exclude=PATTERN use one of these for each file you want to exclude
89
+ else
90
+ exclude = nil
91
+ end
92
+
93
+ cmd = "rsync #{options} #{exclude} #{esc(source)} #{esc(destination)}"
94
+ if $TESTING
95
+ `#{cmd}`
96
+ else
97
+ puts "Executing: #{cmd}"
98
+ system(cmd)
99
+ end
100
+ end
101
+
102
+ def run
103
+ @profiles.each do |profile|
104
+ rsync(profile)
105
+ end
106
+ end
107
+ end
@@ -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.4"
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-10-05}
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/fixtures/source/3.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.5}
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 = 3
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,21 @@
1
+ profile_1:
2
+ source: SPEC/fixtures/source/*
3
+ destination: SPEC/fixtures/destination
4
+ exclude: 1.txt
5
+ profile_2:
6
+ source: SPEC/fixtures/source/*
7
+ destination: SPEC/fixtures/destination
8
+ exclude: 2.txt
9
+ profile_3:
10
+ profile_4:
11
+ source: SPEC/fixtures/source/*
12
+ destination: SPEC/fixtures/destination
13
+ exclude:
14
+ - 1.txt
15
+ - 2.txt
16
+ profile_5:
17
+ source: SPEC/fixtures/source/*
18
+ destination: SPEC/fixtures/destination
19
+ exclude:
20
+ - 1.txt
21
+ - 3.txt
@@ -0,0 +1 @@
1
+ 1
@@ -0,0 +1 @@
1
+ 2
@@ -0,0 +1 @@
1
+ 3
@@ -0,0 +1,46 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
+
3
+ describe RBackup do
4
+ before(:each) do
5
+ Dir[SPEC + '/fixtures/destination/*'].each do |path|
6
+ FileUtils.rm_rf(path)
7
+ end
8
+ end
9
+
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 == true
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/2.txt').should == '2'
17
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
18
+ end
19
+
20
+ it "should backup profile_1" do
21
+ RBackup.new('profile_1').run
22
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
23
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
24
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
25
+ File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
26
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
27
+ end
28
+
29
+ it "should backup profile_2" do
30
+ RBackup.new('profile_2').run
31
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == true
32
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == false
33
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
34
+ File.read(SPEC + '/fixtures/destination/1.txt').should == '1'
35
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
36
+ end
37
+
38
+ it "should backup profile_3" do
39
+ RBackup.new('profile_3').run
40
+ File.exists?(SPEC + '/fixtures/destination/1.txt').should == false
41
+ File.exists?(SPEC + '/fixtures/destination/2.txt').should == true
42
+ File.exists?(SPEC + '/fixtures/destination/3.txt').should == true
43
+ File.read(SPEC + '/fixtures/destination/2.txt').should == '2'
44
+ File.read(SPEC + '/fixtures/destination/3.txt').should == '3'
45
+ end
46
+ end
@@ -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,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbackup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Winton Welsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-06 00:00:00 -08:00
13
+ default_executable:
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/rbackup
26
+ - gemspec.rb
27
+ - lib/rbackup.rb
28
+ - MIT-LICENSE
29
+ - Rakefile
30
+ - rbackup.gemspec
31
+ - README.markdown
32
+ - spec/fixtures/rbackup.yml
33
+ - spec/fixtures/source/1.txt
34
+ - spec/fixtures/source/2.txt
35
+ - spec/fixtures/source/3.txt
36
+ - spec/rbackup_spec.rb
37
+ - spec/spec.opts
38
+ - spec/spec_helper.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/winton/rbackup
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.5
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Backup your stuff with Ruby and Rsync
67
+ test_files: []
68
+