266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
# File 'lib/rubber/commands/util.rb', line 266
def execute
signal_usage_error "DBUSER, DBHOST are required" unless dbuser && dbhost
file = filename
user = dbuser
pass = dbpass
pass = nil if pass && pass.strip.size == 0
host = dbhost
name = dbname
raise "No db_restore_cmd defined in rubber.yml" unless Rubber.config.db_restore_cmd
db_restore_cmd = Rubber.config.db_restore_cmd.gsub(/%([^%]+)%/, '#{\1}')
db_restore_cmd = eval('%Q{' + db_restore_cmd + '}')
backup_bucket = Rubber.cloud.env.backup_bucket
raise "No backup_bucket defined in rubber.yml" unless backup_bucket
key = nil
cloud_prefix = "db/"
if filename
key = "#{cloud_prefix}#{filename}"
else
puts "trying to fetch last modified cloud backup"
max = nil
Rubber.cloud.storage(backup_bucket).walk_tree(cloud_prefix) do |f|
if f.key =~ /#{Rubber.env}_dump_/
max = f if max.nil? || f.last_modified > max.last_modified
end
end
key = max.key if max
end
raise "could not access backup file from cloud" unless key
puts "piping restore data from #{backup_bucket}:#{key} to command [#{db_restore_cmd}]"
IO.popen(db_restore_cmd, 'wb') do |p|
Rubber.cloud.storage(backup_bucket).fetch(key) do |chunk|
p.write chunk
end
end
end
|