backup 2.3.1 → 2.3.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +16 -1
- data/README.textile +42 -177
- data/bin/backup +14 -17
- data/generators/backup/templates/config/backup.rb +26 -6
- data/generators/backup/templates/migrations/create_backup_tables.rb +3 -2
- data/generators/backup/templates/tasks/backup.rake +14 -17
- data/generators/backup_update/backup_update_generator.rb +50 -0
- data/generators/backup_update/templates/migrations/update_backup_tables.rb +27 -0
- data/lib/backup.rb +31 -30
- data/lib/backup/adapters/archive.rb +19 -54
- data/lib/backup/adapters/base.rb +55 -35
- data/lib/backup/adapters/custom.rb +15 -53
- data/lib/backup/adapters/mysql.rb +24 -55
- data/lib/backup/adapters/postgresql.rb +19 -54
- data/lib/backup/adapters/sqlite.rb +25 -0
- data/lib/backup/command_helper.rb +11 -0
- data/lib/backup/configuration/adapter.rb +4 -11
- data/lib/backup/configuration/adapter_options.rb +3 -14
- data/lib/backup/configuration/attributes.rb +19 -0
- data/lib/backup/configuration/base.rb +26 -9
- data/lib/backup/configuration/mail.rb +3 -9
- data/lib/backup/configuration/smtp.rb +3 -14
- data/lib/backup/configuration/storage.rb +3 -12
- data/lib/backup/connection/s3.rb +3 -1
- data/lib/backup/environment/unix.rb +4 -4
- data/lib/backup/mail/base.rb +8 -2
- data/lib/backup/mail/mail.txt +3 -3
- data/lib/backup/record/base.rb +65 -0
- data/lib/backup/record/ftp.rb +10 -69
- data/lib/backup/record/local.rb +26 -0
- data/lib/backup/record/s3.rb +9 -63
- data/lib/backup/record/scp.rb +9 -64
- data/lib/backup/record/sftp.rb +10 -68
- data/lib/backup/storage/ftp.rb +3 -1
- data/lib/backup/storage/local.rb +24 -0
- data/lib/backup/storage/s3.rb +3 -1
- data/lib/backup/storage/scp.rb +3 -1
- data/lib/backup/storage/sftp.rb +3 -1
- data/setup/backup.rb +27 -6
- data/setup/backup.sqlite3 +0 -0
- metadata +130 -60
- data/.document +0 -5
- data/.gitignore +0 -5
- data/Rakefile +0 -70
- data/backup.gemspec +0 -111
data/lib/backup/record/sftp.rb
CHANGED
@@ -1,41 +1,20 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
|
1
3
|
module Backup
|
2
4
|
module Record
|
3
|
-
class SFTP <
|
4
|
-
|
5
|
-
if DB_CONNECTION_SETTINGS
|
6
|
-
establish_connection(DB_CONNECTION_SETTINGS)
|
7
|
-
end
|
5
|
+
class SFTP < Backup::Record::Base
|
8
6
|
|
9
|
-
|
10
|
-
default_scope \
|
11
|
-
:order => 'created_at desc',
|
12
|
-
:conditions => {:storage => 'sftp'}
|
13
|
-
|
14
|
-
# Callbacks
|
15
|
-
after_save :clean_backups
|
16
|
-
|
17
|
-
# Attributes
|
18
|
-
attr_accessor :adapter_config, :keep_backups, :ip, :user, :password
|
7
|
+
attr_accessor :ip, :user, :password
|
19
8
|
|
20
|
-
|
21
|
-
# Sets the SCP values
|
22
|
-
def load_adapter(adapter)
|
23
|
-
self.adapter_config = adapter
|
24
|
-
self.storage = 'sftp'
|
25
|
-
self.trigger = adapter.procedure.trigger
|
26
|
-
self.adapter = adapter.procedure.adapter_name.to_s
|
27
|
-
self.filename = adapter.final_file
|
28
|
-
self.keep_backups = adapter.procedure.attributes['keep_backups']
|
29
|
-
|
9
|
+
def load_specific_settings(adapter)
|
30
10
|
%w(ip user password path).each do |method|
|
31
11
|
send(:"#{method}=", adapter.procedure.get_storage_configuration.attributes[method])
|
32
12
|
end
|
33
13
|
end
|
34
14
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
unless backups.empty?
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.destroy_backups(procedure, backups)
|
39
18
|
ip = procedure.get_storage_configuration.attributes['ip']
|
40
19
|
user = procedure.get_storage_configuration.attributes['user']
|
41
20
|
password = procedure.get_storage_configuration.attributes['password']
|
@@ -47,50 +26,13 @@ module Backup
|
|
47
26
|
sftp.remove!(File.join(backup.path, backup.filename))
|
48
27
|
backup.destroy
|
49
28
|
rescue
|
29
|
+
puts "Could not find backup #{backup.path}/#{backup.filename}.."
|
50
30
|
backup.destroy
|
51
31
|
end
|
52
32
|
end
|
53
33
|
end
|
54
|
-
|
55
|
-
puts "\nAll \"#{trigger}\" backups destroyed.\n\n"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
# Maintains the backup file amount on the remote server
|
62
|
-
# This is invoked after a successful record save
|
63
|
-
# This deletes the oldest files when the backup limit has been exceeded
|
64
|
-
def clean_backups
|
65
|
-
if keep_backups.is_a?(Integer)
|
66
|
-
backups = Backup::Record::SFTP.all(:conditions => {:trigger => trigger})
|
67
|
-
backups_to_destroy = Array.new
|
68
|
-
backups.each_with_index do |backup, index|
|
69
|
-
if index >= keep_backups then
|
70
|
-
backups_to_destroy << backup
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
unless backups_to_destroy.empty?
|
75
|
-
Net::SFTP.start(ip, user, :password => password) do |sftp|
|
76
|
-
backups_to_destroy.each do |backup|
|
77
|
-
puts "\nDestroying backup \"#{backup.filename}\" from path \"#{backup.path}\"."
|
78
|
-
begin
|
79
|
-
sftp.remove!(File.join(backup.path, backup.filename))
|
80
|
-
backup.destroy
|
81
|
-
rescue
|
82
|
-
puts "Could not find backup #{backup.path}/#{backup.filename}.."
|
83
|
-
backup.destroy
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
puts "\nBackup storage for \"#{trigger}\" is limited to #{keep_backups} backups."
|
89
|
-
puts "\nThe #{keep_backups} most recent backups are now stored on the remote server.\n\n"
|
90
|
-
end
|
91
|
-
end
|
92
34
|
end
|
93
35
|
|
94
36
|
end
|
95
37
|
end
|
96
|
-
end
|
38
|
+
end
|
data/lib/backup/storage/ftp.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Backup
|
2
|
+
module Storage
|
3
|
+
class Local
|
4
|
+
|
5
|
+
include Backup::CommandHelper
|
6
|
+
|
7
|
+
# Store on same machine, preferentially in a different hard drive or in
|
8
|
+
# a mounted network path (NFS, Samba, etc)
|
9
|
+
attr_accessor :path, :tmp_path, :final_file
|
10
|
+
|
11
|
+
# Stores the backup file on local machine
|
12
|
+
def initialize(adapter)
|
13
|
+
self.path = adapter.procedure.get_storage_configuration.attributes['path']
|
14
|
+
self.tmp_path = adapter.tmp_path
|
15
|
+
self.final_file = adapter.final_file
|
16
|
+
|
17
|
+
run "mkdir -p #{path}"
|
18
|
+
run "cp #{File.join(tmp_path, final_file).gsub('\ ', ' ')} #{File.join(path, final_file)}"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/lib/backup/storage/s3.rb
CHANGED
data/lib/backup/storage/scp.rb
CHANGED
data/lib/backup/storage/sftp.rb
CHANGED
data/setup/backup.rb
CHANGED
@@ -16,18 +16,21 @@
|
|
16
16
|
# ADAPTERS
|
17
17
|
# - MySQL
|
18
18
|
# - PostgreSQL
|
19
|
+
# - SQLite
|
19
20
|
# - Archive
|
20
21
|
# - Custom
|
21
22
|
#
|
22
23
|
# STORAGE METHODS
|
23
|
-
# - S3
|
24
|
-
# - SCP
|
25
|
-
# - FTP
|
26
|
-
# - SFTP
|
24
|
+
# - S3 (Amazon)
|
25
|
+
# - SCP (Remote Server)
|
26
|
+
# - FTP (Remote Server)
|
27
|
+
# - SFTP (Remote Server)
|
28
|
+
# - LOCAL (Local Server)
|
27
29
|
#
|
28
30
|
# GLOBAL OPTIONS
|
29
31
|
# - Keep Backups (keep_backups)
|
30
32
|
# - Encrypt With Pasword (encrypt_with_password)
|
33
|
+
# - Notify (notify)
|
31
34
|
#
|
32
35
|
# This is the "decrypt" command for all encrypted backups:
|
33
36
|
# sudo backup --decrypt /path/to/encrypted/file
|
@@ -138,8 +141,7 @@ end
|
|
138
141
|
backup 'archive-backup-ftp' do
|
139
142
|
|
140
143
|
adapter :archive do
|
141
|
-
files ["log", "db"]
|
142
|
-
# files "log"
|
144
|
+
files ["/path/to/log", "/path/to/db"]
|
143
145
|
end
|
144
146
|
|
145
147
|
storage :ftp do
|
@@ -178,4 +180,23 @@ backup 'custom-backup-sftp' do
|
|
178
180
|
encrypt_with_password 'password'
|
179
181
|
notify false
|
180
182
|
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
# Initializ with:
|
187
|
+
# sudo backup --run sqlite-backup-local
|
188
|
+
backup 'sqlite-backup-local' do
|
189
|
+
|
190
|
+
adapter :sqlite do
|
191
|
+
database "/path/to/database.sqlite3"
|
192
|
+
end
|
193
|
+
|
194
|
+
storage :local do
|
195
|
+
path "/path/to/storage/location/"
|
196
|
+
end
|
197
|
+
|
198
|
+
keep_backups :all
|
199
|
+
encrypt_with_password false
|
200
|
+
notify false
|
201
|
+
|
181
202
|
end
|
data/setup/backup.sqlite3
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 961916020
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 3
|
9
|
+
- 2
|
10
|
+
- pre
|
11
|
+
version: 2.3.2.pre
|
5
12
|
platform: ruby
|
6
13
|
authors:
|
7
14
|
- Michael van Rooijen
|
@@ -9,120 +16,164 @@ autorequire:
|
|
9
16
|
bindir: bin
|
10
17
|
cert_chain: []
|
11
18
|
|
12
|
-
date: 2010-
|
13
|
-
default_executable:
|
19
|
+
date: 2010-07-10 00:00:00 +02:00
|
20
|
+
default_executable:
|
14
21
|
dependencies:
|
15
22
|
- !ruby/object:Gem::Dependency
|
16
23
|
name: aws-s3
|
17
|
-
|
18
|
-
|
19
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
20
27
|
requirements:
|
21
28
|
- - ">="
|
22
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 6
|
34
|
+
- 2
|
23
35
|
version: 0.6.2
|
24
|
-
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
25
38
|
- !ruby/object:Gem::Dependency
|
26
39
|
name: net-ssh
|
27
|
-
|
28
|
-
|
29
|
-
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
30
43
|
requirements:
|
31
44
|
- - ">="
|
32
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 17
|
47
|
+
segments:
|
48
|
+
- 2
|
49
|
+
- 0
|
50
|
+
- 15
|
33
51
|
version: 2.0.15
|
34
|
-
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
35
54
|
- !ruby/object:Gem::Dependency
|
36
55
|
name: net-scp
|
37
|
-
|
38
|
-
|
39
|
-
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
40
59
|
requirements:
|
41
60
|
- - ">="
|
42
61
|
- !ruby/object:Gem::Version
|
62
|
+
hash: 19
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 0
|
66
|
+
- 2
|
43
67
|
version: 1.0.2
|
44
|
-
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id003
|
45
70
|
- !ruby/object:Gem::Dependency
|
46
71
|
name: net-sftp
|
47
|
-
|
48
|
-
|
49
|
-
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
50
75
|
requirements:
|
51
76
|
- - ">="
|
52
77
|
- !ruby/object:Gem::Version
|
78
|
+
hash: 7
|
79
|
+
segments:
|
80
|
+
- 2
|
81
|
+
- 0
|
82
|
+
- 4
|
53
83
|
version: 2.0.4
|
54
|
-
|
84
|
+
type: :runtime
|
85
|
+
version_requirements: *id004
|
55
86
|
- !ruby/object:Gem::Dependency
|
56
87
|
name: activerecord
|
57
|
-
|
58
|
-
|
59
|
-
|
88
|
+
prerelease: false
|
89
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
60
91
|
requirements:
|
61
92
|
- - ">="
|
62
93
|
- !ruby/object:Gem::Version
|
94
|
+
hash: 9
|
95
|
+
segments:
|
96
|
+
- 2
|
97
|
+
- 3
|
98
|
+
- 5
|
63
99
|
version: 2.3.5
|
64
|
-
|
100
|
+
type: :runtime
|
101
|
+
version_requirements: *id005
|
65
102
|
- !ruby/object:Gem::Dependency
|
66
103
|
name: sqlite3-ruby
|
67
|
-
|
68
|
-
|
69
|
-
|
104
|
+
prerelease: false
|
105
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
70
107
|
requirements:
|
71
|
-
- - "
|
108
|
+
- - "="
|
72
109
|
- !ruby/object:Gem::Version
|
110
|
+
hash: 21
|
111
|
+
segments:
|
112
|
+
- 1
|
113
|
+
- 2
|
114
|
+
- 5
|
73
115
|
version: 1.2.5
|
74
|
-
|
116
|
+
type: :runtime
|
117
|
+
version_requirements: *id006
|
75
118
|
- !ruby/object:Gem::Dependency
|
76
119
|
name: hirb
|
77
|
-
|
78
|
-
|
79
|
-
|
120
|
+
prerelease: false
|
121
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
80
123
|
requirements:
|
81
124
|
- - ">="
|
82
125
|
- !ruby/object:Gem::Version
|
126
|
+
hash: 5
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
- 2
|
130
|
+
- 9
|
83
131
|
version: 0.2.9
|
84
|
-
|
132
|
+
type: :runtime
|
133
|
+
version_requirements: *id007
|
85
134
|
- !ruby/object:Gem::Dependency
|
86
135
|
name: pony
|
87
|
-
|
88
|
-
|
89
|
-
|
136
|
+
prerelease: false
|
137
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
90
139
|
requirements:
|
91
140
|
- - ">="
|
92
141
|
- !ruby/object:Gem::Version
|
142
|
+
hash: 1
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
- 5
|
93
146
|
version: "0.5"
|
94
|
-
|
95
|
-
|
96
|
-
|
147
|
+
type: :runtime
|
148
|
+
version_requirements: *id008
|
149
|
+
description: |-
|
150
|
+
Backup is a Ruby Gem written for Unix and Rails environments. It can be used both with and without the
|
151
|
+
Ruby on Rails framework! This gem offers a quick and simple solution to backing up databases such as
|
152
|
+
MySQL/PostgreSQL and Files/Folders. All backups can be transferred to Amazon S3 or any remote server you
|
153
|
+
have access to, using either SCP, SFTP or regular FTP. Backup handles Compression, Archiving, Encryption
|
154
|
+
and Backup Cleaning (Cycling).
|
155
|
+
email: meskyanichi@gmail.com
|
97
156
|
executables:
|
98
157
|
- backup
|
99
158
|
extensions: []
|
100
159
|
|
101
|
-
extra_rdoc_files:
|
102
|
-
|
103
|
-
- README.textile
|
160
|
+
extra_rdoc_files: []
|
161
|
+
|
104
162
|
files:
|
105
|
-
- .
|
106
|
-
- .gitignore
|
163
|
+
- README.textile
|
107
164
|
- CHANGELOG
|
108
165
|
- LICENSE
|
109
|
-
- README.textile
|
110
|
-
- Rakefile
|
111
166
|
- VERSION
|
112
|
-
- backup.gemspec
|
113
|
-
- bin/backup
|
114
|
-
- generators/backup/backup_generator.rb
|
115
|
-
- generators/backup/templates/config/backup.rb
|
116
|
-
- generators/backup/templates/migrations/create_backup_tables.rb
|
117
|
-
- generators/backup/templates/tasks/backup.rake
|
118
|
-
- lib/backup.rb
|
119
167
|
- lib/backup/adapters/archive.rb
|
120
168
|
- lib/backup/adapters/base.rb
|
121
169
|
- lib/backup/adapters/custom.rb
|
122
170
|
- lib/backup/adapters/mysql.rb
|
123
171
|
- lib/backup/adapters/postgresql.rb
|
172
|
+
- lib/backup/adapters/sqlite.rb
|
173
|
+
- lib/backup/command_helper.rb
|
124
174
|
- lib/backup/configuration/adapter.rb
|
125
175
|
- lib/backup/configuration/adapter_options.rb
|
176
|
+
- lib/backup/configuration/attributes.rb
|
126
177
|
- lib/backup/configuration/base.rb
|
127
178
|
- lib/backup/configuration/helpers.rb
|
128
179
|
- lib/backup/configuration/mail.rb
|
@@ -134,41 +185,60 @@ files:
|
|
134
185
|
- lib/backup/environment/unix.rb
|
135
186
|
- lib/backup/mail/base.rb
|
136
187
|
- lib/backup/mail/mail.txt
|
188
|
+
- lib/backup/record/base.rb
|
137
189
|
- lib/backup/record/ftp.rb
|
190
|
+
- lib/backup/record/local.rb
|
138
191
|
- lib/backup/record/s3.rb
|
139
192
|
- lib/backup/record/scp.rb
|
140
193
|
- lib/backup/record/sftp.rb
|
141
194
|
- lib/backup/storage/ftp.rb
|
195
|
+
- lib/backup/storage/local.rb
|
142
196
|
- lib/backup/storage/s3.rb
|
143
197
|
- lib/backup/storage/scp.rb
|
144
198
|
- lib/backup/storage/sftp.rb
|
199
|
+
- lib/backup.rb
|
200
|
+
- bin/backup
|
201
|
+
- generators/backup/backup_generator.rb
|
202
|
+
- generators/backup/templates/config/backup.rb
|
203
|
+
- generators/backup/templates/migrations/create_backup_tables.rb
|
204
|
+
- generators/backup/templates/tasks/backup.rake
|
205
|
+
- generators/backup_update/backup_update_generator.rb
|
206
|
+
- generators/backup_update/templates/migrations/update_backup_tables.rb
|
145
207
|
- setup/backup.rb
|
146
208
|
- setup/backup.sqlite3
|
147
209
|
has_rdoc: true
|
148
|
-
homepage: http://
|
210
|
+
homepage: http://github.com/meskyanichi/backup
|
149
211
|
licenses: []
|
150
212
|
|
151
213
|
post_install_message:
|
152
|
-
rdoc_options:
|
153
|
-
|
214
|
+
rdoc_options: []
|
215
|
+
|
154
216
|
require_paths:
|
155
217
|
- lib
|
156
218
|
required_ruby_version: !ruby/object:Gem::Requirement
|
219
|
+
none: false
|
157
220
|
requirements:
|
158
221
|
- - ">="
|
159
222
|
- !ruby/object:Gem::Version
|
223
|
+
hash: 3
|
224
|
+
segments:
|
225
|
+
- 0
|
160
226
|
version: "0"
|
161
|
-
version:
|
162
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
|
+
none: false
|
163
229
|
requirements:
|
164
|
-
- - "
|
230
|
+
- - ">"
|
165
231
|
- !ruby/object:Gem::Version
|
166
|
-
|
167
|
-
|
232
|
+
hash: 25
|
233
|
+
segments:
|
234
|
+
- 1
|
235
|
+
- 3
|
236
|
+
- 1
|
237
|
+
version: 1.3.1
|
168
238
|
requirements: []
|
169
239
|
|
170
240
|
rubyforge_project:
|
171
|
-
rubygems_version: 1.3.
|
241
|
+
rubygems_version: 1.3.7
|
172
242
|
signing_key:
|
173
243
|
specification_version: 3
|
174
244
|
summary: Backup is a Ruby Gem that simplifies making backups for databases, files and folders.
|