blanket 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/blanket-cfg +10 -3
- data/lib/blanket/init.rb +2 -0
- data/lib/blanket/plugins/sinks/s3.rb +4 -0
- data/lib/blanket/plugins/sinks/scp.rb +39 -0
- data/lib/blanket/plugins/sinks/sftp.rb +43 -0
- data/lib/capistrano/recipes/blanket.rb +5 -5
- data/lib/capistrano/recipes/s3.rb +14 -0
- data/lib/capistrano/recipes/sftp.rb +18 -0
- metadata +5 -1
data/bin/blanket-cfg
CHANGED
@@ -36,6 +36,7 @@ $stderr << BAD_ARGS unless OPTIONS[:task] && OPTIONS[:source] && OPTIONS[:sink]
|
|
36
36
|
|
37
37
|
task = OPTIONS[:task]
|
38
38
|
source_class = OPTIONS[:source]
|
39
|
+
sink_class = OPTIONS[:sink]
|
39
40
|
@task_dir = FileUtils.pwd + "/" +task
|
40
41
|
puts "Creating #{@task_dir}"
|
41
42
|
FileUtils.mkdir_p @task_dir
|
@@ -51,6 +52,14 @@ end
|
|
51
52
|
write_config_for(:source)
|
52
53
|
write_config_for(:sink)
|
53
54
|
|
55
|
+
requirements = ["'capistrano/recipes/blanket'"]
|
56
|
+
[:source, :sink].each do |phase|
|
57
|
+
phase_class = Object.const_get(OPTIONS[phase])
|
58
|
+
(requirements << phase_class.additional_requirements) if phase_class.respond_to? :additional_requirements
|
59
|
+
end
|
60
|
+
|
61
|
+
capfile_requires = requirements.inject("") {|statement, r| statement += "require #{r}\r\n" }
|
62
|
+
|
54
63
|
|
55
64
|
def unindent(string)
|
56
65
|
indentation = string[/\A\s*/]
|
@@ -58,9 +67,7 @@ def unindent(string)
|
|
58
67
|
end
|
59
68
|
|
60
69
|
files = {
|
61
|
-
"Capfile" => unindent(
|
62
|
-
require 'capistrano/recipes/blanket'
|
63
|
-
FILE
|
70
|
+
"Capfile" => unindent(capfile_requires)
|
64
71
|
}
|
65
72
|
|
66
73
|
files.each do |file, content|
|
data/lib/blanket/init.rb
CHANGED
@@ -22,3 +22,5 @@ require File.dirname(__FILE__) + "/plugins/sources/single_file.rb"
|
|
22
22
|
require File.dirname(__FILE__) + "/plugins/sources/remote_directory.rb"
|
23
23
|
require File.dirname(__FILE__) + "/plugins/sources/postgresql.rb"
|
24
24
|
require File.dirname(__FILE__) + "/plugins/sinks/s3.rb"
|
25
|
+
require File.dirname(__FILE__) + "/plugins/sinks/scp.rb"
|
26
|
+
require File.dirname(__FILE__) + "/plugins/sinks/sftp.rb"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class Scp < Sink
|
2
|
+
|
3
|
+
def initialize(reader)
|
4
|
+
@reader = reader
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.attribute_symbols
|
8
|
+
[:sink_type, :host, :user, :password, :remote_path, :local_path ]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.default_sink_type
|
12
|
+
"Scp"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.default_host
|
16
|
+
"yourhost.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.default_user
|
20
|
+
"username"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.default_password
|
24
|
+
"password"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.default_remote_path
|
28
|
+
"/path/to/remote/backup/directory"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.default_local_path
|
32
|
+
"/path/to/local/blanket"
|
33
|
+
end
|
34
|
+
|
35
|
+
def cleanup_command
|
36
|
+
noop
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Sftp < Sink
|
2
|
+
|
3
|
+
def initialize(reader)
|
4
|
+
@reader = reader
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.additional_requirements
|
8
|
+
"'capistrano/recipes/sftp'"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.attribute_symbols
|
12
|
+
[:sink_type, :host, :user, :password, :remote_path, :local_path ]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.default_sink_type
|
16
|
+
"Sftp"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.default_host
|
20
|
+
"yourhost.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.default_user
|
24
|
+
"username"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.default_password
|
28
|
+
"password"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.default_remote_path
|
32
|
+
"/path/to/remote/backup/directory"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.default_local_path
|
36
|
+
"/path/to/local/blanket"
|
37
|
+
end
|
38
|
+
|
39
|
+
def cleanup_command
|
40
|
+
noop
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -42,14 +42,14 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
42
42
|
end
|
43
43
|
set :sink, Object.const_get(sink_type).new(reader)
|
44
44
|
end
|
45
|
-
|
46
|
-
desc "
|
47
|
-
task :export do
|
48
|
-
|
49
|
-
variables[:sink].drain(bucket, upload_filename)
|
45
|
+
|
46
|
+
desc "Export file using put"
|
47
|
+
task :export, :hosts => lambda{ host } do
|
48
|
+
put variables[:source].remote_backup_path, variables[:sink].remote_path
|
50
49
|
end
|
51
50
|
|
52
51
|
end
|
53
52
|
before "sink:export", "source:download"
|
54
53
|
before "sink:export", "sink:load_config"
|
54
|
+
|
55
55
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
gem 'blanket'
|
2
|
+
require 'blanket/init'
|
3
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
4
|
+
|
5
|
+
namespace :sink do
|
6
|
+
|
7
|
+
desc "Upload file to S3"
|
8
|
+
task :export do
|
9
|
+
upload_filename = Pathname.new(variables[:source].local_backup_path).basename.to_s
|
10
|
+
variables[:sink].drain(bucket, upload_filename)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
gem 'blanket'
|
2
|
+
require 'blanket/init'
|
3
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
4
|
+
|
5
|
+
namespace :sink do
|
6
|
+
|
7
|
+
desc "Upload file to S3"
|
8
|
+
task :export do
|
9
|
+
puts "Uploading #{variables[:source].local_backup_path} to #{variables[:sink].remote_path}"
|
10
|
+
Net::SFTP.start(host, user, password) do |sftp|
|
11
|
+
sftp.put_file variables[:source].local_backup_path, variables[:sink].remote_path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blanket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Van Fleet
|
@@ -57,6 +57,8 @@ files:
|
|
57
57
|
- lib/blanket/utils.rb
|
58
58
|
- lib/capistrano/recipes
|
59
59
|
- lib/capistrano/recipes/blanket.rb
|
60
|
+
- lib/capistrano/recipes/s3.rb
|
61
|
+
- lib/capistrano/recipes/sftp.rb
|
60
62
|
- lib/blanket/plugins/sources
|
61
63
|
- lib/blanket/plugins/sources/confluence.rb
|
62
64
|
- lib/blanket/plugins/sources/mysql.rb
|
@@ -65,6 +67,8 @@ files:
|
|
65
67
|
- lib/blanket/plugins/sources/remote_directory.rb
|
66
68
|
- lib/blanket/plugins/sources/postgresql.rb
|
67
69
|
- lib/blanket/plugins/sinks/s3.rb
|
70
|
+
- lib/blanket/plugins/sinks/scp.rb
|
71
|
+
- lib/blanket/plugins/sinks/sftp.rb
|
68
72
|
- spec/fixtures
|
69
73
|
- spec/confluence_spec.rb
|
70
74
|
- spec/dependency_spec.rb
|