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.
Files changed (47) hide show
  1. data/Gemfile +8 -2
  2. data/Gemfile.lock +21 -10
  3. data/Guardfile +17 -0
  4. data/README.md +87 -42
  5. data/backup.gemspec +1 -9
  6. data/lib/backup.rb +6 -2
  7. data/lib/backup/archive.rb +1 -1
  8. data/lib/backup/cli.rb +1 -1
  9. data/lib/backup/compressor/bzip2.rb +64 -0
  10. data/lib/backup/configuration/compressor/bzip2.rb +23 -0
  11. data/lib/backup/configuration/notifier/presently.rb +25 -0
  12. data/lib/backup/encryptor/gpg.rb +1 -1
  13. data/lib/backup/notifier/presently.rb +105 -0
  14. data/lib/backup/storage/s3.rb +2 -6
  15. data/lib/backup/syncer/s3.rb +6 -4
  16. data/lib/backup/version.rb +1 -1
  17. data/lib/templates/archive +3 -0
  18. data/lib/templates/compressor/bzip2 +7 -0
  19. data/lib/templates/compressor/gzip +3 -0
  20. data/lib/templates/database/mongodb +3 -0
  21. data/lib/templates/database/mysql +3 -0
  22. data/lib/templates/database/postgresql +4 -1
  23. data/lib/templates/database/redis +3 -0
  24. data/lib/templates/encryptor/gpg +3 -0
  25. data/lib/templates/encryptor/openssl +3 -0
  26. data/lib/templates/notifier/campfire +3 -0
  27. data/lib/templates/notifier/mail +3 -0
  28. data/lib/templates/notifier/presently +12 -0
  29. data/lib/templates/notifier/twitter +3 -0
  30. data/lib/templates/readme +1 -1
  31. data/lib/templates/storage/cloudfiles +3 -0
  32. data/lib/templates/storage/dropbox +3 -0
  33. data/lib/templates/storage/ftp +3 -0
  34. data/lib/templates/storage/rsync +3 -0
  35. data/lib/templates/storage/s3 +14 -1
  36. data/lib/templates/storage/scp +3 -0
  37. data/lib/templates/storage/sftp +3 -0
  38. data/lib/templates/syncer/rsync +3 -0
  39. data/lib/templates/syncer/s3 +3 -0
  40. data/spec/archive_spec.rb +4 -4
  41. data/spec/compressor/bzip2_spec.rb +59 -0
  42. data/spec/encryptor/gpg_spec.rb +10 -10
  43. data/spec/notifier/presently_spec.rb +99 -0
  44. data/spec/spec_helper.rb +4 -0
  45. metadata +15 -7
  46. data/.infinity_test +0 -7
  47. 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
@@ -30,7 +30,7 @@ module Backup
30
30
 
31
31
  instance_eval(&block) if block_given?
32
32
 
33
- @key = key.gsub(/^(\s|\t)+/, '')
33
+ @key = key.gsub(/^[[:blank:]]+/, '')
34
34
  end
35
35
 
36
36
  ##
@@ -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
@@ -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::SocketError
88
- puts "\nAn error occurred while trying to transfer the backup."
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
 
@@ -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
- set_s3sync_credentials!
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
- unset_s3sync_credentials!
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 set_s3sync_credentials!
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 unset_s3sync_credentials!
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
@@ -13,7 +13,7 @@ module Backup
13
13
  # Defines the minor version
14
14
  # PATCH:
15
15
  # Defines the patch version
16
- MAJOR, MINOR, PATCH = 3, 0, 15
16
+ MAJOR, MINOR, PATCH = 3, 0, 16
17
17
 
18
18
  ##
19
19
  # Returns the major version ( big release based off of multiple minor releases )
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Archive [Archive]
3
+ #
1
4
  archive :my_archive do |archive|
2
5
  archive.add '/path/to/a/file.rb'
3
6
  archive.add '/path/to/a/folder/'
