From c37b592cd9155d6b432f8948a90ac03d0c9e89f8 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Thu, 18 Sep 2014 01:08:09 +0300 Subject: [PATCH] Add a rake task for backing up the DB --- Gemfile | 2 +- lib/tasks/backup.rake | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/backup.rake diff --git a/Gemfile b/Gemfile index 86749eb..23b6bf1 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake new file mode 100644 index 0000000..2e67d87 --- /dev/null +++ b/lib/tasks/backup.rake @@ -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