duplicati 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -6,6 +6,9 @@ This gem is a [Duplicati](http://duplicati.com) backup utility wrapper written i
6
6
 
7
7
  ## Installation
8
8
 
9
+ 1. Install [Duplicati](http://duplicati.com) itself.
10
+ 2. Install Duplicati gem.
11
+
9
12
  Add this line to your application's Gemfile:
10
13
 
11
14
  gem 'duplicati'
@@ -20,7 +23,7 @@ Or install it yourself as:
20
23
 
21
24
  ## Usage
22
25
 
23
- ````
26
+ ````ruby
24
27
  require "duplicati"
25
28
 
26
29
  Duplicati.backup(
@@ -32,9 +35,110 @@ Duplicati.backup(
32
35
 
33
36
  Refer to [Duplicati documentation](http://duplicati.com/howtos) for different backup store locations.
34
37
 
38
+ ## Filters
39
+
40
+ Duplicati allows to specify inclusion and exclusion filters when it comes to backups, restoring and so on.
41
+
42
+ It has [quite complex filtering API](https://code.google.com/p/duplicati/wiki/FilterUsage), which this gem tries to simplify.
43
+
44
+ To include only .txt files, you need to write this:
45
+
46
+ ````ruby
47
+ Duplicati.backup(:inclusion_filter => /.*\.txt$/)
48
+ ````
49
+
50
+ Globs are also supported:
51
+ ````ruby
52
+ Duplicati.backup(:inclusion_filter => "*.mp3")
53
+ ````
54
+
55
+ It is also possible to have multiple filters:
56
+ ````ruby
57
+ Duplicati.backup(:inclusion_filters => [/.*\.txt$/, "*.mp3"])
58
+ ````
59
+
60
+ Exclusion filters work similarly:
61
+ ````ruby
62
+ Duplicati.backup(:exclusion_filter => "*.exe")
63
+ ````
64
+
65
+ ## Notifications
66
+
67
+ Duplicati gem supports currently two different notifications.
68
+
69
+ ### Growl
70
+
71
+ Growl notifications are enabled by default if not specified otherwise.
72
+
73
+ For these to work you need to install [Growl](http://growl.info/) or [Growl for Windows](http://www.growlforwindows.com) and
74
+ a [ruby_gntp](https://github.com/snaka/ruby_gntp) gem.
75
+
76
+ You can enable Growl notifications manually by specifying ````:notifications```` option like this:
77
+
78
+ ````ruby
79
+ Duplicati.backup(
80
+ :notifications => [Duplicati::Notification::Growl.new],
81
+ # other options
82
+ )
83
+ ````
84
+
85
+ ### E-mail
86
+
87
+ To use e-mail notifications, you need to install [mail](https://github.com/mikel/mail) gem.
88
+
89
+ After that you need to specify ````:notifications```` option like this:
90
+
91
+ ````ruby
92
+ Duplicati.backup(
93
+ :notifications => [
94
+ Duplicati::Notification::Mail.new(
95
+ :to => "recipient@example.com",
96
+ :smtp_config => { :domain => "example.com", :address => "mail.example.com" }
97
+ )
98
+ ],
99
+ # other options
100
+ )
101
+ ````
102
+
103
+
104
+ ### Multiple notifications
105
+
106
+ You can use multiple notifications together by specifying them in the ````:notifications```` option array:
107
+
108
+ ````ruby
109
+ Duplicati.backup(:notifications => [NotificationClass1.new, NotificationClass2.new, ...])
110
+ ````
111
+
112
+ ### Disabling notifications
113
+
114
+ To disable all notifications, you need to pass an empty array to ````:notifications```` option:
115
+
116
+ ````ruby
117
+ Duplicati.backup(:notifications => [])
118
+ ````
119
+
120
+ ### Others
121
+
122
+ It is really easy to add new notification types by just implementing one class with single method called ````#notify````.
123
+
124
+ This method takes a single boolean argument called ````success```` which will be true if the Duplicati command succeeded
125
+ and false otherwise. For example:
126
+
127
+ ````ruby
128
+ class CustomNotification
129
+ def notify(success)
130
+ if success
131
+ # notify with success message
132
+ else
133
+ # notify with failure message
134
+ end
135
+ end
136
+ end
137
+ ````
138
+
35
139
  ## Limitations
36
140
 
37
- * Currently only backup is supported. Use command line or GUI utility directly for restoring.
141
+ * Currently only backup is supported. Use Duplicati's command line or GUI utility directly for restoring.
38
142
  * You need to start Ruby with administrative privileges under Windows to backup files in use.
39
143
 
40
144
  ## Contributing
@@ -0,0 +1,13 @@
1
+ class Duplicati
2
+ module Notification
3
+ class Base
4
+ def load_gem(name)
5
+ require name
6
+ true
7
+ rescue LoadError
8
+ Kernel.warn "#{name} gem is not installed, which is needed for #{self.class.name}!"
9
+ false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,35 +1,23 @@
1
1
  class Duplicati
2
2
  module Notification
3
- class Growl
4
- class << self
5
- def notify(success)
6
- return unless load_gem
3
+ class Growl < Base
4
+ def notify(success)
5
+ return unless load_gem "ruby_gntp"
7
6
 
8
- growl = GNTP.new("Backup")
9
- growl.register(:notifications => [{
10
- :name => "backup-notify",
11
- :enabled => true,
12
- }])
7
+ growl = GNTP.new("Backup")
8
+ growl.register(:notifications => [{
9
+ :name => "backup-notify",
10
+ :enabled => true,
11
+ }])
13
12
 
14
- growl.notify(
15
- :name => "backup-notify",
16
- :title => "Backup",
17
- :text => success ? "Backup successfully finished!" : "Backup failed!",
18
- :icon => File.expand_path(success ? "success.png" : "failed.png", File.dirname(__FILE__))
19
- )
20
- rescue => e
21
- Kernel.warn "Failed to notify via Growl: #{e.message}"
22
- end
23
-
24
- private
25
-
26
- def load_gem
27
- require "ruby_gntp"
28
- true
29
- rescue LoadError
30
- Kernel.warn "ruby_gntp gem is not installed, which is needed for Growl notifications!"
31
- false
32
- end
13
+ growl.notify(
14
+ :name => "backup-notify",
15
+ :title => "Backup",
16
+ :text => success ? "Backup successfully finished!" : "Backup failed!",
17
+ :icon => File.expand_path(success ? "success.png" : "failed.png", File.dirname(__FILE__))
18
+ )
19
+ rescue => e
20
+ Kernel.warn "Failed to notify via Growl: #{e.message}"
33
21
  end
34
22
  end
35
23
  end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__)) + "/base"
2
+
3
+ class Duplicati
4
+ module Notification
5
+ class Mail < Base
6
+ def initialize(opts={})
7
+ @smtp_config = {:port => 25, :openssl_verify_mode => "none"}.merge(opts[:smtp_config] || {})
8
+ @to = opts[:to]
9
+ end
10
+
11
+ def notify(success)
12
+ return unless load_gem "mail"
13
+
14
+ smtp_config = @smtp_config
15
+ to_address = @to
16
+
17
+ ::Mail.deliver do
18
+ delivery_method :smtp, smtp_config
19
+
20
+ to to_address
21
+ from "backup@duplicati.com"
22
+ subject "#{`hostname`.strip} - Backup #{success ? "Succeeded" : "Failed"}!"
23
+ body "#{Time.now} - backup #{success ? "succeeded" : "failed"}!"
24
+ end
25
+ rescue => e
26
+ Kernel.warn "Failed to notify via Mail: #{e.message}"
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -1,3 +1,3 @@
1
1
  class Duplicati
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/duplicati.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require File.expand_path("duplicati/version", File.dirname(__FILE__))
2
2
  require File.expand_path("duplicati/backup", File.dirname(__FILE__))
3
+ require File.expand_path("duplicati/notification/base", File.dirname(__FILE__))
3
4
  require File.expand_path("duplicati/notification/growl", File.dirname(__FILE__))
5
+ require File.expand_path("duplicati/notification/mail", File.dirname(__FILE__))
4
6
 
5
7
  class Duplicati
6
8
 
@@ -15,7 +17,7 @@ class Duplicati
15
17
  def initialize(opts={})
16
18
  opts[:log_path] ||= "duplicati.log"
17
19
  opts[:duplicati_path] = duplicati_path(opts[:duplicati_path])
18
- opts[:notifications] ||= [Notification::Growl]
20
+ opts[:notifications] ||= [Notification::Growl.new]
19
21
  opts[:inclusion_filters] ||= [opts[:inclusion_filter]].compact
20
22
  opts[:exclusion_filters] ||= [opts[:exclusion_filter]].compact
21
23
 
@@ -8,7 +8,7 @@ describe Duplicati::Notification::Growl do
8
8
  GNTP = double('gntp').as_null_object unless defined?(GNTP) && GNTP.null_object?
9
9
  end
10
10
 
11
- let(:growl) { subject.class }
11
+ let(:growl) { subject }
12
12
 
13
13
  it "notifies with success message" do
14
14
  GNTP.should_receive(:notify).with notification_args("Backup successfully finished!", "success.png")
@@ -21,7 +21,7 @@ describe Duplicati::Notification::Growl do
21
21
  end
22
22
 
23
23
  it "does not blow up when ruby_gntp gem is not installed" do
24
- Object.any_instance.unstub(:require)
24
+ Object.any_instance.stub(:require).with("ruby_gntp") { raise LoadError }
25
25
  GNTP.should_not_receive(:notify)
26
26
 
27
27
  expect {
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe Duplicati::Notification::Mail do
4
+
5
+ before do
6
+ Kernel.stub(:warn)
7
+ Object.any_instance.stub(:require).with("mail")
8
+ ::Mail = double('mail').as_null_object unless defined?(::Mail) && ::Mail.null_object?
9
+ end
10
+
11
+ let(:mail) { Duplicati::Notification::Mail.new(:to => "foo@example.com", :smtp_config => {:domain => "example.com", :port => 26})}
12
+ let(:smtp_config) { {:port => 26, :openssl_verify_mode => "none", :domain => "example.com"} }
13
+
14
+ it "notifies with message" do
15
+ ::Mail.should_receive(:deliver)
16
+ mail.notify(true)
17
+ end
18
+
19
+ it "does not blow up when mail gem is not installed" do
20
+ Object.any_instance.stub(:require).with("mail") { raise LoadError }
21
+ ::Mail.should_not_receive(:deliver)
22
+
23
+ expect {
24
+ mail.notify(false)
25
+ }.to_not raise_error
26
+ end
27
+
28
+ it "does not blow up when notifying fails" do
29
+ ::Mail.stub(:deliver) { raise "foo" }
30
+
31
+ expect {
32
+ mail.notify(false)
33
+ }.to_not raise_error
34
+ end
35
+
36
+ end
@@ -29,7 +29,9 @@ describe Duplicati do
29
29
  end
30
30
 
31
31
  it "has default notifications" do
32
- Duplicati.new.opts[:notifications].should == [Duplicati::Notification::Growl]
32
+ notifications = Duplicati.new.opts[:notifications]
33
+ notifications.size.should == 1
34
+ notifications.first.should be_kind_of(Duplicati::Notification::Growl)
33
35
  end
34
36
 
35
37
  it "allows to specify notifications" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duplicati
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-30 00:00:00.000000000 Z
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -61,12 +61,15 @@ files:
61
61
  - duplicati.gemspec
62
62
  - lib/duplicati.rb
63
63
  - lib/duplicati/backup.rb
64
+ - lib/duplicati/notification/base.rb
64
65
  - lib/duplicati/notification/failed.png
65
66
  - lib/duplicati/notification/growl.rb
67
+ - lib/duplicati/notification/mail.rb
66
68
  - lib/duplicati/notification/success.png
67
69
  - lib/duplicati/version.rb
68
70
  - spec/duplicati/backup_spec.rb
69
71
  - spec/duplicati/notification/growl_spec.rb
72
+ - spec/duplicati/notification/mail_spec.rb
70
73
  - spec/duplicati_spec.rb
71
74
  - spec/spec_helper.rb
72
75
  homepage: https://github.com/jarmo/duplicati-rb
@@ -81,18 +84,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
84
  - - ! '>='
82
85
  - !ruby/object:Gem::Version
83
86
  version: '0'
84
- segments:
85
- - 0
86
- hash: -687412045
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  none: false
89
89
  requirements:
90
90
  - - ! '>='
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
- segments:
94
- - 0
95
- hash: -687412045
96
93
  requirements: []
97
94
  rubyforge_project:
98
95
  rubygems_version: 1.8.24
@@ -103,5 +100,7 @@ summary: Duplicati backup utility wrapper in Ruby with easier API and sensible c
103
100
  test_files:
104
101
  - spec/duplicati/backup_spec.rb
105
102
  - spec/duplicati/notification/growl_spec.rb
103
+ - spec/duplicati/notification/mail_spec.rb
106
104
  - spec/duplicati_spec.rb
107
105
  - spec/spec_helper.rb
106
+ has_rdoc: