clarion/lib/tasks/backup.rake

15 lines
702 B
Ruby
Raw Normal View History

2014-09-18 01:08:09 +03:00
# Copyright Dimitar Dimitrov, 2011
desc "Generates an SQL dump of the production database in the destination path provided as an argument."
task :backup, [:destination] => :environment do |t, args|
conf = ActiveRecord::Base.connection.instance_variable_get :@config
cmd = "PGPASSWORD=#{conf[:password]} pg_dump -U #{conf[:username]} --inserts #{conf[:database]} -p #{conf[:port]} -h #{conf[:host]} > #{args.destination}"
silent = Rake.application.options.silent
puts "Backing up '#{conf[:database]}' into: #{args.destination}" unless silent
if system(cmd)
2019-04-28 21:10:54 +03:00
puts "Backup completed." unless silent
2014-09-18 01:08:09 +03:00
else
puts "Backup failed!\nCommand exit status: #{$?}\nCommand was: #{cmd}"
end
end