backup 3.0.2 → 3.0.3.build.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/bin/backup +12 -190
  2. metadata +7 -191
  3. data/.gitignore +0 -2
  4. data/.infinity_test +0 -7
  5. data/.rspec +0 -3
  6. data/Gemfile +0 -17
  7. data/Gemfile.lock +0 -88
  8. data/LICENSE.md +0 -24
  9. data/README.md +0 -236
  10. data/backup.gemspec +0 -41
  11. data/lib/backup.rb +0 -148
  12. data/lib/backup/archive.rb +0 -54
  13. data/lib/backup/cli.rb +0 -50
  14. data/lib/backup/compressor/base.rb +0 -17
  15. data/lib/backup/compressor/gzip.rb +0 -61
  16. data/lib/backup/configuration/base.rb +0 -15
  17. data/lib/backup/configuration/compressor/base.rb +0 -10
  18. data/lib/backup/configuration/compressor/gzip.rb +0 -23
  19. data/lib/backup/configuration/database/base.rb +0 -18
  20. data/lib/backup/configuration/database/mongodb.rb +0 -37
  21. data/lib/backup/configuration/database/mysql.rb +0 -37
  22. data/lib/backup/configuration/database/postgresql.rb +0 -37
  23. data/lib/backup/configuration/database/redis.rb +0 -35
  24. data/lib/backup/configuration/encryptor/base.rb +0 -10
  25. data/lib/backup/configuration/encryptor/gpg.rb +0 -17
  26. data/lib/backup/configuration/encryptor/open_ssl.rb +0 -26
  27. data/lib/backup/configuration/helpers.rb +0 -54
  28. data/lib/backup/configuration/notifier/base.rb +0 -39
  29. data/lib/backup/configuration/notifier/mail.rb +0 -52
  30. data/lib/backup/configuration/storage/base.rb +0 -18
  31. data/lib/backup/configuration/storage/cloudfiles.rb +0 -21
  32. data/lib/backup/configuration/storage/dropbox.rb +0 -25
  33. data/lib/backup/configuration/storage/ftp.rb +0 -25
  34. data/lib/backup/configuration/storage/rsync.rb +0 -25
  35. data/lib/backup/configuration/storage/s3.rb +0 -25
  36. data/lib/backup/configuration/storage/scp.rb +0 -25
  37. data/lib/backup/configuration/storage/sftp.rb +0 -25
  38. data/lib/backup/database/base.rb +0 -33
  39. data/lib/backup/database/mongodb.rb +0 -137
  40. data/lib/backup/database/mysql.rb +0 -104
  41. data/lib/backup/database/postgresql.rb +0 -111
  42. data/lib/backup/database/redis.rb +0 -105
  43. data/lib/backup/encryptor/base.rb +0 -17
  44. data/lib/backup/encryptor/gpg.rb +0 -78
  45. data/lib/backup/encryptor/open_ssl.rb +0 -67
  46. data/lib/backup/finder.rb +0 -39
  47. data/lib/backup/logger.rb +0 -80
  48. data/lib/backup/model.rb +0 -249
  49. data/lib/backup/notifier/base.rb +0 -29
  50. data/lib/backup/notifier/binder.rb +0 -32
  51. data/lib/backup/notifier/mail.rb +0 -141
  52. data/lib/backup/notifier/templates/notify_failure.erb +0 -31
  53. data/lib/backup/notifier/templates/notify_success.erb +0 -16
  54. data/lib/backup/storage/base.rb +0 -67
  55. data/lib/backup/storage/cloudfiles.rb +0 -95
  56. data/lib/backup/storage/dropbox.rb +0 -82
  57. data/lib/backup/storage/ftp.rb +0 -114
  58. data/lib/backup/storage/object.rb +0 -45
  59. data/lib/backup/storage/rsync.rb +0 -100
  60. data/lib/backup/storage/s3.rb +0 -108
  61. data/lib/backup/storage/scp.rb +0 -105
  62. data/lib/backup/storage/sftp.rb +0 -106
  63. data/lib/backup/version.rb +0 -72
  64. data/lib/templates/archive +0 -4
  65. data/lib/templates/compressor/gzip +0 -4
  66. data/lib/templates/database/mongodb +0 -10
  67. data/lib/templates/database/mysql +0 -11
  68. data/lib/templates/database/postgresql +0 -11
  69. data/lib/templates/database/redis +0 -10
  70. data/lib/templates/encryptor/gpg +0 -9
  71. data/lib/templates/encryptor/openssl +0 -5
  72. data/lib/templates/notifier/mail +0 -14
  73. data/lib/templates/readme +0 -15
  74. data/lib/templates/storage/cloudfiles +0 -7
  75. data/lib/templates/storage/dropbox +0 -8
  76. data/lib/templates/storage/ftp +0 -8
  77. data/lib/templates/storage/rsync +0 -7
  78. data/lib/templates/storage/s3 +0 -8
  79. data/lib/templates/storage/scp +0 -8
  80. data/lib/templates/storage/sftp +0 -8
  81. data/spec/archive_spec.rb +0 -53
  82. data/spec/backup_spec.rb +0 -11
  83. data/spec/compressor/gzip_spec.rb +0 -59
  84. data/spec/configuration/base_spec.rb +0 -35
  85. data/spec/configuration/compressor/gzip_spec.rb +0 -28
  86. data/spec/configuration/database/base_spec.rb +0 -16
  87. data/spec/configuration/database/mongodb_spec.rb +0 -30
  88. data/spec/configuration/database/mysql_spec.rb +0 -32
  89. data/spec/configuration/database/postgresql_spec.rb +0 -32
  90. data/spec/configuration/database/redis_spec.rb +0 -30
  91. data/spec/configuration/encryptor/gpg_spec.rb +0 -25
  92. data/spec/configuration/encryptor/open_ssl_spec.rb +0 -31
  93. data/spec/configuration/notifier/mail_spec.rb +0 -32
  94. data/spec/configuration/storage/cloudfiles_spec.rb +0 -34
  95. data/spec/configuration/storage/dropbox_spec.rb +0 -40
  96. data/spec/configuration/storage/ftp_spec.rb +0 -40
  97. data/spec/configuration/storage/rsync_spec.rb +0 -37
  98. data/spec/configuration/storage/s3_spec.rb +0 -37
  99. data/spec/configuration/storage/scp_spec.rb +0 -40
  100. data/spec/configuration/storage/sftp_spec.rb +0 -40
  101. data/spec/database/base_spec.rb +0 -30
  102. data/spec/database/mongodb_spec.rb +0 -144
  103. data/spec/database/mysql_spec.rb +0 -150
  104. data/spec/database/postgresql_spec.rb +0 -164
  105. data/spec/database/redis_spec.rb +0 -122
  106. data/spec/encryptor/gpg_spec.rb +0 -57
  107. data/spec/encryptor/open_ssl_spec.rb +0 -102
  108. data/spec/logger_spec.rb +0 -37
  109. data/spec/model_spec.rb +0 -236
  110. data/spec/notifier/mail_spec.rb +0 -97
  111. data/spec/spec_helper.rb +0 -21
  112. data/spec/storage/base_spec.rb +0 -33
  113. data/spec/storage/cloudfiles_spec.rb +0 -102
  114. data/spec/storage/dropbox_spec.rb +0 -89
  115. data/spec/storage/ftp_spec.rb +0 -133
  116. data/spec/storage/object_spec.rb +0 -74
  117. data/spec/storage/rsync_spec.rb +0 -115
  118. data/spec/storage/s3_spec.rb +0 -110
  119. data/spec/storage/scp_spec.rb +0 -129
  120. data/spec/storage/sftp_spec.rb +0 -125
  121. data/spec/version_spec.rb +0 -32
