liquid_backup 0.2.1 → 0.3.0
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/LICENSE +1 -1
- data/VERSION +1 -1
- data/bin/liquid_backup +12 -0
- data/lib/liquid_backup.rb +1 -1
- data/lib/liquid_backup/job.rb +34 -3
- data/lib/liquid_backup/manager.rb +11 -2
- data/lib/liquid_backup/notifier/talker_notifier.rb +15 -0
- data/spec/backup_spec.rb +12 -10
- data/spec/fs_root/home/user1/app1/production/current/config/backup_notify_talker.rb +6 -0
- metadata +10 -7
data/LICENSE
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/bin/liquid_backup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'liquid_backup'
|
5
|
+
|
6
|
+
include LiquidBackup
|
7
|
+
|
8
|
+
s3 = Handler::S3.new({:access_key_id =>'1NXAG53SXSSG82H0V902', :secret_access_key =>"Cgm/9/B+IVNJtkXKBY9zWdCGl6B0g+vPVtvms9b9"})
|
9
|
+
|
10
|
+
Manager.use(:s3, s3)
|
11
|
+
|
12
|
+
Manager.collect_jobs('/home/**/current/config/backup.rb').perform_all
|
data/lib/liquid_backup.rb
CHANGED
@@ -11,5 +11,5 @@ $: << File.join(File.dirname(__FILE__),'liquid_backup')
|
|
11
11
|
require 'job'
|
12
12
|
require 'manager'
|
13
13
|
|
14
|
-
|
15
14
|
Dir.glob(File.join(File.dirname(__FILE__),'liquid_backup','handler','*.rb')).each{|h| require h}
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__),'liquid_backup','notifier','*.rb')).each{|h| require h}
|
data/lib/liquid_backup/job.rb
CHANGED
@@ -14,14 +14,17 @@ class LiquidBackup::Job
|
|
14
14
|
attr_accessor :destination_handler
|
15
15
|
attr_accessor :destination_location
|
16
16
|
|
17
|
+
attr_accessor :notifiers
|
18
|
+
|
17
19
|
define_callbacks :upload, :backup
|
18
20
|
|
19
21
|
def initialize(script_path)
|
20
22
|
@script_path = script_path
|
21
|
-
@application_directory = script_path.gsub(
|
23
|
+
@application_directory = script_path.gsub(/\/current\/config\/(.*).rb/,'')
|
22
24
|
@backups_path = File.join(application_directory,'backups')
|
23
25
|
@current_backup_path = File.join(backups_path,'current')
|
24
26
|
@previous_backups_path = File.join(backups_path,'previous')
|
27
|
+
@notifiers = {}
|
25
28
|
end
|
26
29
|
|
27
30
|
set_callback :backup, :before do
|
@@ -45,6 +48,15 @@ class LiquidBackup::Job
|
|
45
48
|
|
46
49
|
set_callback :upload, :after do
|
47
50
|
cleanup
|
51
|
+
send_notifications
|
52
|
+
end
|
53
|
+
|
54
|
+
def backup_size
|
55
|
+
`du -sh #{current_backup_path}`.split("\t")[0]
|
56
|
+
end
|
57
|
+
|
58
|
+
def application_name
|
59
|
+
application_directory.split("/")[-2]
|
48
60
|
end
|
49
61
|
|
50
62
|
private
|
@@ -69,7 +81,7 @@ class LiquidBackup::Job
|
|
69
81
|
|
70
82
|
def upload
|
71
83
|
files_to_backup = Dir.glob(File.join(current_backup_path,'*.tar.gz'))
|
72
|
-
LiquidBackup::Manager.handler(destination_handler).store(destination_location, files_to_backup).cleanup
|
84
|
+
LiquidBackup::Manager.handler(destination_handler).store(destination_location, files_to_backup).cleanup if LiquidBackup::Manager.handler(destination_handler)
|
73
85
|
end
|
74
86
|
|
75
87
|
def compress(source,destination)
|
@@ -81,13 +93,32 @@ class LiquidBackup::Job
|
|
81
93
|
end
|
82
94
|
|
83
95
|
def create_folder(*name)
|
84
|
-
name.each{|f| FileUtils.mkdir_p f}
|
96
|
+
name.each{|f| FileUtils.mkdir_p f rescue puts "Folder Exsists"}
|
85
97
|
end
|
86
98
|
|
87
99
|
def destination(name, location)
|
88
100
|
@destination_handler = name
|
89
101
|
@destination_location = location
|
90
102
|
end
|
103
|
+
|
104
|
+
def notify(name, message)
|
105
|
+
@notifiers[name] || @notifiers[name] = []
|
106
|
+
@notifiers[name] << message
|
107
|
+
end
|
108
|
+
|
109
|
+
def replace_keywords(message)
|
110
|
+
message[:body].gsub!(/#backup_size#/,backup_size)
|
111
|
+
message[:body].gsub!(/#application_name#/,application_name)
|
112
|
+
message
|
113
|
+
end
|
114
|
+
|
115
|
+
def send_notifications
|
116
|
+
@notifiers.each do |notifier,messages|
|
117
|
+
messages.each do | message|
|
118
|
+
LiquidBackup::Manager.notifier(notifier).notify(replace_keywords(message))
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
91
122
|
end
|
92
123
|
|
93
124
|
Dir.glob(File.join(File.dirname(__FILE__),'job','modules','*_module.rb')).each {|s| require s}
|
@@ -7,7 +7,8 @@ class LiquidBackup::Manager
|
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@backup_handler = {}
|
10
|
-
|
10
|
+
@backup_jobs = []
|
11
|
+
@notifiers = {}
|
11
12
|
end
|
12
13
|
|
13
14
|
def collect_jobs(pattern)
|
@@ -22,14 +23,22 @@ class LiquidBackup::Manager
|
|
22
23
|
self
|
23
24
|
end
|
24
25
|
|
25
|
-
def
|
26
|
+
def use_handler(name, handler)
|
26
27
|
@backup_handler[name] = handler
|
27
28
|
end
|
28
29
|
|
30
|
+
def use_notifier(name, notifier)
|
31
|
+
@notifiers[name] = notifier
|
32
|
+
end
|
33
|
+
|
29
34
|
def handler(name)
|
30
35
|
@backup_handler[name]
|
31
36
|
end
|
32
37
|
|
38
|
+
def notifier(name)
|
39
|
+
@notifiers[name]
|
40
|
+
end
|
41
|
+
|
33
42
|
def self.method_missing(method, *args)
|
34
43
|
self.instance.send(method, *args)
|
35
44
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LiquidBackup
|
2
|
+
module Notifier
|
3
|
+
class Talker
|
4
|
+
def initialize(options={})
|
5
|
+
@token = options[:api_token]
|
6
|
+
@subdomain = options[:subdomain]
|
7
|
+
@default_room = options[:default_room]
|
8
|
+
end
|
9
|
+
|
10
|
+
def notify(message={})
|
11
|
+
`curl -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'X-Talker-Token: #{@token}' -d '{"message":"#{message[:body]}"}' https://#{@subdomain}.talkerapp.com/rooms/#{message[:room] || @default_room}/messages.json`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/backup_spec.rb
CHANGED
@@ -21,16 +21,18 @@ describe LiquidBackup do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe LiquidBackup::Job do
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
context ".Base" do
|
25
|
+
before(:each) do
|
26
|
+
@job = LiquidBackup::Job.new(File.join(File.dirname(__FILE__), "/fs_root/home/user1/app1/production/current/config/backup.rb"))
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
it "should report the correct application directory" do
|
30
|
+
@job.application_directory.should eql(File.join(File.dirname(__FILE__), "/fs_root/home/user1/app1/production"))
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
it "should create a backup directory" do
|
34
|
+
File.directory?(@job.backups_path).should be true
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
context "S3" do
|
@@ -39,10 +41,10 @@ describe LiquidBackup do
|
|
39
41
|
AWS::S3::Base.should_receive(:establish_connection!).with(credidentials).and_return(true)
|
40
42
|
|
41
43
|
s3 = LiquidBackup::Handler::S3.new(credidentials)
|
42
|
-
LiquidBackup::Manager.
|
44
|
+
LiquidBackup::Manager.use_handler(:s3, s3)
|
43
45
|
|
44
46
|
@job = LiquidBackup::Job.new(File.join(File.dirname(__FILE__), "/fs_root/home/user1/app1/production/current/config/backup.rb"))
|
45
|
-
LiquidBackup::Manager.handler(:s3).should_receive(:store).
|
47
|
+
LiquidBackup::Manager.handler(:s3).should_receive(:store).and_return(LiquidBackup::Manager.handler(:s3))
|
46
48
|
@job.perform
|
47
49
|
end
|
48
50
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dan Williams
|
@@ -14,8 +14,8 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
18
|
-
default_executable:
|
17
|
+
date: 2010-03-12 00:00:00 -04:00
|
18
|
+
default_executable: liquid_backup
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -45,8 +45,8 @@ dependencies:
|
|
45
45
|
version_requirements: *id002
|
46
46
|
description: Backup your application server
|
47
47
|
email: os@liquidmedia.ca
|
48
|
-
executables:
|
49
|
-
|
48
|
+
executables:
|
49
|
+
- liquid_backup
|
50
50
|
extensions: []
|
51
51
|
|
52
52
|
extra_rdoc_files:
|
@@ -65,8 +65,10 @@ files:
|
|
65
65
|
- lib/liquid_backup/job/modules/database_module.rb
|
66
66
|
- lib/liquid_backup/job/modules/folder_module.rb
|
67
67
|
- lib/liquid_backup/manager.rb
|
68
|
+
- lib/liquid_backup/notifier/talker_notifier.rb
|
68
69
|
- spec/backup_spec.rb
|
69
70
|
- spec/fs_root/home/user1/app1/production/current/config/backup.rb
|
71
|
+
- spec/fs_root/home/user1/app1/production/current/config/backup_notify_talker.rb
|
70
72
|
- spec/fs_root/home/user1/app1/production/current/public/system/important_files/file1.txt
|
71
73
|
- spec/fs_root/home/user1/app1/production/current/public/system/important_files/file2.txt
|
72
74
|
- spec/spec.opts
|
@@ -104,4 +106,5 @@ summary: Backup your application server
|
|
104
106
|
test_files:
|
105
107
|
- spec/backup_spec.rb
|
106
108
|
- spec/fs_root/home/user1/app1/production/current/config/backup.rb
|
109
|
+
- spec/fs_root/home/user1/app1/production/current/config/backup_notify_talker.rb
|
107
110
|
- spec/spec_helper.rb
|