rdbackup 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ Gemfile.lock
2
+ doc/
3
+ pkg/
4
+ vendor/cache/*.gem
5
+ .yardoc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title "backup Documentation" --protected
data/ChangeLog.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2012-08-13
2
+
3
+ * Initial release:
4
+
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'kramdown'
7
+
8
+ gem 'rubygems-tasks', '~> 0.2'
9
+ gem 'rspec', '~> 2.4'
10
+ gem 'yard', '~> 0.7'
11
+ gem 'bundler', '~> 1.0'
12
+ gem 'rake', '~> 0.8'
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Christophe Arguel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # rdbackup
2
+
3
+ Backup local directories to a remote server leveraging rdiff-backup.
4
+
5
+ ## Description
6
+
7
+ This gem provides an executable script, __rdbackup__, that allows
8
+ to backup local directories to a remote server. The actual backup
9
+ operation is ensured by rdiff-backup.
10
+ The backup configuration is provided by a YAML file.
11
+
12
+ ## Examples
13
+
14
+ Example backup configuration:
15
+
16
+ server: &backup_server
17
+ hostname: backup-server
18
+ directory: /var/lib/backup
19
+
20
+ backup:
21
+ - directory: /var/lib/dir1
22
+ server: *backup_server
23
+
24
+ - directory: /var/lib/dir2
25
+ server: *backup_server
26
+
27
+
28
+ Start a backup according to a given configuration file.
29
+
30
+ $ rdbackup go path/to/config.yml
31
+
32
+ Start a backup considering default configuration (_$HOME/.rdbackup.conf_ otherwise _/etc/rdbackup.conf_)
33
+
34
+ $ rdbackup go
35
+
36
+ ## Requirements
37
+ rdiff-backup shall be installed on current host and remote host.
38
+ Running as root should the preferable option In order to backup system files.
39
+
40
+ ## Install
41
+
42
+ $ gem install rdbackup
43
+
44
+ ## Copyright
45
+
46
+ Copyright (c) 2012 Christophe Arguel
47
+
48
+ See {file:LICENSE.txt} for details.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'bundler'
7
+ rescue LoadError => e
8
+ warn e.message
9
+ warn "Run `gem install bundler` to install Bundler."
10
+ exit e.status_code
11
+ end
12
+
13
+ begin
14
+ Bundler.setup(:development)
15
+ rescue Bundler::BundlerError => e
16
+ warn e.message
17
+ warn "Run `bundle install` to install missing gems."
18
+ exit e.status_code
19
+ end
20
+
21
+ require 'rake'
22
+
23
+ require 'rubygems/tasks'
24
+ Gem::Tasks.new
25
+
26
+ require 'rspec/core/rake_task'
27
+ RSpec::Core::RakeTask.new
28
+
29
+ task :test => :spec
30
+ task :default => :spec
31
+
32
+ require 'yard'
33
+ YARD::Rake::YardocTask.new
34
+ task :doc => :yard
data/bin/rdbackup ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib_dir=File.expand_path(File.join(File.dirname(__FILE__), '../lib'))
4
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
+
6
+ require 'thor'
7
+ require 'rdbackup'
8
+
9
+ class RdBackupCli < Thor
10
+
11
+ include Thor::Actions
12
+
13
+ desc "go CONFIF", <<-DOC
14
+ Make a backup considering the given YAML configuration file.
15
+ If CONFIG is not provided try to load ~/.rdbackup.conf or /etc/rdbackup.conf.
16
+ DOC
17
+ def go(config=nil)
18
+ config ||= default_config
19
+
20
+ if config.nil?
21
+ error("No YAML configuration file found. Aborting.")
22
+ exit 1
23
+ end
24
+
25
+
26
+ begin
27
+ app = RdBackup::Application.new config
28
+ app.backup
29
+ rescue Exception => message
30
+ error ""
31
+ error "An error occured during backup with the following message : #{message}"
32
+ exit 1
33
+ end
34
+ end
35
+
36
+
37
+ no_tasks do
38
+
39
+ # Identify the default configuration.
40
+ def default_config
41
+ config = nil
42
+ catch(:config_found) {
43
+ [File.join(ENV["HOME"], ".rdbackup.conf"), File.join("/etc", "rdbackup.conf")].each do |conf|
44
+ if File.exist? conf
45
+ config = conf
46
+ throw :config_found
47
+ end
48
+ end
49
+ }
50
+
51
+ return config
52
+ end
53
+
54
+ end
55
+ end
56
+
57
+ RdBackupCli.start
@@ -0,0 +1,23 @@
1
+ require 'psych'
2
+
3
+ module RdBackup
4
+
5
+ # Backup all directories define in a YAML configuration file.
6
+ # The actuel backup is ensured by rdiff-backup command.
7
+ class Application
8
+
9
+ # Initialize the instance with a YAML configuration file
10
+ # @param config [String] path to the YAML config file
11
+ def initialize(config)
12
+ @config = Psych.load(File.open(config))
13
+ end
14
+
15
+ # Call rdiff-backup for each source directory to backup
16
+ def backup
17
+ @config["backup"].each do |item|
18
+ well_executed = system("rdiff-backup #{item["directory"]} #{item["server"]["hostname"]}::#{item["server"]["directory"]}")
19
+ raise "rdiff-backup failed" unless well_executed
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module RdBackup
2
+ # backup version
3
+ VERSION = "0.1.1"
4
+ end
data/lib/rdbackup.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'rdbackup/version'
2
+ require 'rdbackup/app'
data/rdbackup.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/rdbackup/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "rdbackup"
7
+ gem.version = RdBackup::VERSION
8
+ gem.summary = %q{Backup local directories to a remote server leveraging rdiff-backup.}
9
+ gem.description = <<EOD
10
+ This gem provides an executable script to backup local directories.
11
+ THe actual backup is ensured by rdiff-backup.
12
+ The backup configuration is provided by a YAML configuration.
13
+ EOD
14
+ gem.license = "MIT"
15
+ gem.authors = ["Christophe Arguel"]
16
+ gem.email = "christophe.arguel@free.fr"
17
+ gem.homepage = "https://rubygems.org/gems/rdbackup"
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ['lib']
23
+
24
+ gem.add_development_dependency 'bundler', '~> 1.0'
25
+ gem.add_development_dependency 'yard', '~> 0.7'
26
+ gem.add_dependency 'psych', '~> 1.3.4'
27
+ gem.add_dependency 'thor', '~> 0.15.4'
28
+ end
data/spec/app_spec.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'rdbackup'
3
+
4
+ module RdBackup
5
+
6
+ describe Application do
7
+
8
+ context "after loading sample_config.yml" do
9
+ subject { RdBackup::Application.new(sample_config) }
10
+
11
+ it "should call rdiff-backup for each source diretory to backup" do
12
+ subject.should_receive(:system).with("rdiff-backup /var/lib/dir1 backup-server::/var/lib/backup").ordered.and_return(0)
13
+ subject.should_receive(:system).with("rdiff-backup /var/lib/dir2 backup-server::/var/lib/backup").ordered.and_return(0)
14
+ subject.backup
15
+ end
16
+
17
+ it "should raise an error whenever rdiff-backup failed" do
18
+ subject.stub(:system) { return 0 }
19
+ lambda {subject.backup}.should raise_error
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'rdbackup'
3
+
4
+ describe RdBackup do
5
+ it "should have a VERSION constant" do
6
+ subject.const_get('VERSION').should_not be_empty
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ server: &backup_server
2
+ hostname: backup-server
3
+ directory: /var/lib/backup
4
+
5
+ backup:
6
+ - directory: /var/lib/dir1
7
+ server: *backup_server
8
+
9
+ - directory: /var/lib/dir2
10
+ server: *backup_server
@@ -0,0 +1,8 @@
1
+ gem 'rspec', '~> 2.4'
2
+ require 'rspec'
3
+ require 'rdbackup/version'
4
+
5
+ #include Backup
6
+ def sample_config
7
+ File.join(File.dirname(__FILE__), "sample_config.yml")
8
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdbackup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christophe Arguel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &9332200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *9332200
25
+ - !ruby/object:Gem::Dependency
26
+ name: yard
27
+ requirement: &9345680 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.7'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *9345680
36
+ - !ruby/object:Gem::Dependency
37
+ name: psych
38
+ requirement: &9344560 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.3.4
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *9344560
47
+ - !ruby/object:Gem::Dependency
48
+ name: thor
49
+ requirement: &9343860 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.15.4
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *9343860
58
+ description: ! 'This gem provides an executable script to backup local directories.
59
+
60
+ THe actual backup is ensured by rdiff-backup.
61
+
62
+ The backup configuration is provided by a YAML configuration.
63
+
64
+ '
65
+ email: christophe.arguel@free.fr
66
+ executables:
67
+ - rdbackup
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .document
72
+ - .gitignore
73
+ - .rspec
74
+ - .yardopts
75
+ - ChangeLog.md
76
+ - Gemfile
77
+ - LICENSE.txt
78
+ - README.md
79
+ - Rakefile
80
+ - bin/rdbackup
81
+ - lib/rdbackup.rb
82
+ - lib/rdbackup/app.rb
83
+ - lib/rdbackup/version.rb
84
+ - rdbackup.gemspec
85
+ - spec/app_spec.rb
86
+ - spec/backup_spec.rb
87
+ - spec/sample_config.yml
88
+ - spec/spec_helper.rb
89
+ homepage: https://rubygems.org/gems/rdbackup
90
+ licenses:
91
+ - MIT
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: 4285831268404969671
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: 4285831268404969671
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.5
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Backup local directories to a remote server leveraging rdiff-backup.
120
+ test_files:
121
+ - spec/app_spec.rb
122
+ - spec/backup_spec.rb
123
+ - spec/sample_config.yml
124
+ - spec/spec_helper.rb