backup2s3 0.2.2 → 0.2.4

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/README CHANGED
@@ -5,7 +5,7 @@ SETUP:
5
5
 
6
6
 
7
7
  2. Add the below code to config/environment.rb
8
- config.gem "backup2s3", :version => ">= 0.2.1"
8
+ config.gem "backup2s3", :version => ">= 0.2.3"
9
9
 
10
10
 
11
11
  3. Run the generator in your application root directory
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('backup2s3', '0.2.2') do |p|
5
+ Echoe.new('backup2s3', '0.2.4') do |p|
6
6
  p.description = "Backup2s3 is a gem that performs database and application backups and stores this data on Amazon S3."
7
7
  p.summary = "Backup2s3 is a gem that creates, deletes and restores db and application backups."
8
8
  p.url = "http://github.com/aricwalker/backup2s3"
data/backup2s3.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{backup2s3}
5
- s.version = "0.2.2"
5
+ s.version = "0.2.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aric Walker"]
9
- s.date = %q{2010-09-13}
9
+ s.date = %q{2011-03-18}
10
10
  s.description = %q{Backup2s3 is a gem that performs database and application backups and stores this data on Amazon S3.}
11
11
  s.email = %q{aric@truespire.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "README", "lib/adapters/s3_adapter.rb", "lib/adapters/s3cmd_adapter.rb", "lib/backup2s3.rb", "lib/backup_management/backup.rb", "lib/backup_management/backup_manager.rb", "lib/system.rb"]
@@ -1,29 +1,26 @@
1
+ require 'backup2s3'
2
+
1
3
  namespace :backup2s3 do
2
4
  namespace :backup do
3
- desc "Save a full back to S3"
4
- task :create => :environment do
5
+ desc "Save a full backup to S3"
6
+ task :create do
5
7
  Backup2s3.new.create
6
8
  end
7
9
 
8
- desc "Save a full back to S3"
9
- task :delete => :environment do
10
+ desc "Delete a backup from S3"
11
+ task :delete do
10
12
  Backup2s3.new.delete
11
13
  end
12
14
 
13
- desc "Save a full back to S3"
14
- task :list => :environment do
15
+ desc "List all the backups saved on S3"
16
+ task :list do
15
17
  Backup2s3.new.list
16
18
  end
17
19
 
18
20
  desc "Restore your DB from S3"
19
- task :restore => :environment do
21
+ task :restore do
20
22
  Backup2s3.new.restore
21
23
  end
22
-
23
- # desc "Keep all backups for the last day, one per day for the last week, and one per week before that. Delete the rest."
24
- # task :clean => :environment do
25
- # Backup2s3.new.clean
26
- # end
27
24
  end
28
25
 
29
26
  desc "Show table sizes for your database"
@@ -1,7 +1,7 @@
1
1
  require 'aws/s3'
2
2
 
3
3
 
4
- class Adapters::S3Adapter
4
+ class S3Adapter
5
5
  include System
6
6
 
7
7
  def initialize(config)
@@ -57,7 +57,7 @@ class Adapters::S3Adapter
57
57
  private
58
58
 
59
59
  def bucket
60
- @bucket ||= clean("#{ActiveRecord::Base.connection.current_database.to_str.downcase}-ON-#{System.hostname.downcase}")
60
+ @bucket ||= clean("#{System.db_credentials['database'].downcase}-ON-#{System.hostname.downcase}")
61
61
  end
62
62
 
63
63
  def clean(str)
@@ -1,5 +1,5 @@
1
1
 
2
- class Adapters::S3cmdAdapter
2
+ class S3cmdAdapter
3
3
  include System
4
4
 
5
5
  def initialize(config)
@@ -47,7 +47,7 @@ class Adapters::S3cmdAdapter
47
47
  private
48
48
 
49
49
  def bucket
50
- @bucket ||= clean("#{ActiveRecord::Base.connection.current_database.to_str.downcase}-ON-#{System.hostname.downcase}")
50
+ @bucket ||= clean("#{System.db_credentials['database'].downcase}-ON-#{System.hostname.downcase}")
51
51
  end
52
52
 
53
53
  def clean(str)
data/lib/backup2s3.rb CHANGED
@@ -3,6 +3,12 @@ require 'active_support'
3
3
  require 'tempfile'
