backup 3.0.15 → 3.0.16
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/Gemfile +8 -2
- data/Gemfile.lock +21 -10
- data/Guardfile +17 -0
- data/README.md +87 -42
- data/backup.gemspec +1 -9
- data/lib/backup.rb +6 -2
- data/lib/backup/archive.rb +1 -1
- data/lib/backup/cli.rb +1 -1
- data/lib/backup/compressor/bzip2.rb +64 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/encryptor/gpg.rb +1 -1
- data/lib/backup/notifier/presently.rb +105 -0
- data/lib/backup/storage/s3.rb +2 -6
- data/lib/backup/syncer/s3.rb +6 -4
- data/lib/backup/version.rb +1 -1
- data/lib/templates/archive +3 -0
- data/lib/templates/compressor/bzip2 +7 -0
- data/lib/templates/compressor/gzip +3 -0
- data/lib/templates/database/mongodb +3 -0
- data/lib/templates/database/mysql +3 -0
- data/lib/templates/database/postgresql +4 -1
- data/lib/templates/database/redis +3 -0
- data/lib/templates/encryptor/gpg +3 -0
- data/lib/templates/encryptor/openssl +3 -0
- data/lib/templates/notifier/campfire +3 -0
- data/lib/templates/notifier/mail +3 -0
- data/lib/templates/notifier/presently +12 -0
- data/lib/templates/notifier/twitter +3 -0
- data/lib/templates/readme +1 -1
- data/lib/templates/storage/cloudfiles +3 -0
- data/lib/templates/storage/dropbox +3 -0
- data/lib/templates/storage/ftp +3 -0
- data/lib/templates/storage/rsync +3 -0
- data/lib/templates/storage/s3 +14 -1
- data/lib/templates/storage/scp +3 -0
- data/lib/templates/storage/sftp +3 -0
- data/lib/templates/syncer/rsync +3 -0
- data/lib/templates/syncer/s3 +3 -0
- data/spec/archive_spec.rb +4 -4
- data/spec/compressor/bzip2_spec.rb +59 -0
- data/spec/encryptor/gpg_spec.rb +10 -10
- data/spec/notifier/presently_spec.rb +99 -0
- data/spec/spec_helper.rb +4 -0
- metadata +15 -7
- data/.infinity_test +0 -7
- data/.rspec +0 -3
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Configuration
|
5
|
+
module Compressor
|
6
|
+
class Bzip2 < Base
|
7
|
+
class << self
|
8
|
+
|
9
|
+
##
|
10
|
+
# Tells Backup::Compressor::Bzip2 to compress
|
11
|
+
# better (-9) which is bzip2 default anyway
|
12
|
+
attr_accessor :best
|
13
|
+
|
14
|
+
##
|
15
|
+
# Tells Backup::Compressor::Bzip2 to compress
|
16
|
+
# faster (-1) (but not significantly faster)
|
17
|
+
attr_accessor :fast
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Configuration
|
5
|
+
module Notifier
|
6
|
+
class Presently < Base
|
7
|
+
class << self
|
8
|
+
|
9
|
+
##
|
10
|
+
# Presently subdomain
|
11
|
+
attr_accessor :subdomain
|
12
|
+
|
13
|
+
##
|
14
|
+
# Presently credentials
|
15
|
+
attr_accessor :user_name, :password
|
16
|
+
|
17
|
+
##
|
18
|
+
# Group id
|
19
|
+
attr_accessor :group_id
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/backup/encryptor/gpg.rb
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Backup::Dependency.load('httparty')
|
4
|
+
|
5
|
+
module Backup
|
6
|
+
module Notifier
|
7
|
+
class Presently < Base
|
8
|
+
|
9
|
+
##
|
10
|
+
# Container for the Presently Client object
|
11
|
+
attr_accessor :presently_client
|
12
|
+
|
13
|
+
##
|
14
|
+
# Container for the Model object
|
15
|
+
attr_accessor :model
|
16
|
+
|
17
|
+
##
|
18
|
+
# Presently subdomain
|
19
|
+
attr_accessor :subdomain
|
20
|
+
|
21
|
+
##
|
22
|
+
# Presently credentials
|
23
|
+
attr_accessor :user_name, :password
|
24
|
+
|
25
|
+
##
|
26
|
+
# Group id
|
27
|
+
attr_accessor :group_id
|
28
|
+
|
29
|
+
##
|
30
|
+
# Instantiates a new Backup::Notifier::Presently object
|
31
|
+
def initialize(&block)
|
32
|
+
load_defaults!
|
33
|
+
|
34
|
+
instance_eval(&block) if block_given?
|
35
|
+
|
36
|
+
set_defaults!
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Performs the notification
|
41
|
+
# Takes an exception object that might've been created if an exception occurred.
|
42
|
+
# If this is the case it'll invoke notify_failure!(exception), otherwise, if no
|
43
|
+
# error was raised, it'll go ahead and notify_success!
|
44
|
+
#
|
45
|
+
# If'll only perform these if on_success is true or on_failure is true
|
46
|
+
def perform!(model, exception = false)
|
47
|
+
@model = model
|
48
|
+
|
49
|
+
if notify_on_success? and exception.eql?(false)
|
50
|
+
log!
|
51
|
+
notify_success!
|
52
|
+
elsif notify_on_failure? and not exception.eql?(false)
|
53
|
+
log!
|
54
|
+
notify_failure!(exception)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
##
|
61
|
+
# Sends a tweet informing the user that the backup operation
|
62
|
+
# proceeded without any errors
|
63
|
+
def notify_success!
|
64
|
+
presently_client.update("[Backup::Succeeded] #{model.label} (#{ File.basename(Backup::Model.file) })")
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Sends a tweet informing the user that the backup operation
|
69
|
+
# raised an exception
|
70
|
+
def notify_failure!(exception)
|
71
|
+
presently_client.update("[Backup::Failed] #{model.label} (#{ File.basename(Backup::Model.file) })")
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Create a default Presently::Client object
|
76
|
+
def set_defaults!
|
77
|
+
@presently_client = Client.new subdomain, user_name, password, group_id
|
78
|
+
end
|
79
|
+
|
80
|
+
class Client
|
81
|
+
include HTTParty
|
82
|
+
|
83
|
+
attr_accessor :subdomain, :user_name, :password, :group_id
|
84
|
+
|
85
|
+
def initialize(subdomain, user_name, password, group_id)
|
86
|
+
@subdomain = subdomain
|
87
|
+
@user_name = user_name
|
88
|
+
@password = password
|
89
|
+
@group_id = group_id
|
90
|
+
|
91
|
+
self.class.base_uri "https://#{subdomain}.presently.com"
|
92
|
+
self.class.basic_auth user_name, password
|
93
|
+
end
|
94
|
+
|
95
|
+
def update(message)
|
96
|
+
message = "d @#{group_id} #{message}" if group_id
|
97
|
+
self.class.post "/api/twitter/statuses/update.json", :body => {
|
98
|
+
:status => message,
|
99
|
+
:source => "Backup Notifier"
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/backup/storage/s3.rb
CHANGED
@@ -84,12 +84,8 @@ module Backup
|
|
84
84
|
File.join(remote_path, remote_file),
|
85
85
|
File.open(File.join(local_path, local_file))
|
86
86
|
)
|
87
|
-
rescue Excon::Errors::
|
88
|
-
|
89
|
-
puts "Make sure the bucket exists, and that you specified the correct bucket region.\n\n"
|
90
|
-
puts "The available regions are:\n\n"
|
91
|
-
puts %w[eu-west-1 us-east-1 ap-southeast-1 us-west-1].map{ |region| "\s\s* #{region}" }.join("\n")
|
92
|
-
exit
|
87
|
+
rescue Excon::Errors::NotFound
|
88
|
+
raise "An error occurred while trying to transfer the backup, please make sure the bucket exists."
|
93
89
|
end
|
94
90
|
end
|
95
91
|
|
data/lib/backup/syncer/s3.rb
CHANGED
@@ -48,14 +48,14 @@ module Backup
|
|
48
48
|
# and once it's finished syncing the files and directories to Amazon S3, it'll
|
49
49
|
# unset these credentials (back to nil values)
|
50
50
|
def perform!
|
51
|
-
|
51
|
+
set_environment_variables!
|
52
52
|
|
53
53
|
directories.each do |directory|
|
54
54
|
Logger.message("#{ self.class } started syncing '#{ directory }'.")
|
55
55
|
Logger.silent( run("#{ utility(:s3sync) } #{ options } '#{ directory }' '#{ bucket }:#{ path }'") )
|
56
56
|
end
|
57
57
|
|
58
|
-
|
58
|
+
unset_environment_variables!
|
59
59
|
end
|
60
60
|
|
61
61
|
##
|
@@ -99,16 +99,18 @@ module Backup
|
|
99
99
|
# In order for S3Sync to know what credentials to use, we have to set the
|
100
100
|
# AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, these
|
101
101
|
# evironment variables will be used by S3Sync
|
102
|
-
def
|
102
|
+
def set_environment_variables!
|
103
103
|
ENV['AWS_ACCESS_KEY_ID'] = access_key_id
|
104
104
|
ENV['AWS_SECRET_ACCESS_KEY'] = secret_access_key
|
105
|
+
ENV['AWS_CALLING_FORMAT'] = 'SUBDOMAIN'
|
105
106
|
end
|
106
107
|
|
107
108
|
##
|
108
109
|
# Sets the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY back to nil
|
109
|
-
def
|
110
|
+
def unset_environment_variables!
|
110
111
|
ENV['AWS_ACCESS_KEY_ID'] = nil
|
111
112
|
ENV['AWS_SECRET_ACCESS_KEY'] = nil
|
113
|
+
ENV['AWS_CALLING_FORMAT'] = nil
|
112
114
|
end
|
113
115
|
|
114
116
|
end
|
data/lib/backup/version.rb
CHANGED
data/lib/templates/archive
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# PostgreSQL [Database]
|
3
|
+
#
|
1
4
|
database PostgreSQL do |db|
|
2
5
|
db.name = "my_database_name"
|
3
6
|
db.username = "my_username"
|
@@ -7,5 +10,5 @@
|
|
7
10
|
db.socket = "/tmp/pg.sock"
|
8
11
|
db.skip_tables = ['skip', 'these', 'tables']
|
9
12
|
db.only_tables = ['only', 'these' 'tables']
|
10
|
-
db.additional_options = ['
|
13
|
+
db.additional_options = ['-xc', '-E=utf8']
|
11
14
|
end
|
data/lib/templates/encryptor/gpg
CHANGED
data/lib/templates/notifier/mail
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
##
|
2
|
+
# Presently [Notifier]
|
3
|
+
#
|
4
|
+
notify_by Presently do |presently|
|
5
|
+
presently.on_success = true
|
6
|
+
presently.on_failure = true
|
7
|
+
|
8
|
+
presently.subdomain = 'my_subdomain'
|
9
|
+
presently.user_name = 'my_user_name'
|
10
|
+
presently.password = 'my_password'
|
11
|
+
presently.group_id = 'my_group_id' # optional
|
12
|
+
end
|
data/lib/templates/readme
CHANGED
@@ -11,5 +11,5 @@
|
|
11
11
|
# When you're finished configuring this configuration file,
|
12
12
|
# you can run it from the command line by issuing the following command:
|
13
13
|
#
|
14
|
-
# $ backup -t my_backup [-c <path_to_configuration_file>]
|
14
|
+
# $ backup perform -t my_backup [-c <path_to_configuration_file>]
|
15
15
|
|
data/lib/templates/storage/ftp
CHANGED
data/lib/templates/storage/rsync
CHANGED
data/lib/templates/storage/s3
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
##
|
2
|
+
# Amazon Simple Storage Service [Storage]
|
3
|
+
#
|
4
|
+
# Available Regions:
|
5
|
+
#
|
6
|
+
# - ap-northeast-1
|
7
|
+
# - ap-southeast-1
|
8
|
+
# - eu-west-1
|
9
|
+
# - us-east-1
|
10
|
+
# - us-west-1
|
11
|
+
#
|
1
12
|
store_with S3 do |s3|
|
2
13
|
s3.access_key_id = 'my_access_key_id'
|
3
14
|
s3.secret_access_key = 'my_secret_access_key'
|
@@ -5,4 +16,6 @@
|
|
5
16
|
s3.bucket = 'bucket-name'
|
6
17
|
s3.path = '/path/to/my/backups'
|
7
18
|
s3.keep = 10
|
8
|
-
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
data/lib/templates/storage/scp
CHANGED
data/lib/templates/storage/sftp
CHANGED
data/lib/templates/syncer/rsync
CHANGED