backup 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -27,9 +27,25 @@ This looks basically the same as the other options, except that you will have to
27
27
  line'd shell command" to generate a sql dump file. Once you generate the file, Backup will take care of the rest
28
28
  of the (optional)archiving, compressing, encrypting and pushing to Amazon S3 or any remote server that supports SSH.
29
29
 
30
+
30
31
  === Encryption
31
32
 
32
33
  Backup also provides encryption. Adding a single line to one of the configuration files will enable encryption for your backups!
34
+ This is what that line looks like:
35
+
36
+ encrypt: my_secret_password
37
+
38
+ Now all backups will be encrypted with the specified password.
39
+
40
+
41
+ === Backup Cleaning
42
+
43
+ Backup has the ability to clean up old backup files. If you don't feel the need to have more than 120 backups on your S3 account then you can easily specify so! It's as simple as adding this line to your configuration file. (or rather, uncommenting it)
44
+
45
+ keep_backups: 120
46
+
47
+ It will now automagically remove the oldest backup from for example, S3, when the 121st backup gets uploaded.
48
+
33
49
 
34
50
  == Why?
35
51
 
@@ -40,6 +56,7 @@ Backup also provides encryption. Adding a single line to one of the configuratio
40
56
  - I wanted it to support an additional (custom) adapter incase the database type isn't SQLite3 or MySQL
41
57
  - I wanted it to support some encryption
42
58
  - I wanted to be able to store my files on my private backup server and on Amazon S3
59
+ - I wanted it to be able to automatically (and optionally) remove old backups to keep S3/backup server costs low
43
60
 
44
61
  ==== Setting up Backup takes me about 1-2 minutes and it's really easy!
45
62
 
@@ -89,17 +106,6 @@ Report it!
89
106
  http://github.com/meskyanichi/backup/issues
90
107
 
91
108
 
92
- === Upcoming Feature(s)
93
-
94
- The ability to set the amount of backups you wish to keep stored.
95
- This will be configurable inside the .yml files.
96
- It'd look something like this:
97
-
98
- keep_backups: 50
99
-
100
- When this is set, and the 51th backup gets stored, it will remove the oldest one from S3 or what ever other
101
- server you've set up to back up to.
102
-
103
109
  === Copyright
104
110
 
105
111
  Copyright (c) 2009 Michael van Rooijen | Final Creation. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
data/backup.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backup}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["meskyanichi"]
@@ -1,33 +1,22 @@
1
+ def generate_yaml(config_file)
2
+ File.open(File.join(RAILS_ROOT, 'config', 'backup', config_file), 'r') do |file|
3
+ tmp_file = File.new(File.join(RAILS_ROOT, 'config', 'backup', 'tmp.yml'), 'w+')
4
+ tmp_file.write(file.read.gsub(/:rails_root/, RAILS_ROOT))
5
+ tmp_file.close
6
+ end
7
+ yaml_file = YAML.load_file(File.join(RAILS_ROOT, 'config', 'backup', 'tmp.yml'))
8
+ File.delete(File.join(RAILS_ROOT, 'config', 'backup', 'tmp.yml'))
9
+ return yaml_file
10
+ end
11
+
1
12
  namespace :backup do
2
13
 
3
14
  task :s3_config => :environment do
4
- @config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'backup', 's3.yml'))
5
-
6
- @config.each do |key, value|
7
- value.each do |k, v|
8
- if @config[key][k].is_a?(String)
9
- @config[key][k] = @config[key][k][v].gsub(/:rails_root/, RAILS_ROOT)
10
- end
11
- if @config[key][k].is_a?(Array)
12
- @config[key][k].map! {|string| string.gsub(/:rails_root/, RAILS_ROOT)}
13
- end
14
- end
15
- end
15
+ @config = generate_yaml('s3.yml')
16
16
  end
17
17
 
18
18
  task :ssh_config => :environment do
19
- @config = YAML.load_file(File.join(RAILS_ROOT, 'config', 'backup', 'ssh.yml'))
20
-
21
- @config.each do |key, value|
22
- value.each do |k, v|
23
- if @config[key][k].is_a?(String)
24
- @config[key][k] = @config[key][k][v].gsub(/:rails_root/, RAILS_ROOT)
25
- end
26
- if @config[key][k].is_a?(Array)
27
- @config[key][k].map! {|string| string.gsub(/:rails_root/, RAILS_ROOT)}
28
- end
29
- end
30
- end
19
+ @config = generate_yaml('ssh.yml')
31
20
  end
