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 +17 -11
- data/VERSION +1 -1
- data/backup.gemspec +1 -1
- data/generators/backup_files/templates/config.rake +13 -24
- data/generators/backup_files/templates/s3.rake +139 -55
- data/generators/backup_files/templates/ssh.rake +139 -55
- metadata +1 -1
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
|
+
1.2.0
|
data/backup.gemspec
CHANGED
@@ -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 =
|
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 =
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:
|
18
|
-
|
19
|
-
|
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
|
-
|
23
|
-
|
23
|
+
:encrypt => @config['encrypt'],
|
24
|
+
:keep_backups => @config['keep_backups'],
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
:
|
16
|
-
|
17
|
-
|
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
|
-
|
21
|
-
|
21
|
+
:encrypt => @config['encrypt'],
|
22
|
+
:keep_backups => @config['keep_backups'],
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|