4
4
  require 'yaml'
5
5
 
6
+ require 'system.rb'
7
+ require 'adapters/s3_adapter.rb'
8
+ require 'adapters/s3cmd_adapter.rb'
9
+ require 'backup_management/backup.rb'
10
+ require 'backup_management/backup_manager.rb'
11
+
6
12
  class Backup2s3
7
13
  include System
8
14
 
@@ -73,7 +79,7 @@ class Backup2s3
73
79
  backup_to_delete = @backup_manager.get_oldest_backup
74
80
  delete_backup(backup_to_delete.time)
75
81
  end
76
- backup = BackupManagement::Backup.new(@time, @application_file, @database_file, comment)
82
+ backup = Backup.new(@time, @application_file, @database_file, comment)
77
83
  @backup_manager.add_backup(backup)
78
84
  puts ""
79
85
  end
@@ -128,32 +134,32 @@ class Backup2s3
128
134
  # Creates instance of class used to interface with S3
129
135
  def load_adapter
130
136
  begin
131
- adapter = "Adapters::#{@conf[:adapter][:type]}".constantize
137
+ adapter = "#{@conf[:adapter][:type]}".constantize
132
138
  rescue
133
- adapter = Adapters::S3Adapter
139
+ adapter = S3Adapter
134
140
  end
135
141
  @adapter = adapter.new(@conf[:adapter])
136
142
  end
137
143
 
138
144
  def load_backup_manager
139
- BackupManagement::BackupManager.new()
140
- BackupManagement::Backup.new(nil, nil, nil)
141
- begin
142
- @backup_manager = YAML.load_file(@adapter.fetch(BackupManagement::BackupManager.filename).path)
143
- @backup_manager ||= YAML.load_file(BackupManagement::BackupManager.local_filename)
145
+ BackupManager.new()
146
+ Backup.new(nil, nil, nil)
147
+ begin
148
+ @backup_manager = YAML.load_file(@adapter.fetch(BackupManager.filename).path)
149
+ @backup_manager ||= YAML.load_file(BackupManager.local_filename)
144
150
  rescue
145
- @backup_manager ||= BackupManagement::BackupManager.new
151
+ @backup_manager ||= BackupManager.new
146
152
  end
147
153
  end
148
154
 
149
155
  def save_backup_manager
150
156
  begin
151
- File.open(BackupManagement::BackupManager.local_filename, "w") { |f| YAML.dump(@backup_manager, f) }
157
+ File.open(BackupManager.local_filename, "w") { |f| YAML.dump(@backup_manager, f) }
152
158
  rescue
153
- puts "Unable to save local file: " << BackupManagement::BackupManager.local_filename
159
+ puts "Unable to save local file: " << BackupManager.local_filename
154
160
  end
155
161
  begin
156
- @adapter.store(BackupManagement::BackupManager.filename, open(BackupManagement::BackupManager.local_filename))
162
+ @adapter.store(BackupManager.filename, open(BackupManager.local_filename))
157
163
  rescue
158
164
  puts "Unable to save BackupManager to S3"
159
165
  end
@@ -2,7 +2,7 @@
2
2
  # and open the template in the editor.
3
3
  require 'yaml'
4
4
 
5
- class BackupManagement::Backup
5
+ class Backup
6
6
 
7
7
  attr_accessor :time, :application_file, :database_file, :comment
8
8
 
@@ -1,6 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
- class BackupManagement::BackupManager
3
+ class BackupManager
4
4
  include System
5
5
 
6
6
  attr_accessor :backup_list_filename, :backups
data/lib/system.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tempfile'
2
+ require 'yaml'
2
3
 
3
4
  module System
4
5
 
@@ -6,8 +7,9 @@ module System
6
7
  `hostname`.to_str.gsub!("\n", "")
7
8
  end
8
9
 
9
- def self.db_credentials
10
- ActiveRecord::Base.configurations[RAILS_ENV]
10
+ def self.db_credentials
11
+ db_config = YAML.load_file("#{RAILS_ROOT}/config/database.yml")
12
+ db_config[RAILS_ENV]
11
13
  end
12
14
 
13
15
  # Run system commands
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup2s3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aric Walker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-13 00:00:00 -06:00
18
+ date: 2011-03-18 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency