backup 1.3.4 → 2.0.0
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/README.rdoc +121 -53
- data/Rakefile +3 -8
- data/VERSION +1 -1
- data/backup.gemspec +20 -34
- data/generators/backup/backup_generator.rb +31 -0
- data/generators/backup/templates/config/backup.rb +60 -0
- data/generators/backup/templates/migrations/create_backup_tables.rb +24 -0
- data/generators/backup/templates/tasks/backup.rake +42 -0
- data/lib/backup.rb +64 -12
- data/lib/backup/adapters/archive.rb +53 -0
- data/lib/backup/adapters/base.rb +65 -0
- data/lib/backup/adapters/mysql.rb +48 -0
- data/lib/backup/configuration/adapter.rb +17 -0
- data/lib/backup/configuration/base.rb +38 -0
- data/lib/backup/configuration/helpers.rb +12 -0
- data/lib/backup/configuration/storage.rb +17 -0
- data/lib/backup/connection/s3.rb +28 -13
- data/lib/backup/record/s3.rb +90 -0
- data/lib/backup/record/scp.rb +92 -0
- data/lib/backup/storage/s3.rb +14 -0
- data/lib/backup/storage/scp.rb +28 -0
- metadata +18 -35
- data/generators/backup_files/backup_files_generator.rb +0 -72
- data/generators/backup_files/templates/backup.sqlite3 +0 -0
- data/generators/backup_files/templates/config.rake +0 -20
- data/generators/backup_files/templates/db.rake +0 -62
- data/generators/backup_files/templates/s3.rake +0 -231
- data/generators/backup_files/templates/s3.yml +0 -120
- data/generators/backup_files/templates/setup.rake +0 -28
- data/generators/backup_files/templates/ssh.rake +0 -226
- data/generators/backup_files/templates/ssh.yml +0 -119
- data/lib/backup/adapter/assets.rb +0 -57
- data/lib/backup/adapter/custom.rb +0 -91
- data/lib/backup/adapter/mysql.rb +0 -65
- data/lib/backup/adapter/sqlite3.rb +0 -49
- data/lib/backup/backup_record/s3.rb +0 -90
- data/lib/backup/backup_record/ssh.rb +0 -90
- data/lib/backup/base.rb +0 -92
- data/lib/backup/connection/base.rb +0 -13
- data/lib/backup/connection/ssh.rb +0 -19
- data/lib/backup/encrypt.rb +0 -18
- data/lib/backup/transfer/base.rb +0 -13
- data/lib/backup/transfer/s3.rb +0 -36
- data/lib/backup/transfer/ssh.rb +0 -30
@@ -1,231 +0,0 @@
|
|
1
|
-
namespace :backup do
|
2
|
-
namespace :s3 do
|
3
|
-
|
4
|
-
# => rake backup:s3:mysql
|
5
|
-
# Fill in your mysql credentials to allow Backup to create a mysql dump, and which database to make a dump from.
|
6
|
-
# Specify that you want to use :s3
|
7
|
-
# Fill in your Amazon S3 Account's Credentials (access_key_id, secret_access_key)
|
8
|
-
# Specify which bucket you wish to store your files to.
|
9
|
-
# If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this:
|
10
|
-
# :bucket => "my_bucket/subfolder1/subfolder2" etc.
|
11
|
-
desc 'Makes a backup from a MySQL database and transfers it to Amazon S3.'
|
12
|
-
task :mysql => :s3_config do
|
13
|
-
@config = @config['mysql']
|
14
|
-
unless @config.is_a?(Array)
|
15
|
-
Backup::Adapter::Mysql.new({
|
16
|
-
:adapter => 'mysql',
|
17
|
-
:index => 0,
|
18
|
-
:mysql => {
|
19
|
-
:user => @config['mysql_config']['user'],
|
20
|
-
:password => @config['mysql_config']['password'],
|
21
|
-
:database => @config['mysql_config']['database']
|
22
|
-
},
|
23
|
-
|
24
|
-
:encrypt => @config['encrypt'],
|
25
|
-
:keep_backups => @config['keep_backups'],
|
26
|
-
|
27
|
-
:use => :s3,
|
28
|
-
:s3 => {
|
29
|
-
:access_key_id => @config['s3']['access_key_id'],
|
30
|
-
:secret_access_key => @config['s3']['secret_access_key'],
|
31
|
-
:bucket => @config['s3']['bucket']
|
32
|
-
}
|
33
|
-
}).run
|
34
|
-
else
|
35
|
-
@config.each_with_index do |config, index|
|
36
|
-
Backup::Adapter::Mysql.new({
|
37
|
-
:adapter => 'mysql',
|
38
|
-
:index => index,
|
39
|
-
:mysql => {
|
40
|
-
:user => config['mysql_config']['user'],
|
41
|
-
:password => config['mysql_config']['password'],
|
42
|
-
:database => config['mysql_config']['database']
|
43
|
-
},
|
44
|
-
|
45
|
-
:encrypt => config['encrypt'],
|
46
|
-
:keep_backups => config['keep_backups'],
|
47
|
-
|
48
|
-
:use => :s3,
|
49
|
-
:s3 => {
|
50
|
-
:access_key_id => config['s3']['access_key_id'],
|
51
|
-
:secret_access_key => config['s3']['secret_access_key'],
|
52
|
-
:bucket => config['s3']['bucket']
|
53
|
-
}
|
54
|
-
}).run
|
55
|
-
sleep(1)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# => rake backup:s3:sqlite3
|
61
|
-
# Specify which sqlite3 file you wish to back up. This will generally be "production.sqlite3". (and this is the default, so you can remove the :file attribute if it is)
|
62
|
-
# Specify that you want to use :s3
|
63
|
-
# Fill in your Amazon S3 Account's Credentials (access_key_id, secret_access_key)
|
64
|
-
# Specify which bucket you wish to store your files to.
|
65
|
-
# If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this:
|
66
|
-
# :bucket => "my_bucket/subfolder1/subfolder2" etc.
|
67
|
-
desc 'Makes a backup from a SQLite3 database and transfers it to Amazon S3.'
|
68
|
-
task :sqlite3 => :s3_config do
|
69
|
-
@config = @config['sqlite3']
|
70
|
-
unless @config.is_a?(Array)
|
71
|
-
Backup::Adapter::Sqlite3.new({
|
72
|
-
:adapter => 'sqlite3',
|
73
|
-
:index => 0,
|
74
|
-
:file => @config['file'],
|
75
|
-
:path => @config['path'],
|
76
|
-
:encrypt => @config['encrypt'],
|
77
|
-
:keep_backups => @config['keep_backups'],
|
78
|
-
|
79
|
-
:use => :s3,
|
80
|
-
:s3 => {
|
81
|
-
:access_key_id => @config['s3']['access_key_id'],
|
82
|
-
:secret_access_key => @config['s3']['secret_access_key'],
|
83
|
-
:bucket => @config['s3']['bucket']
|
84
|
-
}
|
85
|
-
}).run
|
86
|
-
else
|
87
|
-
@config.each_with_index do |config, index|
|
88
|
-
Backup::Adapter::Sqlite3.new({
|
89
|
-
:adapter => 'sqlite3',
|
90
|
-
:index => index,
|
91
|
-
:file => config['file'],
|
92
|
-
:path => config['path'],
|
93
|
-
:encrypt => config['encrypt'],
|
94
|
-
:keep_backups => config['keep_backups'],
|
95
|
-
|
96
|
-
:use => :s3,
|
97
|
-
:s3 => {
|
98
|
-
:access_key_id => config['s3']['access_key_id'],
|
99
|
-
:secret_access_key => config['s3']['secret_access_key'],
|
100
|
-
:bucket => config['s3']['bucket']
|
101
|
-
}
|
102
|
-
}).run
|
103
|
-
sleep(1)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# => rake backup:s3:assets
|
109
|
-
# Specify which directory (:path) (and all it's underlaying files and folders) you wish to backup.
|
110
|
-
# Specify that you want to use :s3
|
111
|
-
# Fill in your Amazon S3 Account's Credentials (access_key_id, secret_access_key)
|
112
|
-
# Specify which bucket you wish to store your files to.
|
113
|
-
# If you wish to put specific files in subfolders inside the bucket, you may do so by doing something like this:
|
114
|
-
# :bucket => "my_bucket/subfolder1/subfolder2" etc.
|
115
|
-
desc 'Makes a backup from Assets and transfers it to Amazon S3.'
|
116
|
-
task :assets => :s3_config do
|
117
|
-
@config = @config['assets']
|
118
|
-
unless @config.is_a?(Array)
|
119
|
-
Backup::Adapter::Assets.new({
|
120
|
-
:adapter => 'assets',
|
121
|
-
:index => 0,
|
122
|
-
:path => @config['path'],
|
123
|
-
:encrypt => @config['encrypt'],
|
124
|
-
:keep_backups => @config['keep_backups'],
|
125
|
-
|
126
|
-
:use => :s3,
|
127
|
-
:s3 => {
|
128
|
-
:access_key_id => @config['s3']['access_key_id'],
|
129
|
-
:secret_access_key => @config['s3']['secret_access_key'],
|
130
|
-
:bucket => @config['s3']['bucket']
|
131
|
-
}
|
132
|
-
}).run
|
133
|
-
else
|
134
|
-
@config.each_with_index do |config, index|
|
135
|
-
Backup::Adapter::Assets.new({
|
136
|
-
:adapter => 'assets',
|
137
|
-
:index => index,
|
138
|
-
:path => config['path'],
|
139
|
-
:encrypt => config['encrypt'],
|
140
|
-
:keep_backups => config['keep_backups'],
|
141
|
-
|
142
|
-
:use => :s3,
|
143
|
-
:s3 => {
|
144
|
-
:access_key_id => config['s3']['access_key_id'],
|
145
|
-
:secret_access_key => config['s3']['secret_access_key'],
|
146
|
-
:bucket => config['s3']['bucket']
|
147
|
-
}
|
148
|
-
}).run
|
149
|
-
sleep(1)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# => rake backup:s3:custom
|
155
|
-
# This is a more complex implementation of the Backup gem.
|
156
|
-
# Might you be using a database type that is currently not supported, then you can manually create an SQL dump
|
157
|
-
# using the :command attribute. This will take either a single string, or an array of strings, depending on how many
|
158
|
-
# commands you wish to execute.
|
159
|
-
#
|
160
|
-
# Single Command
|
161
|
-
# :command => "my command"
|
162
|
-
# Multiple Commands
|
163
|
-
# :command => ["my command 1", "my command 2", "my command 3"] etc.
|
164
|
-
#
|
165
|
-
# This means you have full control over where the sql dump should be placed. But, depending on your decision, you must
|
166
|
-
# set the correct path to the file(s) (sql dumps) that have been generated.
|
167
|
-
#
|
168
|
-
# Path To File(s) Directory
|
169
|
-
# :path => "#{RAILS_ROOT}/db"
|
170
|
-
#
|
171
|
-
# Finally, you must specify which file(s) should be backed up.
|
172
|
-
# The :file attribute can take either a single string, or an array of strings to add multiple files.
|
173
|
-
#
|
174
|
-
# Select a single file to backup from the :path directory you specified
|
175
|
-
# :file => "foobar1.sql"
|
176
|
-
# Select multiple files to backup from the :path directory you specified
|
177
|
-
# :file => ["foobar1.sql", "foobar2.sql"] etc
|
178
|
-
#
|
179
|
-
# When you specify you would like to backup multiple files, it will automatically archive these as a "tar" for you and then compress it.
|
180
|
-
#
|
181
|
-
# By default, after the backup has been pushed to S3, it will remove the original files (created from your :command attribute)
|
182
|
-
# If you wish to keep these files, then add the following line:
|
183
|
-
# :keep_original_files => true
|
184
|
-
# This is set to 'false' by default, as you most likely don't want to keep these files on your production server.
|
185
|
-
#
|
186
|
-
# Just use the ":use => :s3" as usual to tell it you would like to back up these files using S3.
|
187
|
-
# And then, like in the example below, provide the S3 credentials/details to be able to connect to the server you wish to back these files up to.
|
188
|
-
desc 'Makes a backup from a Custom database and transfers it to Amazon S3.'
|
189
|
-
task :custom => :s3_config do
|
190
|
-
@config = @config['custom']
|
191
|
-
unless @config.is_a?(Array)
|
192
|
-
Backup::Adapter::Custom.new({
|
193
|
-
:adapter => 'custom',
|
194
|
-
:index => 0,
|
195
|
-
:file => @config['file'],
|
196
|
-
:path => @config['path'],
|
197
|
-
:command => @config['command'],
|
198
|
-
:encrypt => @config['encrypt'],
|
199
|
-
:keep_backups => @config['keep_backups'],
|
200
|
-
|
201
|
-
:use => :s3,
|
202
|
-
:s3 => {
|
203
|
-
:access_key_id => @config['s3']['access_key_id'],
|
204
|
-
:secret_access_key => @config['s3']['secret_access_key'],
|
205
|
-
:bucket => @config['s3']['bucket']
|
206
|
-
}
|
207
|
-
}).run
|
208
|
-
else
|
209
|
-
@config.each_with_index do |config, index|
|
210
|
-
Backup::Adapter::Custom.new({
|
211
|
-
:adapter => 'custom',
|
212
|
-
:index => index,
|
213
|
-
:file => config['file'],
|
214
|
-
:path => config['path'],
|
215
|
-
:command => config['command'],
|
216
|
-
:encrypt => config['encrypt'],
|
217
|
-
:keep_backups => config['keep_backups'],
|
218
|
-
|
219
|
-
:use => :s3,
|
220
|
-
:s3 => {
|
221
|
-
:access_key_id => config['s3']['access_key_id'],
|
222
|
-
:secret_access_key => config['s3']['secret_access_key'],
|
223
|
-
:bucket => config['s3']['bucket']
|
224
|
-
}
|
225
|
-
}).run
|
226
|
-
sleep(1)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
# Backup Configuration file for "Amazon S3 Backups"
|
2
|
-
# This file was generated with the Backup Generator
|
3
|
-
#
|
4
|
-
# FOR MORE INFORMATION, VIEW THE WIKI ON GITHUB:
|
5
|
-
# http://wiki.github.com/meskyanichi/backup
|
6
|
-
#
|
7
|
-
# If you wish to make use of the Amazon S3 service to store your
|
8
|
-
# backups, use this configuration file.
|
9
|
-
#
|
10
|
-
# Step by Step
|
11
|
-
#
|
12
|
-
# Step 1
|
13
|
-
# Choose the adapter you would like to use to back up your files
|
14
|
-
# (MySQL, SQLite3, Assets or something Custom)
|
15
|
-
#
|
16
|
-
# Step 2
|
17
|
-
# Fill in the values for the adapter you choose.
|
18
|
-
# You do not need to fill in the values for every adapter,
|
19
|
-
# only the ones you are going to use. The rest you can leave untouched or remove.
|
20
|
-
#
|
21
|
-
# Step 3
|
22
|
-
# Once you've filled in all values, you are ready to execute the rake task that
|
23
|
-
# starts that backup process. Above each Adapter you will see what rake task should
|
24
|
-
# be run to start the backup process for that specific Adapter.
|
25
|
-
#
|
26
|
-
# Step 4
|
27
|
-
# Once set up, you could set these rake tasks up in a cronjob to execute it periodically.
|
28
|
-
# For handling this, I recommend using the javan-whenever gem
|
29
|
-
#
|
30
|
-
# See here: http://github.com/javan/whenever
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
# Global Options
|
35
|
-
#
|
36
|
-
# - encrypt (optional!)
|
37
|
-
#
|
38
|
-
# What "encrypt" does is encrypt your backup with the given password
|
39
|
-
# Example:
|
40
|
-
# encrypt: this_is_my_password
|
41
|
-
#
|
42
|
-
# This will encrypt the backup file with the password: this_is_my_password
|
43
|
-
# NOTE: To "decrypt" an encrypted file later on, use the following command:
|
44
|
-
# openssl enc -des-cbc -d -in encrypted_file -out decrypted_file
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# - keep_backups (optional!)
|
48
|
-
#
|
49
|
-
# what "keep_backups" does is it ensures that there won't be more than the specified
|
50
|
-
# amount of backups present on the storage location (S3 or any remotely accessible server)
|
51
|
-
# Example:
|
52
|
-
# keep_backups: 10
|
53
|
-
#
|
54
|
-
# This will make sure there won't be more than 10 backups on the server at a time.
|
55
|
-
# When the 11th backup is pushed to for example Amazon S3, it will delete the oldest
|
56
|
-
# backup. Why would you want this? To avoid S3 from being expensive and otherwise
|
57
|
-
# to not overload your remote server's harddisk and practically fload it.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
# MySQL Adapter
|
63
|
-
# To run this adapter, execute the following rake task:
|
64
|
-
# rake backup:s3:mysql
|
65
|
-
mysql:
|
66
|
-
mysql_config:
|
67
|
-
user: root
|
68
|
-
password: ''
|
69
|
-
database: foobar
|
70
|
-
s3:
|
71
|
-
access_key_id: my_access_key_id
|
72
|
-
secret_access_key: my_secret_access_key
|
73
|
-
bucket: my_bucket
|
74
|
-
#encrypt: my_secret_password # Uncomment me if you want this functionality
|
75
|
-
#keep_backups: 25 # Uncomment me if you want this functionality
|
76
|
-
|
77
|
-
|
78
|
-
# SQLite3 Adapter
|
79
|
-
# To run this adapter, execute the following rake task:
|
80
|
-
# rake backup:s3:sqlite3
|
81
|
-
sqlite3:
|
82
|
-
file: production.sqlite3
|
83
|
-
path: ':rails_root/db'
|
84
|
-
s3:
|
85
|
-
access_key_id: my_access_key_id
|
86
|
-
secret_access_key: my_secret_access_key
|
87
|
-
bucket: my_bucket
|
88
|
-
#encrypt: my_secret_password # Uncomment me if you want this functionality
|
89
|
-
#keep_backups: 25 # Uncomment me if you want this functionality
|
90
|
-
|
91
|
-
|
92
|
-
# Asset Adapter
|
93
|
-
# To run this adapter, execute the following rake task:
|
94
|
-
# rake backup:s3:assets
|
95
|
-
assets:
|
96
|
-
path: ':rails_root/public/assets'
|
97
|
-
s3:
|
98
|
-
access_key_id: my_access_key_id
|
99
|
-
secret_access_key: my_secret_access_key
|
100
|
-
bucket: my_bucket
|
101
|
-
#encrypt: my_secret_password # Uncomment me if you want this functionality
|
102
|
-
#keep_backups: 25 # Uncomment me if you want this functionality
|
103
|
-
|
104
|
-
# Custom Adapter
|
105
|
-
# To run this adapter, execute the following rake task:
|
106
|
-
# rake backup:s3:custom
|
107
|
-
custom:
|
108
|
-
path: ':rails_root/db'
|
109
|
-
file:
|
110
|
-
- 'foobar1.sql'
|
111
|
-
- 'foobar2.sql'
|
112
|
-
command:
|
113
|
-
- 'mysqldump --quick -u root --password="" foobar > :rails_root/db/foobar1.sql'
|
114
|
-
- 'mysqldump --quick -u root --password="" foobar > :rails_root/db/foobar2.sql'
|
115
|
-
s3:
|
116
|
-
access_key_id: my_access_key_id
|
117
|
-
secret_access_key: my_secret_access_key
|
118
|
-
bucket: my_bucket
|
119
|
-
#encrypt: my_secret_password # Uncomment me if you want this functionality
|
120
|
-
#keep_backups: 25 # Uncomment me if you want this functionality
|
@@ -1,28 +0,0 @@
|
|
1
|
-
namespace :backup do
|
2
|
-
namespace :setup do
|
3
|
-
desc "Automatically sets up Capistrano Structure for you!"
|
4
|
-
task :capistrano => :environment do
|
5
|
-
puts 'Looking for shared path!'
|
6
|
-
if File.directory?("../../shared") then
|
7
|
-
puts 'Found shared path!'
|
8
|
-
puts 'Looking for db folder in shared path!'
|
9
|
-
unless File.directory?("../../shared/db") then
|
10
|
-
puts 'Cound not find db folder in shared path! Creating it now!'
|
11
|
-
%x{ mkdir -p ../../shared/db }
|
12
|
-
else
|
13
|
-
puts 'Found db folder in shared path!'
|
14
|
-
end
|
15
|
-
|
16
|
-
puts 'Looking for backup.sqlite3 in shared/db path!'
|
17
|
-
unless File.exist?("../../shared/db/backup.sqlite3") then
|
18
|
-
puts 'Could not find, creating it now!'
|
19
|
-
%x{ cp #{RAILS_ROOT}/lib/tasks/backup/files/backup.sqlite3 ../../shared/db/backup.sqlite3 }
|
20
|
-
else
|
21
|
-
puts "backup.sqlite3 already exists in the shared/db folder! Skipping backup.sqlite3 creation!"
|
22
|
-
end
|
23
|
-
%x{ ln -nfs #{RAILS_ROOT}/../../shared/db/backup.sqlite3 #{RAILS_ROOT}/db/backup.sqlite3 }
|
24
|
-
puts "Set up a symbolic link to the backup.sqlite3 inside #{RAILS_ROOT}/db/ folder!"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,226 +0,0 @@
|
|
1
|
-
namespace :backup do
|
2
|
-
namespace :ssh do
|
3
|
-
|
4
|
-
# => rake backup:ssh:mysql
|
5
|
-
# Fill in your mysql credentials to allow Backup to create a mysql dump, and which database to make a dump from.
|
6
|
-
# Specify that you want to use :ssh
|
7
|
-
# Specify what user should connect through SSH, to what address (be it IP or an URL) and the absolute path on the backup-server
|
8
|
-
# to where Backup should store the backups.
|
9
|
-
desc 'Makes a backup from a MySQL database and transfers it through SSH (SCP).'
|
10
|
-
task :mysql => :ssh_config do
|
11
|
-
@config = @config['mysql']
|
12
|
-
unless @config.is_a?(Array)
|
13
|
-
Backup::Adapter::Mysql.new({
|
14
|
-
:adapter => 'mysql',
|
15
|
-
:index => 0,
|
16
|
-
:mysql => {
|
17
|
-
:user => @config['mysql_config']['user'],
|
18
|
-
:password => @config['mysql_config']['password'],
|
19
|
-
:database => @config['mysql_config']['database']
|
20
|
-
},
|
21
|
-
|
22
|
-
:encrypt => @config['encrypt'],
|
23
|
-
:keep_backups => @config['keep_backups'],
|
24
|
-
|
25
|
-
:use => :ssh,
|
26
|
-
:ssh => {
|
27
|
-
:user => @config['ssh']['user'],
|
28
|
-
:ip => @config['ssh']['ip'],
|
29
|
-
:path => @config['ssh']['path']
|
30
|
-
}
|
31
|
-
}).run
|
32
|
-
else
|
33
|
-
@config.each_with_index do |config, index|
|
34
|
-
Backup::Adapter::Mysql.new({
|
35
|
-
:adapter => 'mysql',
|
36
|
-
:index => index,
|
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 => :ssh,
|
47
|
-
:ssh => {
|
48
|
-
:user => config['ssh']['user'],
|
49
|
-
:ip => config['ssh']['ip'],
|
50
|
-
:path => config['ssh']['path']
|
51
|
-
}
|
52
|
-
}).run
|
53
|
-
sleep(1)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# => rake backup:ssh:sqlite3
|
59
|
-
# Specify which sqlite3 file you wish to back up. This will generally be "production.sqlite3". (and this is the default, so you can remove the :file attribute if it is)
|
60
|
-
# If your sqlite3 file is not located inside the #{RAILS_ROOT}/db folder, then add a :path => "#{RAILS_ROOT}/path/to/db/folder"
|
61
|
-
# Specify that you want to use :ssh
|
62
|
-
# Specify what user should connect through SSH, to what address (be it IP or an URL) and the absolute path on the backup-server
|
63
|
-
# to where Backup should store the backups.
|
64
|
-
desc 'Makes a backup from a SQLite3 database and transfers it through SSH (SCP).'
|
65
|
-
task :sqlite3 => :ssh_config do
|
66
|
-
@config = @config['sqlite3']
|
67
|
-
unless @config.is_a?(Array)
|
68
|
-
Backup::Adapter::Sqlite3.new({
|
69
|
-
:adapter => 'sqlite3',
|
70
|
-
:index => 0,
|
71
|
-
:file => @config['file'],
|
72
|
-
:path => @config['path'],
|
73
|
-
:encrypt => @config['encrypt'],
|
74
|
-
:keep_backups => @config['keep_backups'],
|
75
|
-
|
76
|
-
:use => :ssh,
|
77
|
-
:ssh => {
|
78
|
-
:user => @config['ssh']['user'],
|
79
|
-
:ip => @config['ssh']['ip'],
|
80
|
-
:path => @config['ssh']['path']
|
81
|
-
}
|
82
|
-
}).run
|
83
|
-
else
|
84
|
-
@config.each_with_index do |config, index|
|
85
|
-
Backup::Adapter::Sqlite3.new({
|
86
|
-
:adapter => 'sqlite3',
|
87
|
-
:index => index,
|
88
|
-
:file => config['file'],
|
89
|
-
:path => config['path'],
|
90
|
-
:encrypt => config['encrypt'],
|
91
|
-
:keep_backups => config['keep_backups'],
|
92
|
-
|
93
|
-
:use => :ssh,
|
94
|
-
:ssh => {
|
95
|
-
:user => config['ssh']['user'],
|
96
|
-
:ip => config['ssh']['ip'],
|
97
|
-
:path => config['ssh']['path']
|
98
|
-
}
|
99
|
-
}).run
|
100
|
-
sleep(1)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# => rake backup:ssh:assets
|
106
|
-
# Specify which directory (:path) (and all it's underlaying files and folders) you wish to backup.
|
107
|
-
# Specify that you want to use :ssh
|
108
|
-
# Specify what user should connect through SSH, to what address (be it IP or an URL) and the absolute path on the backup-server
|
109
|
-
# to where Backup should store the backups.
|
110
|
-
desc 'Makes a backup from Assets and transfers it through SSH (SCP).'
|
111
|
-
task :assets => :ssh_config do
|
112
|
-
@config = @config['assets']
|
113
|
-
unless @config.is_a?(Array)
|
114
|
-
Backup::Adapter::Assets.new({
|
115
|
-
:adapter => 'assets',
|
116
|
-
:index => 0,
|
117
|
-
:path => @config['path'],
|
118
|
-
:encrypt => @config['encrypt'],
|
119
|
-
:keep_backups => @config['keep_backups'],
|
120
|
-
|
121
|
-
:use => :ssh,
|
122
|
-
:ssh => {
|
123
|
-
:user => @config['ssh']['user'],
|
124
|
-
:ip => @config['ssh']['ip'],
|
125
|
-
:path => @config['ssh']['path']
|
126
|
-
}
|
127
|
-
}).run
|
128
|
-
else
|
129
|
-
@config.each_with_index do |config, index|
|
130
|
-
Backup::Adapter::Assets.new({
|
131
|
-
:adapter => 'assets',
|
132
|
-
:index => index,
|
133
|
-
:path => config['path'],
|
134
|
-
:encrypt => config['encrypt'],
|
135
|
-
:keep_backups => config['keep_backups'],
|
136
|
-
|
137
|
-
:use => :ssh,
|
138
|
-
:ssh => {
|
139
|
-
:user => config['ssh']['user'],
|
140
|
-
:ip => config['ssh']['ip'],
|
141
|
-
:path => config['ssh']['path']
|
142
|
-
}
|
143
|
-
}).run
|
144
|
-
sleep(1)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# => rake backup:ssh:custom
|
150
|
-
# This is a more complex implementation of the Backup gem.
|
151
|
-
# Might you be using a database type that is currently not supported, then you can manually create an SQL dump
|
152
|
-
# using the :command attribute. This will take either a single string, or an array of strings, depending on how many
|
153
|
-
# commands you wish to execute.
|
154
|
-
#
|
155
|
-
# Single Command
|
156
|
-
# :command => "my command"
|
157
|
-
# Multiple Commands
|
158
|
-
# :command => ["my command 1", "my command 2", "my command 3"] etc.
|
159
|
-
#
|
160
|
-
# This means you have full control over where the sql dump should be placed. But, depending on your decision, you must
|
161
|
-
# set the correct path to the file(s) (sql dumps) that have been generated.
|
162
|
-
#
|
163
|
-
# Path To File(s) Directory
|
164
|
-
# :path => "#{RAILS_ROOT}/db"
|
165
|
-
#
|
166
|
-
# Finally, you must specify which file(s) should be backed up.
|
167
|
-
# The :file attribute can take either a single string, or an array of strings to add multiple files.
|
168
|
-
#
|
169
|
-
# Select a single file to backup from the :path directory you specified
|
170
|
-
# :file => "foobar1.sql"
|
171
|
-
# Select multiple files to backup from the :path directory you specified
|
172
|
-
# :file => ["foobar1.sql", "foobar2.sql"] etc
|
173
|
-
#
|
174
|
-
# When you specify you would like to backup multiple files, it will automatically archive these as a "tar" for you and then compress it.
|
175
|
-
#
|
176
|
-
# By default, after the backup has been pushed to your backup server using SSH, it will remove the original files (created from your :command attribute)
|
177
|
-
# If you wish to keep these files, then add the following line:
|
178
|
-
# :keep_original_files => true
|
179
|
-
# This is set to 'false' by default, as you most likely don't want to keep these files on your production server.
|
180
|
-
#
|
181
|
-
# Just use the ":use => :ssh" as usual to tell it you would like to back up these files using SSH.
|
182
|
-
# And then, like in the example below, provide the SSH details to be able to connect to the server you wish to back these files up to.
|
183
|
-
desc 'Makes a backup from a Custom database and transfers it through SSH (SCP).'
|
184
|
-
task :custom => :ssh_config do
|
185
|
-
@config = @config['custom']
|
186
|
-
unless @config.is_a?(Array)
|
187
|
-
Backup::Adapter::Custom.new({
|
188
|
-
:adapter => 'custom',
|
189
|
-
:index => 0,
|
190
|
-
:file => @config['file'],
|
191
|
-
:path => @config['path'],
|
192
|
-
:command => @config['command'],
|
193
|
-
:encrypt => @config['encrypt'],
|
194
|
-
:keep_backups => @config['keep_backups'],
|
195
|
-
|
196
|
-
:use => :ssh,
|
197
|
-
:ssh => {
|
198
|
-
:user => @config['ssh']['user'],
|
199
|
-
:ip => @config['ssh']['ip'],
|
200
|
-
:path => @config['ssh']['path']
|
201
|
-
}
|
202
|
-
}).run
|
203
|
-
else
|
204
|
-
@config.each_with_index do |config, index|
|
205
|
-
Backup::Adapter::Custom.new({
|
206
|
-
:adapter => 'custom',
|
207
|
-
:index => index,
|
208
|
-
:file => config['file'],
|
209
|
-
:path => config['path'],
|
210
|
-
:command => config['command'],
|
211
|
-
:encrypt => config['encrypt'],
|
212
|
-
:keep_backups => config['keep_backups'],
|
213
|
-
|
214
|
-
:use => :ssh,
|
215
|
-
:ssh => {
|
216
|
-
:user => config['ssh']['user'],
|
217
|
-
:ip => config['ssh']['ip'],
|
218
|
-
:path => config['ssh']['path']
|
219
|
-
}
|
220
|
-
}).run
|
221
|
-
sleep(1)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|