backup 2.3.2.pre3 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,12 +1,41 @@
1
- === 2.?.? ====================================
1
+ UPDATE
2
+ === 2.3.2 =======================================
3
+
4
+ - Only load 'pony' and 'optparse' when they need to be utilized.
5
+ - Only uses 'sudo' if BACKUP_PATH is not writable by current user.
6
+ - With Cloud Files storage, it will automatically create the bucket if it does not yet exist.
7
+ - Backup's logger will now display the current time when logging. Now also indicates what S3 bucket it
8
+ is being backed up to, as well as what the filename is.
9
+ - Backup now supports GPG public key encryption which is a new and more safe way to encrypt your data.
10
+
11
+
12
+ MINOR UPDATE
13
+ === 2.3.2.pre3 ==================================
14
+
15
+ - Added support for Rackspace Cloud Files. Backups can now also be stored in Rackspace Cloud Files.
16
+
17
+
18
+ MINOR UPDATE
19
+ === 2.3.2.pre2 ==================================
20
+
21
+ - Added support for Amazon S3 EEUU and European buckets.
22
+
23
+
24
+ BIG UPDATE
25
+ === 2.3.2.pre ==================================
2
26
 
3
27
  - Added Storage Method: Local
4
28
  - Added Adapter: SQLite
5
29
  - exclude option added for Archive Adapter
6
30
  - Internal cleanup
7
31
  - Will try to automatically determine the path to mysqldump and pg_dump utilities
32
+ - Option to specify which tables to include for the backup
33
+ - The ability to specify a custom backup (unix environment) installation folder with ENV['BACKUP_PATH']
34
+ - Fixed dependency issue with SQLite3 Ruby Driver (must be 1.2.5)
35
+ - Removed Jeweler from Backup, the Gemspec should be manually updated from now on.
8
36
  - Added spec/tests
9
37
 
38
+
10
39
  MINOR UPDATE
11
40
  === 2.3.1 ======================================
12
41
 
data/LICENSE CHANGED
@@ -1,4 +1,15 @@
1
- Copyright (c) 2009 Michael van Rooijen - Final Creation (http://final-creation.com)
1
+ Copyright (c) 2009 Michael van Rooijen - Final Creation (http://michaelvanrooijen.com/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
2
13
 
3
14
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4
15
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
@@ -6,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
6
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
7
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
8
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
9
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # Backup
2
+
3
+ ## A Backup Ruby Gem
4
+
5
+ Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as MySQL/PostgreSQL/SQLite and Files/Folders. All backups can be transferred to Amazon S3, Rackspace Cloud Files, any remote server you have access to (using either SCP, SFTP or regular FTP), or a Local server. Backup handles Compression, Archiving, Encryption, Backup Cleaning (Cycling) and supports Email Notifications.
6
+
7
+ ## Authors/Maintainers
8
+
9
+ * [Meskyanichi - Michael van Rooijen](http://github.com/meskyanichi)
10
+ * [Fernandoluizao - Fernando Migliorini Luizão](http://github.com/fernandoluizao)
11
+
12
+ ## Backup's Current Capabilities
13
+
14
+ ### Storage Methods
15
+
16
+ * Amazon S3
17
+ * Rackspace Cloud Files
18
+ * Remote Server (Available Protocols: SCP, SFTP, FTP)
19
+ * Local server (Example Locations: Another Hard Drive, Network path)
20
+
21
+ ### Adapters
22
+
23
+ * MySQL
24
+ * PostgreSQL
25
+ * SQLite
26
+ * Archive (Any files and/or folders)
27
+ * Custom (Anything you can produce using the command line)
28
+
29
+ ### Archiving
30
+
31
+ Handles archiving for the __Archive__ and __Custom__ adapters.
32
+
33
+ ### Encryption
34
+
35
+ Handles encryption of __all__ backups for __any__ adapter.
36
+ To decrypt a "Backup encrypted file" you can use Backup's built-in utility command:
37
+
38
+ sudo backup --decrypt /path/to/encrypted/file.enc
39
+
40
+ ### Backup Cleaning
41
+
42
+ With Backup you can very easily specify how many backups you would like to have stored (per backup procedure!) on your Amazon S3, Remote or Local server. When the limit you specify gets exceeded, the oldest backup will automatically be cleaned up.
43
+
44
+ ### Email Notifications
45
+
46
+ You will be able to specify whether you would like to be notified by email when a backup successfully been stored.
47
+ Simply fill in the email configuration block and set "notify" to true inside the backup procedure you would like to be notified of.
48
+
49
+ ### Quick Example of a Single Backup Setting/Procedure inside the Backup Configuration File
50
+
51
+ backup 'mysql-backup-s3' do
52
+ adapter :mysql do
53
+ user 'user'
54
+ password 'password'
55
+ database 'database'
56
+ end
57
+ storage :s3 do
58
+ access_key_id 'access_key_id'
59
+ secret_access_key 'secret_access_key'
60
+ bucket '/bucket/backups/mysql/'
61
+ use_ssl true
62
+ end
63
+ keep_backups 25
64
+ encrypt_with_password 'my_password'
65
+ notify true
66
+ end
67
+
68
+ Everything above should be pretty straightforward, so now, using the __trigger__ we specified between
69
+ the `backup` and `do` you can execute this backup procedure like so:
70
+
71
+ __Rails Environment__
72
+
73
+ rake backup:run trigger=mysql-backup-s3
74
+
75
+ __Unix Environment__
76
+
77
+ sudo backup --run mysql-backup-s3
78
+
79
+ That's it. This was a simple example of how it works.
80
+
81
+ ## Interested in trying out Backup?
82
+
83
+ ### Getting started with Backup for the *Unix Environment*
84
+
85
+ [http://wiki.github.com/meskyanichi/backup/getting-started-unix](http://wiki.github.com/meskyanichi/backup/getting-started-unix)
86
+
87
+
88
+ ### Getting started with Backup for the *Rails Environment*
89
+
90
+ [http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails](http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails)
91
+
92
+
93
+ ### Production Mode __RAILS_ENV___
94
+
95
+ [http://wiki.github.com/meskyanichi/backup/production-mode](http://wiki.github.com/meskyanichi/backup/production-mode)
96
+
97
+
98
+ ### Encrypting and Decrypting
99
+
100
+ [http://wiki.github.com/meskyanichi/backup/encrypting-and-decrypting](http://wiki.github.com/meskyanichi/backup/encrypting-and-decrypting)
101
+
102
+
103
+ ### Backup Configuration File (All Adapters, Storage Methods, Mail Settings and Options)
104
+
105
+ [http://wiki.github.com/meskyanichi/backup/configuration-file](http://wiki.github.com/meskyanichi/backup/configuration-file)
106
+
107
+
108
+ ### Unix Utility Commands and Rails Rake Tasks
109
+
110
+ [http://wiki.github.com/meskyanichi/backup/utility-commands](http://wiki.github.com/meskyanichi/backup/utility-commands)
111
+
112
+ [http://wiki.github.com/meskyanichi/backup/rake-tasks](http://wiki.github.com/meskyanichi/backup/rake-tasks)
113
+
114
+
115
+ ### Automatic Backups
116
+
117
+ [http://wiki.github.com/meskyanichi/backup/automatic-backups](http://wiki.github.com/meskyanichi/backup/automatic-backups)
118
+
119
+
120
+ ### Capistrano Recipes
121
+
122
+ [http://wiki.github.com/meskyanichi/backup/capistrano-recipes](http://wiki.github.com/meskyanichi/backup/capistrano-recipes)
123
+
124
+
125
+ ### Capistrano, Whenever!
126
+
127
+ [http://wiki.github.com/meskyanichi/backup/capistrano-whenever](http://wiki.github.com/meskyanichi/backup/capistrano-whenever)
128
+
129
+
130
+ ### Understanding "The Backup Database"
131
+
132
+ [http://wiki.github.com/meskyanichi/backup/the-backup-database](http://wiki.github.com/meskyanichi/backup/the-backup-database)
133
+
134
+
135
+ ### Trouble Shooting
136
+
137
+ [http://wiki.github.com/meskyanichi/backup/troubleshooting](http://wiki.github.com/meskyanichi/backup/troubleshooting)
138
+
139
+
140
+ ### Requirements
141
+
142
+ [http://wiki.github.com/meskyanichi/backup/requirements](http://wiki.github.com/meskyanichi/backup/requirements)
143
+
144
+
145
+ ### Resources
146
+
147
+ [http://wiki.github.com/meskyanichi/backup/resources](http://wiki.github.com/meskyanichi/backup/resources)
148
+
149
+
150
+ ### Requests
151
+
152
+ If anyone has any requests, please send us a message or post it in the [issue log](http://github.com/meskyanichi/backup/issues)!
153
+
154
+
155
+ ### Suggestions?
156
+
157
+ Send us a message! Fork the project!
158
+
159
+
160
+ ### Found a Bug?
161
+
162
+ [Report it](http://github.com/meskyanichi/backup/issues)
163
+
164
+
165
+ ### Contributors
166
+
167
+ * [dtrueman](http://github.com/dtrueman)
168
+ * [Nathan L Smith](http://github.com/smith)
169
+ * [Francesc Esplugas](http://github.com/fesplugas)
170
+ * [wakiki](http://github.com/wakiki)
171
+ * [Dan Hixon](http://github.com/danhixon)
172
+ * [Adam Greene](http://github.com/skippy)
173
+
174
+ __Michael van Rooijen | Final Creation. ([http://michaelvanrooijen.com](http://michaelvanrooijen.com))__
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.2.pre2
1
+ 2.3.2
data/bin/backup CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'backup'
4
5
 
5
6
  include Backup::Environment::Unix::Commands
@@ -21,15 +22,7 @@ optparse = OptionParser.new do |opts|
21
22
  confirm_configuration_file_existence
22
23
  puts "Finding backup records with trigger: #{trigger}."
23
24
  backup = Backup::Setup.new(trigger, @backup_procedures)
24
- records = Array.new
25
- case backup.procedure.storage_name.to_sym
26
- when :cloudfiles then records = Backup::Record::CloudFiles.all :conditions => {:trigger => trigger}
27
- when :s3 then records = Backup::Record::S3.all :conditions => {:trigger => trigger}
28
- when :scp then records = Backup::Record::SCP.all :conditions => {:trigger => trigger}
29
- when :ftp then records = Backup::Record::FTP.all :conditions => {:trigger => trigger}
30
- when :sftp then records = Backup::Record::SFTP.all :conditions => {:trigger => trigger}
31
- when :local then records = Backup::Record::Local.all :conditions => {:trigger => trigger}
32
- end
25
+ records = backup.procedure.record_class.all( :conditions => {:trigger => trigger} )
33
26
 
34
27
  if options[:table]
35
28
  puts Hirb::Helpers::AutoTable.render(records)
@@ -49,14 +42,7 @@ optparse = OptionParser.new do |opts|
49
42
  confirm_configuration_file_existence
50
43
  puts "Destroying backup records with trigger: #{trigger}."
51
44
  backup = Backup::Setup.new(trigger, @backup_procedures)
52
- case backup.procedure.storage_name.to_sym
53
- when :cloudfiles then Backup::Record::CloudFiles.destroy_all_backups backup.procedure, trigger
54
- when :s3 then Backup::Record::S3.destroy_all_backups backup.procedure, trigger
55
- when :scp then Backup::Record::SCP.destroy_all_backups backup.procedure, trigger
56
- when :ftp then Backup::Record::FTP.destroy_all_backups backup.procedure, trigger
57
- when :sftp then Backup::Record::SFTP.destroy_all_backups backup.procedure, trigger
58
- when :local then Backup::Record::Local.destroy_all_backups backup.procedure, trigger
59
- end
45
+ backup.procedure.record_class.destroy_all_backups( backup.procedure, trigger )
60
46
  end
61
47
 
62
48
  opts.on('--truncate-all', "Truncates all backup records") do
@@ -69,14 +55,7 @@ optparse = OptionParser.new do |opts|
69
55
  puts "Destroying all backup records."
70
56
  backup = Backup::Setup.new(false, @backup_procedures)
71
57
  backup.procedures.each do |backup_procedure|
72
- case backup_procedure.storage_name.to_sym
73
- when :cloudfiles then Backup::Record::CloudFiles.destroy_all_backups backup_procedure, backup_procedure.trigger
74
- when :s3 then Backup::Record::S3.destroy_all_backups backup_procedure, backup_procedure.trigger
75
- when :scp then Backup::Record::SCP.destroy_all_backups backup_procedure, backup_procedure.trigger
76
- when :ftp then Backup::Record::FTP.destroy_all_backups backup_procedure, backup_procedure.trigger
77
- when :sftp then Backup::Record::SFTP.destroy_all_backups backup_procedure, backup_procedure.trigger
78
- when :local then Backup::Record::Local.destroy_all_backups backup.procedure, backup_procedure.trigger
79
- end
58
+ backup_procedure.record_class.destroy_all_backups( backup_procedure, backup_procedure.trigger )
80
59
  end
81
60
  end
82
61
 
@@ -22,6 +22,7 @@
22
22
  #
23
23
  # STORAGE METHODS
24
24
  # - S3 (Amazon)
25
+ # - CF (Rackspace Cloud Files)
25
26
  # - SCP (Remote Server)
26
27
  # - FTP (Remote Server)
27
28
  # - SFTP (Remote Server)
@@ -103,6 +104,22 @@ backup 'mysql-backup-s3' do
103
104
 
104
105
  end
105
106
 
107
+ # Initialize with:
108
+ # rake backup:run trigger='mysql-backup-cloudfiles'
109
+ backup 'mysql-backup-cloudfiles' do
110
+
111
+ adapter :mysql do
112
+ user 'user'
113
+ password 'password'
114
+ database 'database'
115
+ end
116
+
117
+ storage :cloudfiles do
118
+ username 'username'
119
+ api_key 'api_key'
120
+ container 'mysql_backup'
121
+ end
122
+ end
106
123
 
107
124
  # Initialize with:
108
125
  # rake backup:run trigger='postgresql-backup-s3'
@@ -199,4 +216,4 @@ backup 'sqlite-backup-local' do
199
216
  encrypt_with_password false
200
217
  notify false
201
218
 
202
- end
219
+ end
@@ -10,14 +10,7 @@ namespace :backup do
10
10
  task :find => :environment do
11
11
  puts "Finding backup records with trigger: #{ENV['trigger']}."
12
12
  backup = Backup::Setup.new(ENV['trigger'], @backup_procedures)
13
- records = Array.new
14
- case backup.procedure.storage_name.to_sym
15
- when :s3 then records = Backup::Record::S3.all :conditions => {:trigger => ENV['trigger']}
16
- when :scp then records = Backup::Record::SCP.all :conditions => {:trigger => ENV['trigger']}
17
- when :ftp then records = Backup::Record::FTP.all :conditions => {:trigger => ENV['trigger']}
18
- when :sftp then records = Backup::Record::SFTP.all :conditions => {:trigger => ENV['trigger']}
19
- when :local then records = Backup::Record::Local.all :conditions => {:trigger => ENV['trigger']}
20
- end
13
+ records = backup.procedure.record_class.all( :conditions => {:trigger => ENV['trigger']} )
21
14
 
22
15
  if ENV['table'].eql?("true")
23
16
  puts Hirb::Helpers::AutoTable.render(records)
@@ -44,13 +37,7 @@ namespace :backup do
44
37
  task :destroy => :environment do
45
38
  puts "Destroying backup records with trigger: #{ENV['trigger']}."
46
39
  backup = Backup::Setup.new(ENV['trigger'], @backup_procedures)
47
- case backup.procedure.storage_name.to_sym
48
- when :s3 then Backup::Record::S3.destroy_all_backups backup.procedure, ENV['trigger']
49
- when :scp then Backup::Record::SCP.destroy_all_backups backup.procedure, ENV['trigger']
50
- when :ftp then Backup::Record::FTP.destroy_all_backups backup.procedure, ENV['trigger']
51
- when :sftp then Backup::Record::SFTP.destroy_all_backups backup.procedure, ENV['trigger']
52
- when :local then Backup::Record::Local.destroy_all_backups backup.procedure, ENV['trigger']
53
- end
40
+ backup.procedure.record_class.destroy_all_backups( backup.procedure, ENV['trigger'] )
54
41
  end
55
42
 
56
43
  desc "Destroys all records for the specified \"trigger\", including the physical files on s3 or the remote server."
@@ -58,13 +45,7 @@ namespace :backup do
58
45
  puts "Destroying all backup records."
59
46
  backup = Backup::Setup.new(false, @backup_procedures)
60
47
  backup.procedures.each do |backup_procedure|
61
- case backup_procedure.storage_name.to_sym
62
- when :s3 then Backup::Record::S3.destroy_all_backups backup_procedure, backup_procedure.trigger
63
- when :scp then Backup::Record::SCP.destroy_all_backups backup_procedure, backup_procedure.trigger
64
- when :ftp then Backup::Record::FTP.destroy_all_backups backup_procedure, backup_procedure.trigger
65
- when :sftp then Backup::Record::SFTP.destroy_all_backups backup_procedure, backup_procedure.trigger
66
- when :local then Backup::Record::Local.destroy_all_backups backup_procedure, backup_procedure.trigger
67
- end
48
+ backup_procedure.record_class.destroy_all_backups( backup_procedure, backup_procedure.trigger )
68
49
  end
69
50
  end
70
51
 
data/lib/backup.rb CHANGED
@@ -51,6 +51,7 @@ module Backup
51
51
  end
52
52
 
53
53
  module Storage
54
+ autoload :Base, 'backup/storage/base'
54
55
  autoload :CloudFiles, 'backup/storage/cloudfiles'
55
56
  autoload :S3, 'backup/storage/s3'
56
57
  autoload :SCP, 'backup/storage/scp'
@@ -4,7 +4,7 @@ module Backup
4
4
 
5
5
  include Backup::CommandHelper
6
6
 
7
- attr_accessor :procedure, :timestamp, :options, :tmp_path, :encrypt_with_password, :keep_backups, :trigger
7
+ attr_accessor :procedure, :timestamp, :options, :tmp_path, :encrypt_with_password, :encrypt_with_gpg_public_key, :keep_backups, :trigger
8
8
 
9
9
  # IMPORTANT
10
10
  # final_file must have the value of the final filename result
@@ -12,7 +12,9 @@ module Backup
12
12
  # myfile.gz
13
13
  #
14
14
  # and if a file afterwards gets encrypted, the file will look like:
15
- # myfile.gz.enc
15
+ # myfile.gz.enc (with a password)
16
+ # myfile.gz.gpg (with a gpg public key)
17
+ #
16
18
  #
17
19
  # It is important that, whatever the final filename of the file will be, that :final_file will contain it.
18
20
  attr_accessor :performed_file, :compressed_file, :encrypted_file, :final_file
@@ -31,16 +33,16 @@ module Backup
31
33
  #
32
34
  # Wrapped inside of begin/ensure/end block to ensure the deletion of any files in the tmp directory
33
35
  def initialize(trigger, procedure)
34
- self.trigger = trigger
35
- self.procedure = procedure
36
- self.timestamp = Time.now.strftime("%Y%m%d%H%M%S")
37
- self.tmp_path = File.join(BACKUP_PATH.gsub(' ', '\ '), 'tmp', 'backup', trigger)
38
- self.encrypt_with_password = procedure.attributes['encrypt_with_password']
39
- self.keep_backups = procedure.attributes['keep_backups']
36
+ self.trigger = trigger
37
+ self.procedure = procedure
38
+ self.timestamp = Time.now.strftime("%Y%m%d%H%M%S")
39
+ self.tmp_path = File.join(BACKUP_PATH.gsub(' ', '\ '), 'tmp', 'backup', trigger)
40
+ self.encrypt_with_password = procedure.attributes['encrypt_with_password']
41
+ self.encrypt_with_gpg_public_key = procedure.attributes['encrypt_with_gpg_public_key']
42
+ self.keep_backups = procedure.attributes['keep_backups']
40
43
 
41
44
  self.performed_file = "#{timestamp}.#{trigger.gsub(' ', '-')}#{performed_file_extension}"
42
45
  self.compressed_file = "#{performed_file}.gz"
43
- self.encrypted_file = "#{compressed_file}.enc"
44
46
  self.final_file = compressed_file
45
47
 
46
48
  begin
@@ -72,11 +74,33 @@ module Backup
72
74
 
73
75
  # Encrypts the archive file
74
76
  def encrypt
75
- if encrypt_with_password.is_a?(String)
76
- log system_messages[:encrypting]
77
+ if encrypt_with_gpg_public_key.is_a?(String) && encrypt_with_password.is_a?(String)
78
+ puts "both 'encrypt_with_gpg_public_key' and 'encrypt_with_password' are set. Please choose one or the other. Exiting."
79
+ exit 1
80
+ end
81
+
82
+ if encrypt_with_gpg_public_key.is_a?(String)
83
+ if `which gpg` == ''
84
+ puts "Encrypting with a GPG public key requires that gpg be in your public path. gpg was not found. Exiting"
85
+ exit 1
86
+ end
87
+ log system_messages[:encrypting_w_key]
88
+ self.encrypted_file = "#{self.final_file}.gpg"
89
+
90
+ # tmp_file = Tempfile.new('backup.pub'){ |tmp_file| tmp_file << encrypt_with_gpg_public_key }
91
+ tmp_file = Tempfile.new('backup.pub')
92
+ tmp_file << encrypt_with_gpg_public_key
93
+ tmp_file.close
94
+ # that will either say the key was added OR that it wasn't needed, but either way we need to parse for the uid
95
+ # which will be wrapped in '<' and '>' like <sweetspot-backup2007@6bar8.com>
96
+ encryptionKeyId = `gpg --import #{tmp_file.path} 2>&1`.match(/<(.+)>/)[1]
97
+ run "gpg -e --trust-model always -o #{File.join(tmp_path, encrypted_file)} -r '#{encryptionKeyId}' #{File.join(tmp_path, compressed_file)}"
98
+ elsif encrypt_with_password.is_a?(String)
99
+ log system_messages[:encrypting_w_pass]
100
+ self.encrypted_file = "#{self.final_file}.enc"
77
101
  run "openssl enc -des-cbc -in #{File.join(tmp_path, compressed_file)} -out #{File.join(tmp_path, encrypted_file)} -k #{encrypt_with_password}"
78
- self.final_file = encrypted_file
79
102
  end
103
+ self.final_file = encrypted_file
80
104
  end
81
105
 
82
106
  # Initializes the storing process
@@ -99,13 +123,14 @@ module Backup
99
123
  end
100
124
 
101
125
  def system_messages
102
- { :compressing => "Compressing backup..",
103
- :archiving => "Archiving backup..",
104
- :encrypting => "Encrypting backup..",
105
- :mysqldump => "Creating MySQL dump..",
106
- :pgdump => "Creating PostgreSQL dump..",
107
- :sqlite => "Copying and compressing SQLite database..",
108
- :commands => "Executing commands.." }
126
+ { :compressing => "Compressing backup..",
127
+ :archiving => "Archiving backup..",
128
+ :encrypting_w_pass => "Encrypting backup with password..",
129
+ :encrypting_w_key => "Encrypting backup with gpg public key..",
130
+ :mysqldump => "Creating MySQL dump..",
131
+ :pgdump => "Creating PostgreSQL dump..",
132
+ :sqlite => "Copying and compressing SQLite database..",
133
+ :commands => "Executing commands.." }
109
134
  end
110
135
 
111
136
  end
@@ -5,7 +5,7 @@ module Backup
5
5
  end
6
6
 
7
7
  def log(command)
8
- puts "Backup => #{command}"
8
+ puts "Backup (#{Time.now.strftime("%Y-%m-%d %H:%M:%S %Z")}) => #{command}"
9
9
  end
10
10
  end
11
11
  end
@@ -2,7 +2,7 @@ module Backup
2
2
  module Configuration
3
3
  class Base
4
4
  extend Backup::Configuration::Attributes
5
- generate_attributes %w(encrypt_with_password keep_backups notify)
5
+ generate_attributes %w(encrypt_with_password encrypt_with_gpg_public_key keep_backups notify)
6
6
 
7
7
  attr_accessor :trigger, :storage_name, :adapter_name
8
8
 
@@ -22,28 +22,36 @@ module Backup
22
22
  @storage_configuration.instance_eval &block
23
23
  end
24
24
 
25
- # Initializes the storing process depending on the store settings
26
- def initialize_storage(adapter)
25
+ def storage_class
27
26
  case @storage_name.to_sym
28
- when :cloudfiles then Backup::Storage::CloudFiles.new(adapter)
29
- when :s3 then Backup::Storage::S3.new(adapter)
30
- when :scp then Backup::Storage::SCP.new(adapter)
31
- when :ftp then Backup::Storage::FTP.new(adapter)
32
- when :sftp then Backup::Storage::SFTP.new(adapter)
33
- when :local then Backup::Storage::Local.new(adapter)
27
+ when :cloudfiles then Backup::Storage::CloudFiles
28
+ when :s3 then Backup::Storage::S3
29
+ when :scp then Backup::Storage::SCP
30
+ when :ftp then Backup::Storage::FTP
31
+ when :sftp then Backup::Storage::SFTP
32
+ when :local then Backup::Storage::Local
34
33
  end
35
34
  end
36
35
 
37
- def initialize_record
36
+ def record_class
38
37
  case @storage_name.to_sym
39
- when :cloudfiles then Backup::Record::CloudFiles.new
40
- when :s3 then Backup::Record::S3.new
41
- when :scp then Backup::Record::SCP.new
42
- when :ftp then Backup::Record::FTP.new
43
- when :sftp then Backup::Record::SFTP.new
44
- when :local then Backup::Record::Local.new
38
+ when :cloudfiles then Backup::Record::CloudFiles
39
+ when :s3 then Backup::Record::S3
40
+ when :scp then Backup::Record::SCP
41
+ when :ftp then Backup::Record::FTP
42
+ when :sftp then Backup::Record::SFTP
43
+ when :local then Backup::Record::Local
45
44
  end
46
45
  end
46
+
47
+ # Initializes the storing process depending on the store settings
48
+ def initialize_storage(adapter)
49
+ storage_class.new(adapter)
50
+ end
51
+
52
+ def initialize_record
53
+ record_class.new
54
+ end
47
55
 
48
56
  def get_adapter_configuration
49
57
  @adapter_configuration
@@ -37,7 +37,9 @@ module Backup
37
37
 
38
38
  # Wrapper for the Bucket object
39
39
  def bucket
40
- service.buckets.find(s3_bucket)
40
+ bucket = service.buckets.build(s3_bucket)
41
+ bucket.save
42
+ bucket.retrieve
41
43
  end
42
44
 
43
45
  # Initializes the file transfer to Amazon S3
@@ -3,7 +3,6 @@ module Backup
3
3
  module Unix
4
4
 
5
5
  require 'active_record'
6
- require 'optparse'
7
6
 
8
7
  # Sets BACKUP_PATH
9
8
  BACKUP_PATH = ENV['BACKUP_PATH'] || "/opt/backup"
@@ -21,9 +20,9 @@ module Backup
21
20
  def setup
22
21
  unless File.directory?(BACKUP_PATH)
23
22
  puts "Installing Backup in #{BACKUP_PATH}.."
24
- %x{ sudo mkdir -p #{File.join(BACKUP_PATH, 'config')} }
25
- %x{ sudo cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.sqlite3')} #{BACKUP_PATH} }
26
- %x{ sudo cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.rb')} #{File.join(BACKUP_PATH, 'config')} }
23
+ %x{ #{sudo} mkdir -p #{File.join(BACKUP_PATH, 'config')} }
24
+ %x{ #{sudo} cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.sqlite3')} #{BACKUP_PATH} }
25
+ %x{ #{sudo} cp #{File.join(File.dirname(__FILE__), '..', '..', '..', 'setup', 'backup.rb')} #{File.join(BACKUP_PATH, 'config')} }
27
26
  puts <<-MESSAGE
28
27
 
29
28
  ==============================================================
@@ -72,7 +71,7 @@ module Backup
72
71
 
73
72
  def remove
74
73
  puts "Removing Backup..\n"
75
- %x{ sudo rm -rf #{BACKUP_PATH} }
74
+ %x{ #{sudo} rm -rf #{BACKUP_PATH} }
76
75
  end
77
76
  end
78
77
 
@@ -86,9 +85,25 @@ module Backup
86
85
  exit
87
86
  end
88
87
  end
89
-
88
+
89
+ def sudo
90
+ if writable?(BACKUP_PATH)
91
+ ""
92
+ else
93
+ "sudo"
94
+ end
95
+ end
96
+
97
+ private
98
+ def writable?(f)
99
+ unless File.exists?(f)
100
+ writable?(File.dirname(f))
101
+ else
102
+ File.writable?(f)
103
+ end
104
+ end
90
105
  end
91
106
 
92
107
  end
93
108
  end
94
- end
109
+ end
@@ -1,5 +1,3 @@
1
- require 'pony'
2
-
3
1
  module Backup
4
2
  module Mail
5
3
  class Base
@@ -34,6 +32,8 @@ module Backup
34
32
  # Requires the Backup Object
35
33
  def self.notify!(backup)
36
34
  if self.setup? and backup.procedure.attributes['notify'].eql?(true)
35
+ require 'pony'
36
+
37
37
  @backup = backup
38
38
  self.parse_body
39
39
  Pony.mail({
@@ -67,6 +67,7 @@ module Backup
67
67
  end
68
68
 
69
69
  def self.gsub_content(lines)
70
+ container = @backup.procedure.get_storage_configuration.attributes['container']
70
71
  bucket = @backup.procedure.get_storage_configuration.attributes['bucket']
71
72
  path = @backup.procedure.get_storage_configuration.attributes['path']
72
73
  ip = @backup.procedure.get_storage_configuration.attributes['ip']
@@ -78,9 +79,10 @@ module Backup
78
79
  line.gsub!(':year', Time.now.strftime("%Y"))
79
80
  line.gsub!(':time', Time.now.strftime("%r"))
80
81
  line.gsub!(':adapter', @backup.procedure.adapter_name.to_s)
81
- line.gsub!(':location', bucket || path)
82
+ line.gsub!(':location', container || bucket || path)
82
83
  line.gsub!(':backup', @backup.final_file)
83
84
  case @backup.procedure.storage_name.to_sym
85
+ when :cloudfiles then line.gsub!(':remote', "on Rackspace Cloudfiles")
84
86
  when :s3 then line.gsub!(':remote', "on Amazon S3")
85
87
  when :local then line.gsub!(':remote', "on the local server")
86
88
  when :scp, :sftp, :ftp then line.gsub!(':remote', "on the remote server (#{ip})")
@@ -0,0 +1,10 @@
1
+ module Backup
2
+ module Storage
3
+ class Base
4
+ include Backup::CommandHelper
5
+
6
+ end
7
+ end
8
+ end
9
+
10
+
@@ -2,7 +2,7 @@ require 'backup/connection/cloudfiles'
2
2
 
3
3
  module Backup
4
4
  module Storage
5
- class CloudFiles
5
+ class CloudFiles < Base
6
6
 
7
7
  # Stores the backup file on the remote server using Rackspace Cloud Files
8
8
  def initialize(adapter)
@@ -2,7 +2,7 @@ require 'net/ftp'
2
2
 
3
3
  module Backup
4
4
  module Storage
5
- class FTP
5
+ class FTP < Backup::Storage::Base
6
6
 
7
7
  attr_accessor :user, :password, :ip, :path, :tmp_path, :final_file
8
8
 
@@ -1,8 +1,6 @@
1
1
  module Backup
2
2
  module Storage
3
- class Local
4
-
5
- include Backup::CommandHelper
3
+ class Local < Base
6
4
 
7
5
  # Store on same machine, preferentially in a different hard drive or in
8
6
  # a mounted network path (NFS, Samba, etc)
@@ -2,12 +2,13 @@ require 'backup/connection/s3'
2
2
 
3
3
  module Backup
4
4
  module Storage
5
- class S3
5
+ class S3 < Base
6
6
 
7
7
  # Stores the backup file on the remote server using S3
8
8
  def initialize(adapter)
9
9
  s3 = Backup::Connection::S3.new(adapter)
10
10
  s3.connect
11
+ log("Saving '#{s3.final_file}' to s3 bucket '#{s3.s3_bucket}'")
11
12
  s3.store
12
13
  end
13
14
 
@@ -2,7 +2,7 @@ require 'net/scp'
2
2
 
3
3
  module Backup
4
4
  module Storage
5
- class SCP
5
+ class SCP < Base
6
6
 
7
7
  attr_accessor :user, :password, :ip, :path, :tmp_path, :final_file
8
8
 
@@ -2,7 +2,7 @@ require 'net/sftp'
2
2
 
3
3
  module Backup
4
4
  module Storage
5
- class SFTP
5
+ class SFTP < Base
6
6
 
7
7
  attr_accessor :user, :password, :ip, :path, :tmp_path, :final_file
8
8
 
data/setup/backup.rb CHANGED
@@ -22,6 +22,7 @@
22
22
  #
23
23
  # STORAGE METHODS
24
24
  # - S3 (Amazon)
25
+ # - CF (Rackspace Cloud Files)
25
26
  # - SCP (Remote Server)
26
27
  # - FTP (Remote Server)
27
28
  # - SFTP (Remote Server)
@@ -104,6 +105,33 @@ backup 'mysql-backup-s3' do
104
105
  end
105
106
 
106
107
 
108
+ # Initialize with:
109
+ # sudo backup --run mysql-backup-cloudfiles
110
+ backup 'mysql-backup-cloudfiles' do
111
+
112
+ adapter :mysql do
113
+ user 'user'
114
+ password 'password'
115
+ database 'database'
116
+ end
117
+
118
+ storage :cloudfiles do
119
+ username 'username'
120
+ api_key 'api_key'
121
+ container 'mysql_backup'
122
+ end
123
+
124
+ encrypt_with_gpg_public_key <<-KEY
125
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
126
+ Version: GnuPG v1.4.7 (Darwin)
127
+
128
+ Your very long public key goes here
129
+ -----END PGP PUBLIC KEY BLOCK-----
130
+ KEY
131
+
132
+ end
133
+
134
+
107
135
  # Initialize with:
108
136
  # sudo backup --run postgresql-backup-s3
109
137
  backup 'postgresql-backup-scp' do
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1876988210
5
- prerelease: true
4
+ hash: 7
5
+ prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
9
  - 2
10
- - pre3
11
- version: 2.3.2.pre3
10
+ version: 2.3.2
12
11
  platform: ruby
13
12
  authors:
14
13
  - Michael van Rooijen
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-07-14 00:00:00 +02:00
18
+ date: 2010-09-19 00:00:00 +02:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
@@ -105,7 +104,7 @@ dependencies:
105
104
  requirement: &id006 !ruby/object:Gem::Requirement
106
105
  none: false
107
106
  requirements:
108
- - - "="
107
+ - - ">="
109
108
  - !ruby/object:Gem::Version
110
109
  hash: 21
111
110
  segments:
@@ -163,11 +162,11 @@ dependencies:
163
162
  type: :runtime
164
163
  version_requirements: *id009
165
164
  description: |-
166
- Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the
167
- Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as
168
- MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you
169
- have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption
170
- and Backup Cleaning (Cycling).
165
+ Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with
166
+ and without the Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases
167
+ such as MySQL/PostgreSQL/SQLite and Files/Folders. All backups can be transferred to Amazon S3, Rackspace Cloud Files,
168
+ any remote server you have access to (using either SCP, SFTP or regular FTP), or a Local server. Backup handles
169
+ Compression, Archiving, Encryption (OpenSSL or GPG), Backup Cleaning (Cycling) and supports Email Notifications.
171
170
  email: meskyanichi@gmail.com
172
171
  executables:
173
172
  - backup
@@ -176,7 +175,7 @@ extensions: []
176
175
  extra_rdoc_files: []
177
176
 
178
177
  files:
179
- - README.textile
178
+ - README.md
180
179
  - CHANGELOG
181
180
  - LICENSE
182
181
  - VERSION
@@ -209,6 +208,7 @@ files:
209
208
  - lib/backup/record/s3.rb
210
209
  - lib/backup/record/scp.rb
211
210
  - lib/backup/record/sftp.rb
211
+ - lib/backup/storage/base.rb
212
212
  - lib/backup/storage/cloudfiles.rb
213
213
  - lib/backup/storage/ftp.rb
214
214
  - lib/backup/storage/local.rb
@@ -246,14 +246,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
246
246
  required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  none: false
248
248
  requirements:
249
- - - ">"
249
+ - - ">="
250
250
  - !ruby/object:Gem::Version
251
- hash: 25
251
+ hash: 3
252
252
  segments:
253
- - 1
254
- - 3
255
- - 1
256
- version: 1.3.1
253
+ - 0
254
+ version: "0"
257
255
  requirements: []
258
256
 
259
257
  rubyforge_project:
data/README.textile DELETED
@@ -1,175 +0,0 @@
1
- h1. Backup
2
-
3
- h2. A Backup Ruby Gem
4
-
5
- Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption, Backup Cleaning (Cycling) and supports Email Notifications.
6
-
7
- h2. Authors/Maintainers
8
-
9
- * "Meskyanichi - Michael van Rooijen":http://github.com/meskyanichi
10
- * "Fernandoluizao - Fernando Migliorini Luizão":http://github.com/fernandoluizao
11
-
12
-
13
- h2. Backup's Current Capabilities
14
-
15
- h3. Storage Methods
16
-
17
- * Amazon S3
18
- * Remote Server (Available Protocols: SCP, SFTP, FTP)
19
- * Local server (Example Locations: Another Hard Drive, Network path) *(coming in the next gem release)*
20
-
21
- h3. Adapters
22
-
23
- * MySQL
24
- * SQLite *(in the next gem release)*
25
- * PostgreSQL
26
- * Archive (Any files and/or folders)
27
- * Custom (Anything you can produce using the command line)
28
-
29
- h3. Archiving
30
-
31
- Handles archiving for the *Archive* and *Custom* adapters.
32
-
33
- h3. Encryption
34
-
35
- Handles encryption of *all* backups for *any* adapter.
36
- To decrypt a "Backup encrypted file" you can use Backup's built-in utility command:
37
-
38
- bc. sudo backup --decrypt /path/to/encrypted/file.enc
39
-
40
- h3. Backup Cleaning
41
-
42
- With Backup you can very easily specify how many backups you would like to have stored (per backup procedure!) on your Amazon S3, Remote or Local server. When the limit you specify gets exceeded, the oldest backup will automatically be cleaned up.
43
-
44
- h3. Email Notifications
45
-
46
- You will be able to specify whether you would like to be notified by email when a backup successfully been stored.
47
- Simply fill in the email configuration block and set "notify" to true inside the backup procedure you would like to be notified of.
48
-
49
- h3. Quick Example of a Single Backup Setting/Procedure inside the Backup Configuration File
50
-
51
- bc. backup 'mysql-backup-s3' do
52
- adapter :mysql do
53
- user 'user'
54
- password 'password'
55
- database 'database'
56
- end
57
- storage :s3 do
58
- access_key_id 'access_key_id'
59
- secret_access_key 'secret_access_key'
60
- bucket '/bucket/backups/mysql/'
61
- use_ssl true
62
- end
63
- keep_backups 25
64
- encrypt_with_password 'my_password'
65
- notify true
66
- end
67
-
68
- Everything above should be pretty straightforward, so now, using the "trigger" we specified between
69
- the *backup* and *do* you can execute this backup procedure like so:
70
-
71
- *Rails Environment*
72
-
73
- bc. rake backup:run trigger=mysql-backup-s3
74
-
75
- *Unix Environment*
76
-
77
- bc. sudo backup --run mysql-backup-s3
78
-
79
- That's it. This was a simple example of how it works.
80
-
81
-
82
- h2. Interested in trying out Backup?
83
-
84
-
85
- h3. Getting started with Backup for the *Unix Environment*
86
-
87
- "http://wiki.github.com/meskyanichi/backup/getting-started-unix":http://wiki.github.com/meskyanichi/backup/getting-started-unix
88
-
89
-
90
- h3. Getting started with Backup for the *Rails Environment*
91
-
92
- "http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails":http://wiki.github.com/meskyanichi/backup/getting-started-ruby-on-rails
93
-
94
-
95
- h3. Production Mode *RAILS_ENV*
96
-
97
- "http://wiki.github.com/meskyanichi/backup/production-mode":http://wiki.github.com/meskyanichi/backup/production-mode
98
-
99
-
100
- h3. Encrypting and Decrypting
101
-
102
- "http://wiki.github.com/meskyanichi/backup/encrypting-and-decrypting":http://wiki.github.com/meskyanichi/backup/encrypting-and-decrypting
103
-
104
-
105
- h3. Backup Configuration File (All Adapters, Storage Methods, Mail Settings and Options)
106
-
107
- "http://wiki.github.com/meskyanichi/backup/configuration-file":http://wiki.github.com/meskyanichi/backup/configuration-file
108
-
109
-
110
- h3. Unix Utility Commands and Rails Rake Tasks
111
-
112
- "http://wiki.github.com/meskyanichi/backup/utility-commands":http://wiki.github.com/meskyanichi/backup/utility-commands
113
-
114
- "http://wiki.github.com/meskyanichi/backup/rake-tasks":http://wiki.github.com/meskyanichi/backup/rake-tasks
115
-
116
-
117
- h3. Automatic Backups
118
-
119
- "http://wiki.github.com/meskyanichi/backup/automatic-backups":http://wiki.github.com/meskyanichi/backup/automatic-backups
120
-
121
-
122
- h3. Capistrano Recipes
123
-
124
- "http://wiki.github.com/meskyanichi/backup/capistrano-recipes":http://wiki.github.com/meskyanichi/backup/capistrano-recipes
125
-
126
-
127
- h3. Capistrano, Whenever!
128
-
129
- "http://wiki.github.com/meskyanichi/backup/capistrano-whenever":http://wiki.github.com/meskyanichi/backup/capistrano-whenever
130
-
131
-
132
- h3. Understanding "The Backup Database"
133
-
134
- "http://wiki.github.com/meskyanichi/backup/the-backup-database":http://wiki.github.com/meskyanichi/backup/the-backup-database
135
-
136
-
137
- h3. Trouble Shooting
138
-
139
- "http://wiki.github.com/meskyanichi/backup/troubleshooting":http://wiki.github.com/meskyanichi/backup/troubleshooting
140
-
141
-
142
- h3. Requirements
143
-
144
- "http://wiki.github.com/meskyanichi/backup/requirements":http://wiki.github.com/meskyanichi/backup/requirements
145
-
146
-
147
- h3. Resources
148
-
149
- "http://wiki.github.com/meskyanichi/backup/resources":http://wiki.github.com/meskyanichi/backup/resources
150
-
151
-
152
- h3. Requests
153
-
154
- If anyone has any requests, please send us a message or post it on the issues page!
155
-
156
-
157
- h3. Suggestions?
158
-
159
- Send us a message! Fork the project!
160
-
161
-
162
- h3. Found a Bug?
163
-
164
- "http://github.com/meskyanichi/backup/issues":http://github.com/meskyanichi/backup/issues
165
-
166
-
167
- h3. Contributors
168
-
169
- List of people that forked and added stuff!
170
-
171
- * "dtrueman":http://github.com/dtrueman
172
-
173
-
174
-
175
- _Michael van Rooijen | Final Creation. ("http://final-creation.com":http://final-creation.com)_