32
21
 
33
22
  end
@@ -11,24 +11,48 @@ namespace :backup do
11
11
  desc 'Makes a backup from a MySQL database and transfers it to Amazon S3.'
12
12
  task :mysql => :s3_config do
13
13
  @config = @config['mysql']
14
- Backup::Adapter::Mysql.new({
15
- :adapter => 'mysql',
16
- :mysql => {
17
- :user => @config['mysql_config']['user'],
18
- :password => @config['mysql_config']['password'],
19
- :database => @config['mysql_config']['database']
20
- },
14
+ unless @config.is_a?(Array)
15
+ Backup::Adapter::Mysql.new({
16
+ :adapter => 'mysql',
17
+ :mysql => {
18
+ :user => @config['mysql_config']['user'],
19
+ :password => @config['mysql_config']['password'],
20
+ :database => @config['mysql_config']['database']
21
+ },
21
22
 
22
- :encrypt => @config['encrypt'],
23
- :keep_backups => @config['keep_backups'],
23
+ :encrypt => @config['encrypt'],
24
+ :keep_backups => @config['keep_backups'],
24
25
 
25
- :use => :s3,
26
- :s3 => {
27
- :access_key_id => @config['s3']['access_key_id'],
28
- :secret_access_key => @config['s3']['secret_access_key'],
29
- :bucket => @config['s3']['bucket']
30
- }
31
- }).run
26
+ :use => :s3,
27
+ :s3 => {
28
+ :access_key_id => @config['s3']['access_key_id'],
29
+ :secret_access_key => @config['s3']['secret_access_key'],
30
+ :bucket => @config['s3']['bucket']
31
+ }
32
+ }).run
33
+ else
34
+ @config.each do |config|
35
+ Backup::Adapter::Mysql.new({
36
+ :adapter => 'mysql',
37
+ :mysql => {
38
+ :user => config['mysql_config']['user'],
39
+ :password => config['mysql_config']['password'],
40
+ :database => config['mysql_config']['database']
41
+ },
42
+
43
+ :encrypt => config['encrypt'],
44
+ :keep_backups => config['keep_backups'],
45
+
46
+ :use => :s3,
47
+ :s3 => {
48
+ :access_key_id => config['s3']['access_key_id'],
49
+ :secret_access_key => config['s3']['secret_access_key'],
50
+ :bucket => config['s3']['bucket']
51
+ }
52
+ }).run
53
+ sleep(1)
54
+ end
55
+ end
32
56
  end
33
57
 
34
58
  # => rake backup:s3:sqlite3
@@ -41,20 +65,40 @@ namespace :backup do
41
65
  desc 'Makes a backup from a SQLite3 database and transfers it to Amazon S3.'
42
66
  task :sqlite3 => :s3_config do
43
67
  @config = @config['sqlite3']
44
- Backup::Adapter::Sqlite3.new({
45
- :adapter => 'sqlite3',
46
- :file => @config['file'],
47
- :path => @config['path'],
48
- :encrypt => @config['encrypt'],
49
- :keep_backups => @config['keep_backups'],
68
+ unless @config.is_a?(Array)
69
+ Backup::Adapter::Sqlite3.new({
70
+ :adapter => 'sqlite3',
71
+ :file => @config['file'],
72
+ :path => @config['path'],
73
+ :encrypt => @config['encrypt'],
74
+ :keep_backups => @config['keep_backups'],
50
75
 
51
- :use => :s3,
52
- :s3 => {
53
- :access_key_id => @config['s3']['access_key_id'],
54
- :secret_access_key => @config['s3']['secret_access_key'],
55
- :bucket => @config['s3']['bucket']
56
- }
57
- }).run
76
+ :use => :s3,
77
+ :s3 => {
78
+ :access_key_id => @config['s3']['access_key_id'],
79
+ :secret_access_key => @config['s3']['secret_access_key'],
80
+ :bucket => @config['s3']['bucket']
81
+ }
82
+ }).run
83
+ else
84
+ @config.each do |config|
85
+ Backup::Adapter::Sqlite3.new({
86
+ :adapter => 'sqlite3',
87
+ :file => config['file'],
88
+ :path => config['path'],
89
+ :encrypt => config['encrypt'],
90
+ :keep_backups => config['keep_backups'],
91
+
92
+ :use => :s3,
93
+ :s3 => {
94
+ :access_key_id => config['s3']['access_key_id'],
95
+ :secret_access_key => config['s3']['secret_access_key'],
96
+ :bucket => config['s3']['bucket']
97
+ }
98
+ }).run
99
+ sleep(1)
100
+ end
101
+ end
58
102
  end