@@ -1,100 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##
4
- # Only load the Net::SSH library when the Backup::Storage::RSync class is loaded
5
- require 'net/ssh'
6
-
7
- module Backup
8
- module Storage
9
- class RSync < Base
10
- include Backup::CLI
11
-
12
- ##
13
- # Server credentials
14
- attr_accessor :username, :password
15
-
16
- ##
17
- # Server IP Address and SSH port
18
- attr_accessor :ip, :port
19
-
20
- ##
21
- # Path to store backups to
22
- attr_accessor :path
23
-
24
- ##
25
- # Creates a new instance of the RSync storage object
26
- # First it sets the defaults (if any exist) and then evaluates
27
- # the configuration block which may overwrite these defaults
28
- def initialize(&block)
29
- load_defaults!
30
-
31
- @port ||= 22
32
- @path ||= 'backups'
33
-
34
- instance_eval(&block) if block_given?
35
-
36
- @time = TIME
37
- @path = path.sub(/^\~\//, '')
38
- end
39
-
40
- ##
41
- # This is the remote path to where the backup files will be stored
42
- def remote_path
43
- File.join(path, TRIGGER)
44
- end
45
-
46
- ##
47
- # Performs the backup transfer
48
- def perform!
49
- transfer!
50
- end
51
-
52
- private
53
-
54
- ##
55
- # Establishes a connection to the remote server and returns the Net::SSH object.
56
- # Not doing any instance variable caching because this object gets persisted in YAML
57
- # format to a file and will issues. This, however has no impact on performance since it only
58
- # gets invoked once per object for a #transfer! and once for a remove! Backups run in the
59
- # background anyway so even if it were a bit slower it shouldn't matter.
60
- def connection
61
- Net::SSH.start(ip, username, :password => password, :port => port)
62
- end
63
-
64
- ##
65
- # Transfers the archived file to the specified remote server
66
- def transfer!
67
- Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
68
- create_remote_directories!
69
- run("#{ utility(:rsync) } #{ options } '#{ File.join(local_path, local_file) }' '#{ username }@#{ ip }:#{ File.join(remote_path, remote_file[20..-1]) }'")
70
- end
71
-
72
- ##
73
- # Removes the transferred archive file from the server
74
- def remove!
75
- response = connection.exec!("rm #{ File.join(remote_path, remote_file) }")
76
- if response =~ /No such file or directory/
77
- Logger.warn "Could not remove file \"#{ File.join(remote_path, remote_file) }\"."
78
- end
79
- end
80
-
81
- ##
82
- # Creates (if they don't exist yet) all the directories on the remote
83
- # server in order to upload the backup file.
84
- def create_remote_directories!
85
- connection.exec!("mkdir -p '#{ remote_path }'")
86
- end
87
-
88
- ##
89
- # RSync options
90
- # -z = Compresses the bytes that will be transferred to reduce bandwidth usage
91
- # -e = Allow the usage of SSH remote shell
92
- # --port = the port to connect to through SSH
93
- # -Phv = debug options
94
- def options
95
- "-z -e ssh --port='#{ port }'"
96
- end
97
-
98
- end
99
- end
100
- end
@@ -1,108 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##
4
- # Only load the Fog gem when the Backup::Storage::S3 class is loaded
5
- require 'fog'
6
-
7
- module Backup
8
- module Storage
9
- class S3 < Base
10
-
11
- ##
12
- # Amazon Simple Storage Service (S3) Credentials
13
- attr_accessor :access_key_id, :secret_access_key
14
-
15
- ##
16
- # Amazon S3 bucket name and path
17
- attr_accessor :bucket, :path
18
-
19
- ##
20
- # Region of the specified S3 bucket
21
- attr_accessor :region
22
-
23
- ##
24
- # Creates a new instance of the Amazon S3 storage object
25
- # First it sets the defaults (if any exist) and then evaluates
26
- # the configuration block which may overwrite these defaults
27
- #
28
- # Currently available regions:
29
- # eu-west-1, us-east-1, ap-southeast-1, us-west-1
30
- def initialize(&block)
31
- load_defaults!
32
-
33
- @path ||= 'backups'
34
-
35
- instance_eval(&block) if block_given?
36
-
37
- @path = path.sub(/^\//, '')
38
- @time = TIME
39
- end
40
-
41
- ##
42
- # This is the remote path to where the backup files will be stored
43
- def remote_path
44
- File.join(path, TRIGGER, '/')
45
- end
46
-
47
- ##
48
- # This is the provider that Fog uses for the S3 Storage
49
- def provider
50
- 'AWS'
51
- end
52
-
53
- ##
54
- # Performs the backup transfer
55
- def perform!
56
- transfer!
57
- cycle!
58
- end
59
-
60
- private
61
-
62
- ##
63
- # Establishes a connection to Amazon S3 and returns the Fog object.
64
- # Not doing any instance variable caching because this object gets persisted in YAML
65
- # format to a file and will issues. This, however has no impact on performance since it only
66
- # gets invoked once per object for a #transfer! and once for a remove! Backups run in the
67
- # background anyway so even if it were a bit slower it shouldn't matter.
68
- def connection
69
- Fog::Storage.new(
70
- :provider => provider,
71
- :aws_access_key_id => access_key_id,
72
- :aws_secret_access_key => secret_access_key,
73
- :region => region
74
- )
75
- end
76
-
77
- ##
78
- # Transfers the archived file to the specified Amazon S3 bucket
79
- def transfer!
80
- begin
81
- Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
82
- connection.sync_clock
83
- connection.put_object(
84
- bucket,
85
- File.join(remote_path, remote_file),
86
- File.open(File.join(local_path, local_file))
87
- )
88
- rescue Excon::Errors::SocketError
89
- puts "\nAn error occurred while trying to transfer the backup."
90
- puts "Make sure the bucket exists, and that you specified the correct bucket region.\n\n"
91
- puts "The available regions are:\n\n"
92
- puts %w[eu-west-1 us-east-1 ap-southeast-1 us-west-1].map{ |region| "\s\s* #{region}" }.join("\n")
93
- exit
94
- end
95
- end
96
-
97
- ##
98
- # Removes the transferred archive file from the Amazon S3 bucket
99
- def remove!
100
- begin
101
- connection.sync_clock
102
- connection.delete_object(bucket, File.join(remote_path, remote_file))
103
- rescue Excon::Errors::SocketError; end
104
- end
105
-
106
- end
107
- end
108
- end
@@ -1,105 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##
4
- # Only load the Net::SSH and Net::SCP library/gems
5
- # when the Backup::Storage::SCP class is loaded
6
- require 'net/ssh'
7
- require 'net/scp'
8
-
9
- module Backup
10
- module Storage
11
- class SCP < Base
12
-
13
- ##
14
- # Server credentials
15
- attr_accessor :username, :password
16
-
17
- ##
18
- # Server IP Address and SCP port
19
- attr_accessor :ip, :port
20
-
21
- ##
22
- # Path to store backups to
23
- attr_accessor :path
24
-
25
- ##
26
- # Creates a new instance of the SCP storage object
27
- # First it sets the defaults (if any exist) and then evaluates
28
- # the configuration block which may overwrite these defaults
29
- def initialize(&block)
30
- load_defaults!
31
-
32
- @port ||= 22
33
- @path ||= 'backups'
34
-
35
- instance_eval(&block) if block_given?
36
-
37
- @time = TIME
38
- @path = path.sub(/^\~\//, '')
39
- end
40
-
41
- ##
42
- # This is the remote path to where the backup files will be stored
43
- def remote_path
44
- File.join(path, TRIGGER)
45
- end
46
-
47
- ##
48
- # Performs the backup transfer
49
- def perform!
50
- transfer!
51
- cycle!
52
- end
53
-
54
- private
55
-
56
- ##
57
- # Establishes a connection to the remote server and returns the Net::SCP object.
58
- # Not doing any instance variable caching because this object gets persisted in YAML
59
- # format to a file and will issues. This, however has no impact on performance since it only
60
- # gets invoked once per object for a #transfer! and once for a remove! Backups run in the
61
- # background anyway so even if it were a bit slower it shouldn't matter.
62
- #
63
- # We will be using Net::SSH, and use Net::SCP through Net::SSH to transfer backups
64
- def connection
65
- Net::SSH.start(ip, username, :password => password, :port => port)
66
- end
67
-
68
- ##
69
- # Transfers the archived file to the specified remote server
70
- def transfer!
71
- Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
72
- create_remote_directories!
73
- connection.scp.upload!(
74
- File.join(local_path, local_file),
75
- File.join(remote_path, remote_file)
76
- )
77
- end
78
-
79
- ##
80
- # Removes the transferred archive file from the server
81
- def remove!
82
- response = connection.exec!("rm #{ File.join(remote_path, remote_file) }")
83
- if response =~ /No such file or directory/
84
- Logger.warn "Could not remove file \"#{ File.join(remote_path, remote_file) }\"."
85
- end
86
- end
87
-
88
- ##
89
- # Creates (if they don't exist yet) all the directories on the remote
90
- # server in order to upload the backup file. Net::SCP does not support
91
- # paths to directories that don't yet exist when creating new directories.
92
- # Instead, we split the parts up in to an array (for each '/') and loop through
93
- # that to create the directories one by one. Net::SCP raises an exception when
94
- # the directory it's trying ot create already exists, so we have rescue it
95
- def create_remote_directories!
96
- path_parts = Array.new
97
- remote_path.split('/').each do |path_part|
98
- path_parts << path_part
99
- connection.exec!("mkdir '#{ path_parts.join('/') }'")
100
- end
101
- end
102
-
103
- end
104
- end
105
- end
@@ -1,106 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##
4
- # Only load the Net::SFTP library/gem when the Backup::Storage::SFTP class is loaded
5
- require 'net/sftp'
6
-
7
- module Backup
8
- module Storage
9
- class SFTP < Base
10
-
11
- ##
12
- # Server credentials
13
- attr_accessor :username, :password
14
-
15
- ##
16
- # Server IP Address and SFTP port
17
- attr_accessor :ip, :port
18
-
19
- ##
20
- # Path to store backups to
21
- attr_accessor :path
22
-
23
- ##
24
- # Creates a new instance of the SFTP storage object
25
- # First it sets the defaults (if any exist) and then evaluates
26
- # the configuration block which may overwrite these defaults
27
- def initialize(&block)
28
- load_defaults!
29
-
30
- @port ||= 22
31
- @path ||= 'backups'
32
-
33
- instance_eval(&block) if block_given?
34
-
35
- @time = TIME
36
- @path = path.sub(/^\~\//, '')
37
- end
38
-
39
- ##
40
- # This is the remote path to where the backup files will be stored
41
- def remote_path
42
- File.join(path, TRIGGER)
43
- end
44
-
45
- ##
46
- # Performs the backup transfer
47
- def perform!
48
- transfer!
49
- cycle!
50
- end
51
-
52
- private
53
-
54
- ##
55
- # Establishes a connection to the remote server and returns the Net::SFTP object.
56
- # Not doing any instance variable caching because this object gets persisted in YAML
57
- # format to a file and will issues. This, however has no impact on performance since it only
58
- # gets invoked once per object for a #transfer! and once for a remove! Backups run in the
59
- # background anyway so even if it were a bit slower it shouldn't matter.
60
- def connection
61
- Net::SFTP.start(ip, username, :password => password, :port => port)
62
- end
63
-
64
- ##
65
- # Transfers the archived file to the specified remote server
66
- def transfer!
67
- Logger.message("#{ self.class } started transferring \"#{ remote_file }\".")
68
- create_remote_directories!
69
- connection.upload!(
70
- File.join(local_path, local_file),
71
- File.join(remote_path, remote_file)
72
- )
73
- end
74
-
75
- ##
76
- # Removes the transferred archive file from the server
77
- def remove!
78
- begin
79
- connection.remove!(
80
- File.join(remote_path, remote_file)
81
- )
82
- rescue Net::SFTP::StatusException
83
- Logger.warn "Could not remove file \"#{ File.join(remote_path, remote_file) }\"."
84
- end
85
- end
86
-
87
- ##
88
- # Creates (if they don't exist yet) all the directories on the remote
89
- # server in order to upload the backup file. Net::SFTP does not support
90
- # paths to directories that don't yet exist when creating new directories.
91
- # Instead, we split the parts up in to an array (for each '/') and loop through
92
- # that to create the directories one by one. Net::SFTP raises an exception when
93
- # the directory it's trying ot create already exists, so we have rescue it
94
- def create_remote_directories!
95
- path_parts = Array.new
96
- remote_path.split('/').each do |path_part|
97
- path_parts << path_part
98
- begin
99
- connection.mkdir!(path_parts.join('/'))
100
- rescue Net::SFTP::StatusException; end
101
- end
102
- end
103
-
104
- end
105
- end
106
- end
@@ -1,72 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Backup
4
-
5
- ##
6
- # Usage:
7
- #
8
- # # Returns the current backup version based on the defined constants
9
- # Backup::Version.current
10
- #
11
- # # Returns a gemspec compatible version number based on the defined constants
12
- # Backup::Version.gemspec
13
- #
14
- class Version
15
-
16
- ##
17
- # MAJOR:
18
- # Defines the major version
19
- # MINOR:
20
- # Defines the minor version
21
- # PATCH:
22
- # Defines the patch version
23
- # BUILD:
24
- # Defines the build version ( use 'false' if no build )
25
- MAJOR, MINOR, PATCH, BUILD = 3, 0, 2, false
26
-
27
- # ========================================================= #
28
- # ADJUST THE CONSTANTS ABOVE TO CHANGE THE BACKUP VERSION #
29
- # ========================================================= #
30
-
31
- ##
32
- # Returns the major version ( big release based off of multiple minor releases )
33
- def self.major
34
- MAJOR
35
- end
36
-
37
- ##
38
- # Returns the minor version ( small release based off of multiple patches )
39
- def self.minor
40
- MINOR
41
- end
42
-
43
- ##
44
- # Returns the patch version ( updates, features and (crucial) bug fixes based off of multiple builds )
45
- def self.patch
46
- PATCH
47
- end
48
-
49
- ##
50
- # Returns the build version ( improvements, small additions, frequent releases )
51
- def self.build
52
- BUILD
53
- end
54
-
55
- ##
56
- # Returns the current version ( not for gemspec / rubygems )
57
- def self.current
58
- "#{major}.#{minor}.#{patch} / build #{build or 0}"
59
- end
60
-
61
- ##
62
- # Returns the (gemspec qualified) current version
63
- def self.gemspec
64
- if build.eql?(false)
65
- "#{major}.#{minor}.#{patch}"
66
- else
67
- "#{major}.#{minor}.#{patch}.build.#{build}"
68
- end
69
- end
70
-
71
- end
72
- end