backup2s3 0.2.1 → 0.2.2
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/Manifest +1 -0
- data/README +31 -8
- data/Rakefile +1 -1
- data/backup2s3.gemspec +6 -6
- data/generators/backup2s3/backup2s3_generator.rb +26 -5
- data/generators/backup2s3/templates/backup2s3.yml +7 -0
- data/lib/adapters/s3_adapter.rb +9 -2
- data/lib/adapters/s3cmd_adapter.rb +62 -0
- data/lib/backup2s3.rb +15 -6
- data/lib/system.rb +2 -2
- metadata +13 -4
data/Manifest
CHANGED
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.1
|
8
|
+
config.gem "backup2s3", :version => ">= 0.2.1"
|
9
9
|
|
10
10
|
|
11
11
|
3. Run the generator in your application root directory
|
@@ -17,13 +17,36 @@ SETUP:
|
|
17
17
|
|
18
18
|
USAGE:
|
19
19
|
|
20
|
-
|
20
|
+
2. Get started.
|
21
21
|
|
22
|
-
|
23
|
-
rake backup2s3:backup:delete - Deletes the specific backup
|
24
|
-
rake backup2s3:backup:list - Lists all backups that are currently on S3
|
25
|
-
rake backup2s3:backup:restore - Restores a specific backup
|
22
|
+
Backup tasks
|
26
23
|
|
27
|
-
|
24
|
+
Create -- Creates a backup and moves it to S3
|
25
|
+
-- comment - Add notes here to mark specific backups (optional)
|
28
26
|
|
29
|
-
|
27
|
+
rake backup2s3:backup:create
|
28
|
+
rake backup2s3:backup:create comment='put notes about backup here if needed'
|
29
|
+
|
30
|
+
|
31
|
+
Delete -- Deletes the specific backup
|
32
|
+
-- id - Backup to delete, backup ids will be found using List
|
33
|
+
|
34
|
+
rake backup2s3:backup:delete id='20100913180541'
|
35
|
+
|
36
|
+
|
37
|
+
List -- Lists all backups that are currently on S3
|
38
|
+
-- details - Setting details to true will display backup file names
|
39
|
+
and backup comments (optional)
|
40
|
+
|
41
|
+
rake backup2s3:backup:list
|
42
|
+
rake backup2s3:backup:list details=true
|
43
|
+
|
44
|
+
|
45
|
+
Restore -- Restores a specific backup
|
46
|
+
-- id - Backup to restore, backup ids will be found using List
|
47
|
+
|
48
|
+
rake backup2s3:backup:restore id='20100913180541'
|
49
|
+
|
50
|
+
Some handy tasks
|
51
|
+
|
52
|
+
rake backup2s3:statistics - Shows you the size of your DB
|
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.
|
5
|
+
Echoe.new('backup2s3', '0.2.2') 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,27 +2,27 @@
|
|
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.2"
|
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-
|
9
|
+
s.date = %q{2010-09-13}
|
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
|
-
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
|
-
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"]
|
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"]
|
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/adapters/s3cmd_adapter.rb", "lib/backup2s3.rb", "lib/backup_management/backup.rb", "lib/backup_management/backup_manager.rb", "lib/system.rb", "backup2s3.gemspec"]
|
14
14
|
s.homepage = %q{http://github.com/aricwalker/backup2s3}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Backup2s3", "--main", "README"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{backup2s3}
|
18
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
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
|
-
if Gem::Version.new(Gem::
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
26
|
s.add_development_dependency(%q<aws-s3>, [">= 0.6.2"])
|
27
27
|
else
|
28
28
|
s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
|
@@ -27,11 +27,32 @@ class Backup2s3Generator < Rails::Generator::Base
|
|
27
27
|
2. Get started.
|
28
28
|
|
29
29
|
Backup tasks
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
|
31
|
+
Create -- Creates a backup and moves it to S3
|
32
|
+
-- comment - Add notes here to mark specific backups (optional)
|
33
|
+
|
34
|
+
rake backup2s3:backup:create
|
35
|
+
rake backup2s3:backup:create comment='put notes about backup here if needed'
|
36
|
+
|
37
|
+
|
38
|
+
Delete -- Deletes the specific backup
|
39
|
+
-- id - Backup to delete, backup ids will be found using List
|
40
|
+
|
41
|
+
rake backup2s3:backup:delete id='20100913180541'
|
42
|
+
|
43
|
+
|
44
|
+
List -- Lists all backups that are currently on S3
|
45
|
+
-- details - Setting details to true will display backup file names
|
46
|
+
and backup comments (optional)
|
47
|
+
|
48
|
+
rake backup2s3:backup:list
|
49
|
+
rake backup2s3:backup:list details=true
|
50
|
+
|
51
|
+
|
52
|
+
Restore -- Restores a specific backup
|
53
|
+
-- id - Backup to restore, backup ids will be found using List
|
54
|
+
|
55
|
+
rake backup2s3:backup:restore id='20100913180541'
|
35
56
|
|
36
57
|
Some handy tasks
|
37
58
|
|
@@ -1,4 +1,10 @@
|
|
1
1
|
#Sample backup2s3 configuration file
|
2
|
+
#
|
3
|
+
# Available adapter types:
|
4
|
+
# S3Adapter - Uses aws-s3 gem.
|
5
|
+
# S3cmdAdapter - Uses s3cmd 0.9.9.91 Python library found here: http://s3tools.org/s3cmd
|
6
|
+
#
|
7
|
+
#
|
2
8
|
:backups:
|
3
9
|
:max_number_of_backups: 5
|
4
10
|
:backup_database: true
|
@@ -7,6 +13,7 @@
|
|
7
13
|
- lib
|
8
14
|
|
9
15
|
:adapter:
|
16
|
+
:type: S3Adapter
|
10
17
|
:access_key_id: XXXXXXXXXXXXXXXXXXXX
|
11
18
|
:secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
12
19
|
:use_ssl: true
|
data/lib/adapters/s3_adapter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'aws/s3'
|
2
2
|
|
3
|
+
|
3
4
|
class Adapters::S3Adapter
|
4
5
|
include System
|
5
6
|
|
@@ -10,7 +11,11 @@ class Adapters::S3Adapter
|
|
10
11
|
|
11
12
|
def ensure_connected
|
12
13
|
return if @connected
|
13
|
-
AWS::S3::Base.establish_connection!(
|
14
|
+
AWS::S3::Base.establish_connection!(
|
15
|
+
:access_key_id => @config[:access_key_id],
|
16
|
+
:secret_access_key => @config[:secret_access_key],
|
17
|
+
:use_ssl => @config[:use_ssl]
|
18
|
+
)
|
14
19
|
AWS::S3::Bucket.create(bucket)
|
15
20
|
@connected = true
|
16
21
|
end
|
@@ -62,4 +67,6 @@ class Adapters::S3Adapter
|
|
62
67
|
return str
|
63
68
|
end
|
64
69
|
|
65
|
-
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
class Adapters::S3cmdAdapter
|
3
|
+
include System
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
@connected = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def ensure_connected
|
11
|
+
return if @connected
|
12
|
+
System.run("s3cmd mb s3://#{bucket}")
|
13
|
+
@connected = true
|
14
|
+
end
|
15
|
+
|
16
|
+
def store(file_name, file)
|
17
|
+
ensure_connected
|
18
|
+
System.run("s3cmd put #{file.path} s3://#{bucket}/#{file_name}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def fetch(file_name)
|
22
|
+
ensure_connected
|
23
|
+
file = Tempfile.new("temp")
|
24
|
+
System.run("s3cmd get --force s3://#{bucket}/#{file_name} #{file.path}")
|
25
|
+
file
|
26
|
+
end
|
27
|
+
|
28
|
+
# def read(file_name)
|
29
|
+
# ensure_connected
|
30
|
+
# return AWS::S3::S3Object.find(file_name, bucket)
|
31
|
+
# end
|
32
|
+
|
33
|
+
# def list
|
34
|
+
# ensure_connected
|
35
|
+
# AWS::S3::Bucket.find(bucket).objects.collect {|x| x.path }
|
36
|
+
# end
|
37
|
+
|
38
|
+
def delete(file_name)
|
39
|
+
#TODO use s3cmd ls here to create 'find' like functionality similar to s3_adapter
|
40
|
+
begin
|
41
|
+
System.run("s3cmd del s3://#{bucket}/#{file_name}")
|
42
|
+
rescue
|
43
|
+
raise "Could not delete #{file_name}."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def bucket
|
50
|
+
@bucket ||= clean("#{ActiveRecord::Base.connection.current_database.to_str.downcase}-ON-#{System.hostname.downcase}")
|
51
|
+
end
|
52
|
+
|
53
|
+
def clean(str)
|
54
|
+
str.gsub!(".", "-dot-")
|
55
|
+
str.gsub!("_", "-")
|
56
|
+
str.gsub!("\n", "")
|
57
|
+
return str
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
data/lib/backup2s3.rb
CHANGED
@@ -85,9 +85,13 @@ class Backup2s3
|
|
85
85
|
if backup.nil? then
|
86
86
|
puts "Backup with ID #{backup_id} does not exist."
|
87
87
|
return
|
88
|
-
end
|
89
|
-
|
90
|
-
|
88
|
+
end
|
89
|
+
if !backup.application_file.empty?
|
90
|
+
begin @adapter.delete(backup.application_file) rescue puts "Could not delete #{backup.application_file}!" end
|
91
|
+
end
|
92
|
+
if !backup.database_file.empty?
|
93
|
+
begin @adapter.delete(backup.database_file) rescue puts "Could not delete #{backup.database_file}!" end
|
94
|
+
end
|
91
95
|
puts (@backup_manager.delete_backup(backup) ?
|
92
96
|
"Backup with ID #{backup.time} was successfully deleted." :
|
93
97
|
"Warning: Backup with ID #{backup.time} was not found and therefore not deleted.")
|
@@ -107,7 +111,7 @@ class Backup2s3
|
|
107
111
|
System.unzip_file(application_file)
|
108
112
|
puts "done\n"
|
109
113
|
|
110
|
-
print "\nRetrieving
|
114
|
+
print "\nRetrieving database dump_file..."
|
111
115
|
dump_file = @adapter.fetch(backup.database_file)
|
112
116
|
puts "done";
|
113
117
|
|
@@ -122,8 +126,13 @@ class Backup2s3
|
|
122
126
|
end
|
123
127
|
|
124
128
|
# Creates instance of class used to interface with S3
|
125
|
-
def load_adapter
|
126
|
-
|
129
|
+
def load_adapter
|
130
|
+
begin
|
131
|
+
adapter = "Adapters::#{@conf[:adapter][:type]}".constantize
|
132
|
+
rescue
|
133
|
+
adapter = Adapters::S3Adapter
|
134
|
+
end
|
135
|
+
@adapter = adapter.new(@conf[:adapter])
|
127
136
|
end
|
128
137
|
|
129
138
|
def load_backup_manager
|
data/lib/system.rb
CHANGED
@@ -20,9 +20,9 @@ module System
|
|
20
20
|
def self.tarzip_folders(folders)
|
21
21
|
application_tar = Tempfile.new("app")
|
22
22
|
if folders.is_a?(Array)
|
23
|
-
cmd = "tar --dereference -
|
23
|
+
cmd = "tar --dereference -czpf #{application_tar.path} #{folders.join(" ")}"
|
24
24
|
elsif folders.is_a?(String)
|
25
|
-
cmd = "tar --dereference -
|
25
|
+
cmd = "tar --dereference -czpf #{application_tar.path} #{folders}"
|
26
26
|
end
|
27
27
|
run(cmd)
|
28
28
|
return application_tar
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup2s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Aric Walker
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-09-13 00:00:00 -06:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: aws-s3
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
- 6
|
@@ -41,6 +44,7 @@ extra_rdoc_files:
|
|
41
44
|
- CHANGELOG
|
42
45
|
- README
|
43
46
|
- lib/adapters/s3_adapter.rb
|
47
|
+
- lib/adapters/s3cmd_adapter.rb
|
44
48
|
- lib/backup2s3.rb
|
45
49
|
- lib/backup_management/backup.rb
|
46
50
|
- lib/backup_management/backup_manager.rb
|
@@ -56,6 +60,7 @@ files:
|
|
56
60
|
- generators/backup2s3/templates/backup2s3.yml
|
57
61
|
- init.rb
|
58
62
|
- lib/adapters/s3_adapter.rb
|
63
|
+
- lib/adapters/s3cmd_adapter.rb
|
59
64
|
- lib/backup2s3.rb
|
60
65
|
- lib/backup_management/backup.rb
|
61
66
|
- lib/backup_management/backup_manager.rb
|
@@ -76,16 +81,20 @@ rdoc_options:
|
|
76
81
|
require_paths:
|
77
82
|
- lib
|
78
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
79
85
|
requirements:
|
80
86
|
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
82
89
|
segments:
|
83
90
|
- 0
|
84
91
|
version: "0"
|
85
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
86
94
|
requirements:
|
87
95
|
- - ">="
|
88
96
|
- !ruby/object:Gem::Version
|
97
|
+
hash: 11
|
89
98
|
segments:
|
90
99
|
- 1
|
91
100
|
- 2
|
@@ -93,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
102
|
requirements: []
|
94
103
|
|
95
104
|
rubyforge_project: backup2s3
|
96
|
-
rubygems_version: 1.3.
|
105
|
+
rubygems_version: 1.3.7
|
97
106
|
signing_key:
|
98
107
|
specification_version: 3
|
99
108
|
summary: Backup2s3 is a gem that creates, deletes and restores db and application backups.
|