@@ -0,0 +1,7 @@
1
+ ##
2
+ # Bzip2 [Compressor]
3
+ #
4
+ compress_with Bzip2 do |compression|
5
+ compression.best = true
6
+ compression.fast = false
7
+ end
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Gzip [Compressor]
3
+ #
1
4
  compress_with Gzip do |compression|
2
5
  compression.best = true
3
6
  compression.fast = false
@@ -1,3 +1,6 @@
1
+ ##
2
+ # MongoDB [Database]
3
+ #
1
4
  database MongoDB do |db|
2
5
  db.name = "my_database_name"
3
6
  db.username = "my_username"
@@ -1,3 +1,6 @@
1
+ ##
2
+ # MySQL [Database]
3
+ #
1
4
  database MySQL do |db|
2
5
  db.name = "my_database_name"
3
6
  db.username = "my_username"
@@ -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 = ['--quick', '--single-transaction']
13
+ db.additional_options = ['-xc', '-E=utf8']
11
14
  end
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Redis [Database]
3
+ #
1
4
  database Redis do |db|
2
5
  db.name = "my_database_name"
3
6
  db.path = "/usr/local/var/db/redis"
@@ -1,3 +1,6 @@
1
+ ##
2
+ # GPG [Encryptor]
3
+ #
1
4
  encrypt_with GPG do |encryption|
2
5
  encryption.key = <<-KEY
3
6
  -----BEGIN PGP PUBLIC KEY BLOCK-----
@@ -1,3 +1,6 @@
1
+ ##
2
+ # OpenSSL [Encryptor]
3
+ #
1
4
  encrypt_with OpenSSL do |encryption|
2
5
  encryption.password = 'my_password'
3
6
  encryption.base64 = true
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Campfire [Notifier]
3
+ #
1
4
  notify_by Campfire do |campfire|
2
5
  campfire.on_success = true
3
6
  campfire.on_failure = true
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Mail [Notifier]
3
+ #
1
4
  notify_by Mail do |mail|
2
5
  mail.on_success = true
3
6
  mail.on_failure = true
@@ -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
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Twitter [Notifier]
3
+ #
1
4
  notify_by Twitter do |tweet|
2
5
  tweet.on_success = true
3
6
  tweet.on_failure = true
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
 
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Rackspace Cloud Files [Storage]
3
+ #
1
4
  store_with CloudFiles do |cf|
2
5
  cf.api_key = 'my_api_key'
3
6
  cf.username = 'my_username'
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Dropbox File Hosting Service [Storage]
3
+ #
1
4
  store_with Dropbox do |db|
2
5
  db.email = 'my@email.com'
3
6
  db.password = 'my_password'
@@ -1,3 +1,6 @@
1
+ ##
2
+ # FTP (File Transfer Protocol) [Storage]
3
+ #
1
4
  store_with FTP do |server|
2
5
  server.username = 'my_username'
3
6
  server.password = 'my_password'
@@ -1,3 +1,6 @@
1
+ ##
2
+ # RSync [Storage]
3
+ #
1
4
  store_with RSync do |server|
2
5
  server.username = 'my_username'
3
6
  server.password = 'my_password'
@@ -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
+
@@ -1,3 +1,6 @@
1
+ ##
2
+ # SCP (Secure Copy) [Storage]
3
+ #
1
4
  store_with SCP do |server|
2
5
  server.username = 'my_username'
3
6
  server.password = 'my_password'
@@ -1,3 +1,6 @@
1
+ ##
2
+ # SFTP (Secure File Transfer Protocol) [Storage]
3
+ #
1
4
  store_with SFTP do |server|
2
5
  server.username = 'my_username'
3
6
  server.password = 'my_password'
@@ -1,3 +1,6 @@
1
+ ##
2
+ # RSync [Syncer]
3
+ #
1
4
  sync_with RSync do |rsync|
2
5
  rsync.ip = "123.45.678.90"
3
6
  rsync.port = 22
@@ -1,3 +1,6 @@
1
+ ##
2
+ # Amazon Simple Storage Service [Syncer]
3
+ #
1
4
  sync_with S3 do |s3|
2
5
  s3.access_key_id = "my_access_key_id"
3
6
  s3.secret_access_key = "my_secret_access_key"