backup2s3 0.2.0 → 0.2.1
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/Rakefile +4 -3
- data/backup2s3.gemspec +6 -3
- data/lib/adapters/s3_adapter.rb +7 -11
- data/lib/backup2s3.rb +28 -12
- data/lib/backup_management/backup_manager.rb +1 -1
- data/lib/system.rb +17 -1
- metadata +19 -6
data/Rakefile
CHANGED
@@ -2,11 +2,12 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('backup2s3', '0.2.
|
6
|
-
p.description = "
|
5
|
+
Echoe.new('backup2s3', '0.2.1') do |p|
|
6
|
+
p.description = "Backup2s3 is a gem that performs database and application backups and stores this data on Amazon S3."
|
7
|
+
p.summary = "Backup2s3 is a gem that creates, deletes and restores db and application backups."
|
7
8
|
p.url = "http://github.com/aricwalker/backup2s3"
|
8
9
|
p.author = "Aric Walker"
|
9
10
|
p.email = "aric@truespire.com"
|
10
11
|
p.ignore_pattern = ["nbproject/*/*", "nbproject/*"]
|
11
|
-
p.development_dependencies = []
|
12
|
+
p.development_dependencies = ["aws-s3 >=0.6.2"]
|
12
13
|
end
|
data/backup2s3.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{backup2s3}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.1"
|
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
9
|
s.date = %q{2010-04-18}
|
10
|
-
s.description = %q{
|
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/backup2s3.rb", "lib/backup_management/backup.rb", "lib/backup_management/backup_manager.rb", "lib/system.rb"]
|
13
13
|
s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "generators/backup2s3/USAGE", "generators/backup2s3/backup2s3_generator.rb", "generators/backup2s3/templates/backup2s3.rake", "generators/backup2s3/templates/backup2s3.yml", "init.rb", "lib/adapters/s3_adapter.rb", "lib/backup2s3.rb", "lib/backup_management/backup.rb", "lib/backup_management/backup_manager.rb", "lib/system.rb", "backup2s3.gemspec"]
|
@@ -16,15 +16,18 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{backup2s3}
|
18
18
|
s.rubygems_version = %q{1.3.6}
|
19
|
-
s.summary = %q{
|
19
|
+
s.summary = %q{Backup2s3 is a gem that creates, deletes and restores db and application backups.}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_development_dependency(%q<aws-s3>, [">= 0.6.2"])
|
26
27
|
else
|
28
|
+
s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
|
27
29
|
end
|
28
30
|
else
|
31
|
+
s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
|
29
32
|
end
|
30
33
|
end
|
data/lib/adapters/s3_adapter.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'aws/s3'
|
2
|
-
require 'tidy'
|
3
2
|
|
4
3
|
class Adapters::S3Adapter
|
4
|
+
include System
|
5
5
|
|
6
6
|
def initialize(config)
|
7
7
|
@config = config
|
@@ -33,10 +33,8 @@ class Adapters::S3Adapter
|
|
33
33
|
file
|
34
34
|
end
|
35
35
|
|
36
|
-
def read(file_name)
|
37
|
-
puts "trying..."
|
36
|
+
def read(file_name)
|
38
37
|
ensure_connected
|
39
|
-
puts "trying..."
|
40
38
|
return AWS::S3::S3Object.find(file_name, bucket)
|
41
39
|
end
|
42
40
|
|
@@ -53,17 +51,15 @@ class Adapters::S3Adapter
|
|
53
51
|
|
54
52
|
private
|
55
53
|
|
56
|
-
def access_key_id
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
54
|
def bucket
|
61
|
-
@bucket ||= clean("#{ActiveRecord::Base.connection.current_database.to_str.downcase}-ON-#{
|
55
|
+
@bucket ||= clean("#{ActiveRecord::Base.connection.current_database.to_str.downcase}-ON-#{System.hostname.downcase}")
|
62
56
|
end
|
63
57
|
|
64
58
|
def clean(str)
|
65
59
|
str.gsub!(".", "-dot-")
|
66
|
-
str.gsub!("_", "-")
|
67
|
-
|
60
|
+
str.gsub!("_", "-")
|
61
|
+
str.gsub!("\n", "")
|
62
|
+
return str
|
68
63
|
end
|
64
|
+
|
69
65
|
end
|
data/lib/backup2s3.rb
CHANGED
@@ -26,14 +26,14 @@ class Backup2s3
|
|
26
26
|
|
27
27
|
#DELETE deletes a backup
|
28
28
|
def delete(backup_id = ENV['id'])
|
29
|
-
raise "
|
29
|
+
raise "id is blank! There was no backup specified for deletion." and return if backup_id == nil
|
30
30
|
delete_backup(backup_id)
|
31
31
|
save_backup_manager
|
32
32
|
end
|
33
33
|
|
34
34
|
#RESTORE restores a backup
|
35
35
|
def restore(backup_id = ENV['id'])
|
36
|
-
raise "
|
36
|
+
raise "id is blank! There was no backup specified for restoration." and return if backup_id == nil
|
37
37
|
restore_backup(backup_id)
|
38
38
|
save_backup_manager
|
39
39
|
end
|
@@ -52,16 +52,18 @@ class Backup2s3
|
|
52
52
|
def create_backup(comment)
|
53
53
|
if @conf[:backups][:backup_database]
|
54
54
|
@database_file = "#{@time}-#{System.db_credentials['database']}-database.sql"
|
55
|
+
print "\nDumping database..."
|
55
56
|
database_temp = System.db_dump
|
56
|
-
puts "\n-
|
57
|
+
puts "done\n- Database dump file size: " << database_temp.size.to_s << " B"; print "Backing up database dump file..."
|
57
58
|
@adapter.store(@database_file, open(database_temp.path))
|
58
59
|
puts "done"
|
59
60
|
end
|
60
61
|
|
61
62
|
if @conf[:backups][:backup_application_folders].is_a?(Array)
|
62
63
|
@application_file = "#{@time}-#{System.db_credentials['database']}-application.tar.gz"
|
64
|
+
print "\nZipping application folders..."
|
63
65
|
application_temp = System.tarzip_folders(@conf[:backups][:backup_application_folders])
|
64
|
-
puts "\n- Application tarball size: " << application_temp.size.to_s << " B"; print "
|
66
|
+
puts "done\n- Application tarball size: " << application_temp.size.to_s << " B"; print "Backing up application tarball..."
|
65
67
|
@adapter.store(@application_file, open(application_temp.path))
|
66
68
|
puts "done"
|
67
69
|
end
|
@@ -91,14 +93,28 @@ class Backup2s3
|
|
91
93
|
"Warning: Backup with ID #{backup.time} was not found and therefore not deleted.")
|
92
94
|
end
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
def restore_backup(backup_id)
|
97
|
+
backup = @backup_manager.get_backup(backup_id)
|
98
|
+
if backup.nil? then
|
99
|
+
puts "Backup with ID #{backup_id} does not exist."
|
100
|
+
return
|
101
|
+
end
|
102
|
+
print "\nRetrieving application tarball..."
|
103
|
+
application_file = @adapter.fetch(backup.application_file)
|
104
|
+
puts "done"
|
105
|
+
|
106
|
+
print "Restoring application from application tarball..."
|
107
|
+
System.unzip_file(application_file)
|
108
|
+
puts "done\n"
|
109
|
+
|
110
|
+
print "\nRetrieving datbase dump_file..."
|
111
|
+
dump_file = @adapter.fetch(backup.database_file)
|
112
|
+
puts "done";
|
113
|
+
|
114
|
+
print "Restoring database from database dump file..."
|
115
|
+
System.load_db_dump(dump_file)
|
116
|
+
puts "done\n\n"
|
117
|
+
end
|
102
118
|
|
103
119
|
# Loads the config/backup2s3.yml configuration file
|
104
120
|
def load_configuration
|
@@ -11,7 +11,7 @@ class BackupManagement::BackupManager
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.filename
|
14
|
-
"#{System.db_credentials['database']}_ON_#{
|
14
|
+
"#{System.db_credentials['database']}_ON_#{System.hostname}_backups.yaml"
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.local_filename
|
data/lib/system.rb
CHANGED
@@ -2,6 +2,10 @@ require 'tempfile'
|
|
2
2
|
|
3
3
|
module System
|
4
4
|
|
5
|
+
def self.hostname
|
6
|
+
`hostname`.to_str.gsub!("\n", "")
|
7
|
+
end
|
8
|
+
|
5
9
|
def self.db_credentials
|
6
10
|
ActiveRecord::Base.configurations[RAILS_ENV]
|
7
11
|
end
|
@@ -24,6 +28,11 @@ module System
|
|
24
28
|
return application_tar
|
25
29
|
end
|
26
30
|
|
31
|
+
def self.unzip_file(tarball)
|
32
|
+
cmd = "tar xpf #{tarball.path}"
|
33
|
+
run(cmd)
|
34
|
+
end
|
35
|
+
|
27
36
|
# Creates and runs mysqldump and throws into .tar.gz file.
|
28
37
|
# Returns .tar.gz file
|
29
38
|
def self.db_dump
|
@@ -34,13 +43,20 @@ module System
|
|
34
43
|
return dump_file
|
35
44
|
end
|
36
45
|
|
46
|
+
def self.load_db_dump(dump_file)
|
47
|
+
cmd = "mysql #{mysql_options}"
|
48
|
+
cmd += " < #{dump_file.path}"
|
49
|
+
run(cmd)
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
37
53
|
def self.mysql_options
|
38
54
|
cmd = ''
|
39
55
|
cmd += " -u #{db_credentials['username']} " unless db_credentials['username'].nil?
|
40
56
|
cmd += " -p'#{db_credentials['password']}'" unless db_credentials['password'].nil?
|
41
57
|
cmd += " -h '#{db_credentials['host']}'" unless db_credentials['host'].nil?
|
42
58
|
cmd += " #{db_credentials['database']}"
|
43
|
-
end
|
59
|
+
end
|
44
60
|
|
45
61
|
end
|
46
62
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aric Walker
|
@@ -16,9 +16,22 @@ cert_chain: []
|
|
16
16
|
|
17
17
|
date: 2010-04-18 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: aws-s3
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 6
|
30
|
+
- 2
|
31
|
+
version: 0.6.2
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Backup2s3 is a gem that performs database and application backups and stores this data on Amazon S3.
|
22
35
|
email: aric@truespire.com
|
23
36
|
executables: []
|
24
37
|
|
@@ -83,6 +96,6 @@ rubyforge_project: backup2s3
|
|
83
96
|
rubygems_version: 1.3.6
|
84
97
|
signing_key:
|
85
98
|
specification_version: 3
|
86
|
-
summary:
|
99
|
+
summary: Backup2s3 is a gem that creates, deletes and restores db and application backups.
|
87
100
|
test_files: []
|
88
101
|
|