Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael van Rooijen committed Mar 11, 2011
2 parents f08c3eb + 63adb85 commit a11c7f4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
backup (3.0.0)
backup (3.0.2)
dropbox (~> 1.2.3)
fog (~> 0.5.3)
mail (~> 2.2.15)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Below you see a sample configuration file you could create for Backup 3. Just re

### Explanation for the above example

First it dumps all the tables inside the MySQL database "my_sample_mysql_db", except for the "logs" table. It also dumps the MongoDB database "my_sample_mongo_db", but only the collections "users", "events" and "posts". After that it'll create a "user_avatars.tar" archive with all the uploaded avatars of the users. After that it'll create a "logs.tar" archive with the "production.log", "newrelic_agent.log" and "other.log" logs. After that it'll encrypt the whole backup file (everything included: databases, archives) using "OpenSSL". Now the Backup can only be extracted when you know the password to decrypt it ("my_secret_password" in this case). After that it'll compress the backup file using Gzip (with the mode set to "best", rather than "fast" for best compression). Then it'll store the backup file to Amazon S3 in to 'my_bucket/backups'. Next it'll also transfer a copy of the backup file to a remote server using the RSync protocol, and it'll be stored in to the "$HOME/backups/" path on this server. Finally, it'll notify me by email if the backup raises an error/exception during the process indicating that something went wrong. (When setting `mail.on_success = true` it'll also notify you of every successful backup)
First it dumps all the tables inside the MySQL database "my_sample_mysql_db", except for the "logs" table. It also dumps the MongoDB database "my_sample_mongo_db", but only the collections "users", "events" and "posts". After that it'll create a "user_avatars.tar" archive with all the uploaded avatars of the users. After that it'll create a "logs.tar" archive with the "production.log", "newrelic_agent.log" and "other.log" logs. After that it'll compress the backup file using Gzip (with the mode set to "best", rather than "fast" for best compression). After that it'll encrypt the whole backup file (everything included: databases, archives) using "OpenSSL". Now the Backup can only be extracted when you know the password to decrypt it ("my_secret_password" in this case). Then it'll store the backup file to Amazon S3 in to 'my_bucket/backups'. Next it'll also transfer a copy of the backup file to a remote server using the RSync protocol, and it'll be stored in to the "$HOME/backups/" path on this server. Finally, it'll notify me by email if the backup raises an error/exception during the process indicating that something went wrong. (When setting `mail.on_success = true` it'll also notify you of every successful backup)

### Things to note

Expand Down
13 changes: 13 additions & 0 deletions bin/backup
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require File.expand_path("../../lib/backup", __FILE__)
##
# Build the Backup Command Line Interface using Thor
class BackupCLI < Thor
include Thor::Actions

TEMPLATE_DIR = File.expand_path("../../lib/templates", __FILE__)

Expand Down Expand Up @@ -128,12 +129,14 @@ class BackupCLI < Thor
temp_file.close
if options[:path]
FileUtils.mkdir_p(options[:path])
overwrite?(File.join(Backup::PATH, 'config.rb'))
File.open(File.join(options[:path], 'config.rb'), 'w') do |file|
file.write( File.read(temp_file.path) )
puts "Generated configuration file in '#{File.join(options[:path], 'config.rb')}'"
end
else
FileUtils.mkdir_p(Backup::PATH)
overwrite?(File.join(Backup::PATH, 'config.rb'))
File.open(File.join(Backup::PATH, 'config.rb'), 'w') do |file|
file.write( File.read(temp_file.path) )
puts "Generated configuration file in '#{File.join(Backup::PATH, 'config.rb')}'"
Expand Down Expand Up @@ -172,6 +175,16 @@ class BackupCLI < Thor
puts "Backup #{Backup::Version.current}"
end

private

##
# Helper method for asking the user if he/she wants to overwrite the file
def overwrite?(path)
if File.exist?(path)
exit if no? "A configuration file already exists in #{ path }. Do you want to overwrite? [y/n]"
end
end

end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/backup/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def perform!
databases.each { |d| d.perform! }
archives.each { |a| a.perform! }
package!
encryptors.each { |e| e.perform! }
compressors.each { |c| c.perform! }
encryptors.each { |e| e.perform! }
storages.each { |s| s.perform! }
notifiers.each { |n| n.perform!(self) }
clean!
Expand Down
2 changes: 1 addition & 1 deletion lib/backup/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Version
# Defines the patch version
# BUILD:
# Defines the build version ( use 'false' if no build )
MAJOR, MINOR, PATCH, BUILD = 3, 0, 1, false
MAJOR, MINOR, PATCH, BUILD = 3, 0, 2, false

# ========================================================= #
# ADJUST THE CONSTANTS ABOVE TO CHANGE THE BACKUP VERSION #
Expand Down
2 changes: 1 addition & 1 deletion spec/storage/cloudfiles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
it 'should transfer the provided file to the container' do
Backup::Model.new('blah', 'blah') {}
file = mock("Backup::Storage::CloudFiles::File")
File.expects(:read).with("#{File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER}")}.tar").returns(file)
File.expects(:open).with("#{File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER}")}.tar").returns(file)
cf.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar").twice
connection.expects(:put_object).with('my_container', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar", file)
cf.send(:transfer!)
Expand Down
2 changes: 1 addition & 1 deletion spec/storage/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
it 'should transfer the provided file to the bucket' do
Backup::Model.new('blah', 'blah') {}
file = mock("Backup::Storage::S3::File")
File.expects(:read).with("#{File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER}")}.tar").returns(file)
File.expects(:open).with("#{File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER}")}.tar").returns(file)
s3.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar").twice
connection.expects(:sync_clock)
connection.expects(:put_object).with('my-bucket', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar", file)
Expand Down

0 comments on commit a11c7f4

Please sign in to comment.