59
103
 
60
104
  # => rake backup:s3:assets
@@ -67,19 +111,38 @@ namespace :backup do
67
111
  desc 'Makes a backup from Assets and transfers it to Amazon S3.'
68
112
  task :assets => :s3_config do
69
113
  @config = @config['assets']
70
- Backup::Adapter::Assets.new({
71
- :adapter => 'assets',
72
- :path => @config['path'],
73
- :encrypt => @config['encrypt'],
74
- :keep_backups => @config['keep_backups'],
114
+ unless @config.is_a?(Array)
115
+ Backup::Adapter::Assets.new({
116
+ :adapter => 'assets',
117
+ :path => @config['path'],
118
+ :encrypt => @config['encrypt'],
119
+ :keep_backups => @config['keep_backups'],
75
120
 
76
- :use => :s3,
77
- :s3 => {
78
- :access_key_id => @config['s3']['access_key_id'],
79
- :secret_access_key => @config['s3']['secret_access_key'],
80
- :bucket => @config['s3']['bucket']
81
- }
82
- }).run
121
+ :use => :s3,
122
+ :s3 => {
123
+ :access_key_id => @config['s3']['access_key_id'],
124
+ :secret_access_key => @config['s3']['secret_access_key'],
125
+ :bucket => @config['s3']['bucket']
126
+ }
127
+ }).run
128
+ else
129
+ @config.each do |config|
130
+ Backup::Adapter::Assets.new({
131
+ :adapter => 'assets',
132
+ :path => config['path'],
133
+ :encrypt => config['encrypt'],
134
+ :keep_backups => config['keep_backups'],
135
+
136
+ :use => :s3,
137
+ :s3 => {
138
+ :access_key_id => config['s3']['access_key_id'],
139
+ :secret_access_key => config['s3']['secret_access_key'],
140
+ :bucket => config['s3']['bucket']
141
+ }
142
+ }).run
143
+ sleep(1)
144
+ end
145
+ end
83
146
  end
84
147
 
85
148
  # => rake backup:s3:custom
@@ -119,21 +182,42 @@ namespace :backup do
119
182
  desc 'Makes a backup from a Custom database and transfers it to Amazon S3.'
120
183
  task :custom => :s3_config do
121
184
  @config = @config['custom']
122
- Backup::Adapter::Custom.new({
123
- :adapter => 'custom',
124
- :file => @config['file'],
125
- :path => @config['path'],
126
- :command => @config['command'],
127
- :encrypt => @config['encrypt'],
128
- :keep_backups => @config['keep_backups'],
185
+ unless @config.is_a?(Array)
186
+ Backup::Adapter::Custom.new({
187
+ :adapter => 'custom',
188
+ :file => @config['file'],
189
+ :path => @config['path'],
190
+ :command => @config['command'],
191
+ :encrypt => @config['encrypt'],
192
+ :keep_backups => @config['keep_backups'],
129
193
 
130
- :use => :s3,
131
- :s3 => {
132
- :access_key_id => @config['s3']['access_key_id'],
133
- :secret_access_key => @config['s3']['secret_access_key'],
134
- :bucket => @config['s3']['bucket']
135
- }
136
- }).run
194
+ :use => :s3,
195
+ :s3 => {
196
+ :access_key_id => @config['s3']['access_key_id'],
197
+ :secret_access_key => @config['s3']['secret_access_key'],
198
+ :bucket => @config['s3']['bucket']
199
+ }
200
+ }).run
201
+ else
202
+ @config.each do |config|
203
+ Backup::Adapter::Custom.new({
204
+ :adapter => 'custom',
205
+ :file => config['file'],
206
+ :path => config['path'],
207
+ :command => config['command'],
208
+ :encrypt => config['encrypt'],
209
+ :keep_backups => config['keep_backups'],
210
+
211
+ :use => :s3,
212
+ :s3 => {
213
+ :access_key_id => config['s3']['access_key_id'],
214
+ :secret_access_key => config['s3']['secret_access_key'],
215
+ :bucket => config['s3']['bucket']
216
+ }
217
+ }).run
218
+ sleep(1)
219
+ end
220
+ end
137
221
  end
