Add a rake task for backing up the DB

This commit is contained in:
Petko Bordjukov 2014-09-18 01:08:09 +03:00
parent 24ddcaba3a
commit c37b592cd9
2 changed files with 15 additions and 1 deletions

View File

@ -41,7 +41,7 @@ gem 'bootstrap-sass'
gem 'bootstrap-sass-extras'
gem 'bootswatch-rails'
gem 'autoprefixer-rails'
gem "font-awesome-rails"
gem 'font-awesome-rails'
group :development do
gem 'spring'

14
lib/tasks/backup.rake Normal file
View File

@ -0,0 +1,14 @@
# 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)
puts 'Backup completed.' unless silent
else
puts "Backup failed!\nCommand exit status: #{$?}\nCommand was: #{cmd}"
end
end