138
222
  end
139
223
  end
@@ -9,24 +9,48 @@ namespace :backup do
9
9
  desc 'Makes a backup from a MySQL database and transfers it through SSH (SCP).'
10
10
  task :mysql => :ssh_config do
11
11
  @config = @config['mysql']
12
- Backup::Adapter::Mysql.new({
13
- :adapter => 'mysql',
14
- :mysql => {
15
- :user => @config['mysql_config']['user'],
16
- :password => @config['mysql_config']['password'],
17
- :database => @config['mysql_config']['database']
18
- },
12
+ unless @config.is_a?(Array)
13
+ Backup::Adapter::Mysql.new({
14
+ :adapter => 'mysql',
15
+ :mysql => {
16
+ :user => @config['mysql_config']['user'],
17
+ :password => @config['mysql_config']['password'],
18
+ :database => @config['mysql_config']['database']
19
+ },
19
20
 
20
- :encrypt => @config['encrypt'],
21
- :keep_backups => @config['keep_backups'],
21
+ :encrypt => @config['encrypt'],
22
+ :keep_backups => @config['keep_backups'],
22
23
 
23
- :use => :ssh,
24
- :ssh => {
25
- :user => @config['ssh']['user'],
26
- :ip => @config['ssh']['ip'],
27
- :path => @config['ssh']['path']
28
- }
29
- }).run
24
+ :use => :ssh,
25
+ :ssh => {
26
+ :user => @config['ssh']['user'],
27
+ :ip => @config['ssh']['ip'],
28
+ :path => @config['ssh']['path']
29
+ }
30
+ }).run
31
+ else
32
+ @config.each do |config|
33
+ Backup::Adapter::Mysql.new({
34
+ :adapter => 'mysql',
35
+ :mysql => {
36
+ :user => config['mysql_config']['user'],
37
+ :password => config['mysql_config']['password'],
38
+ :database => config['mysql_config']['database']
39
+ },
40
+
41
+ :encrypt => config['encrypt'],
42
+ :keep_backups => config['keep_backups'],
43
+
44
+ :use => :ssh,
45
+ :ssh => {
46
+ :user => config['ssh']['user'],
47
+ :ip => config['ssh']['ip'],
48
+ :path => config['ssh']['path']
49
+ }
50
+ }).run
51
+ sleep(1)
52
+ end
53
+ end
30
54
  end
31
55
 
32
56
  # => rake backup:ssh:sqlite3
@@ -38,20 +62,40 @@ namespace :backup do
38
62
  desc 'Makes a backup from a SQLite3 database and transfers it through SSH (SCP).'
39
63
  task :sqlite3 => :ssh_config do
40
64
  @config = @config['sqlite3']
41
- Backup::Adapter::Sqlite3.new({
42
- :adapter => 'sqlite3',
43
- :file => @config['file'],
44
- :path => @config['path'],
45
- :encrypt => @config['encrypt'],
46
- :keep_backups => @config['keep_backups'],
65
+ unless @config.is_a?(Array)
66
+ Backup::Adapter::Sqlite3.new({
67
+ :adapter => 'sqlite3',
68
+ :file => @config['file'],
69
+ :path => @config['path'],
70
+ :encrypt => @config['encrypt'],
71
+ :keep_backups => @config['keep_backups'],
47
72
 
48
- :use => :ssh,
49
- :ssh => {
50
- :user => @config['ssh']['user'],
51
- :ip => @config['ssh']['ip'],
52
- :path => @config['ssh']['path']
53
- }
54
- }).run
73
+ :use => :ssh,
74
+ :ssh => {
75
+ :user => @config['ssh']['user'],
76
+ :ip => @config['ssh']['ip'],
77
+ :path => @config['ssh']['path']
78
+ }
79
+ }).run
80
+ else
81
+ @config.each do |config|
82
+ Backup::Adapter::Sqlite3.new({
83
+ :adapter => 'sqlite3',
84
+ :file => config['file'],
85
+ :path => config['path'],
86
+ :encrypt => config['encrypt'],
87
+ :keep_backups => config['keep_backups'],
88
+
89
+ :use => :ssh,
90
+ :ssh => {
91
+ :user => config['ssh']['user'],
92
+ :ip => config['ssh']['ip'],
93
+ :path => config['ssh']['path']
94
+ }
95
+ }).run
96
+ sleep(1)
97
+ end
98
+ end
55
99
  end
56
100
 
57
101
  # => rake backup:ssh:assets
@@ -62,19 +106,38 @@ namespace :backup do
62
106
  desc 'Makes a backup from Assets and transfers it through SSH (SCP).'
63
107
  task :assets => :ssh_config do
64
108
  @config = @config['assets']
65
- Backup::Adapter::Assets.new({
66
- :adapter => 'assets',
67
- :path => @config['path'],
68
- :encrypt => @config['encrypt'],
69
- :keep_backups => @config['keep_backups'],
109
+ unless @config.is_a?(Array)
110
+ Backup::Adapter::Assets.new({
111
+ :adapter => 'assets',
112
+ :path => @config['path'],
113
+ :encrypt => @config['encrypt'],
114
+ :keep_backups => @config['keep_backups'],
70
115
 
71
- :use => :ssh,
72
- :ssh => {
73
- :user => @config['ssh']['user'],
74
- :ip => @config['ssh']['ip'],
75
- :path => @config['ssh']['path']
76
- }
77
- }).run
116
+ :use => :ssh,
117
+ :ssh => {
118
+ :user => @config['ssh']['user'],
119
+ :ip => @config['ssh']['ip'],
120
+ :path => @config['ssh']['path']
121
+ }
122
+ }).run
123
+ else
124
+ @config.each do |config|
125
+ Backup::Adapter::Assets.new({
126
+ :adapter => 'assets',
127
+ :path => config['path'],
128
+ :encrypt => config['encrypt'],
129
+ :keep_backups => config['keep_backups'],
130
+
131
+ :use => :ssh,
132
+ :ssh => {
133
+ :user => config['ssh']['user'],
134
+ :ip => config['ssh']['ip'],
135
+ :path => config['ssh']['path']
136
+ }
137
+ }).run
138
+ sleep(1)
139
+ end
140
+ end
78
141
  end
79
142
 
80
143
  # => rake backup:ssh:custom
@@ -114,21 +177,42 @@ namespace :backup do
114
177
  desc 'Makes a backup from a Custom database and transfers it through SSH (SCP).'
115
178
  task :custom => :ssh_config do
116
179
  @config = @config['custom']
117
- Backup::Adapter::Custom.new({
118
- :adapter => 'custom',
119
- :file => @config['file'],
120
- :path => @config['path'],
121
- :command => @config['command'],
122
- :encrypt => @config['encrypt'],
123
- :keep_backups => @config['keep_backups'],
180
+ unless @config.is_a?(Array)
181
+ Backup::Adapter::Custom.new({
182
+ :adapter => 'custom',
183
+ :file => @config['file'],
184
+ :path => @config['path'],
185
+ :command => @config['command'],
186
+ :encrypt => @config['encrypt'],
187
+ :keep_backups => @config['keep_backups'],
124
188
 
125
- :use => :ssh,
126
- :ssh => {
127
- :user => @config['ssh']['user'],
128
- :ip => @config['ssh']['ip'],
129
- :path => @config['ssh']['path']
130
- }
131
- }).run
189
+ :use => :ssh,
190
+ :ssh => {
191
+ :user => @config['ssh']['user'],
192
+ :ip => @config['ssh']['ip'],
193
+ :path => @config['ssh']['path']
194
+ }
195
+ }).run
196
+ else
197
+ @config.each do |config|
198
+ Backup::Adapter::Custom.new({
199
+ :adapter => 'custom',
200
+ :file => config['file'],
201
+ :path => config['path'],
202
+ :command => config['command'],
203
+ :encrypt => config['encrypt'],
204
+ :keep_backups => config['keep_backups'],
205
+
206
+ :use => :ssh,
207
+ :ssh => {
208
+ :user => config['ssh']['user'],
209
+ :ip => config['ssh']['ip'],
210
+ :path => config['ssh']['path']
211
+ }
212
+ }).run
213
+ sleep(1)
214
+ end
215
+ end
132
216
  end
133
217
  end
134
218
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - meskyanichi