From fc961ccd9c2d3d78eb0ac8b13c0bb3bd29bd95f4 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 9 Aug 2013 14:05:30 -0600 Subject: use a .dump file for db backups and create rake task --- lib/tasks/db.rake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/tasks/db.rake (limited to 'lib/tasks/db.rake') diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake new file mode 100644 index 0000000..20e7782 --- /dev/null +++ b/lib/tasks/db.rake @@ -0,0 +1,16 @@ +require "yaml" + +namespace :db do + desc 'backup database (rake db:backup["production"]' + task :backup, :env do |key, value| + environment = value[:env] || 'development' + sh "cap #{environment} postgresql:backup" + end + + task :restore, :env do |key, value| + environment = value[:env] || 'development' + all_configuration = YAML.load_file(File.join(File.dirname(__FILE__), '../../config/database.yml' )) + config = all_configuration[environment] + sh "pg_restore --verbose --clean --no-acl --no-owner -h #{config["host"]} -U #{config["username"]} -d #{config["database"]} tmp/database.dump" + end +end -- cgit v1.2.3 From a90d09be8a682523e762bda68a3b69bae2bb2864 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 9 Aug 2013 14:26:47 -0600 Subject: default to backing up the qa environment --- lib/tasks/db.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/tasks/db.rake') diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 20e7782..6bb4bcb 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -3,7 +3,7 @@ require "yaml" namespace :db do desc 'backup database (rake db:backup["production"]' task :backup, :env do |key, value| - environment = value[:env] || 'development' + environment = value[:env] || 'qa' sh "cap #{environment} postgresql:backup" end -- cgit v1.2.3 From 8eee6727265617955a1839ef2f8c69d9fe75db36 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 9 Aug 2013 14:29:23 -0600 Subject: add descriptions to the database backup/restore tasks --- config/deploy.rb | 2 +- config/recipes/server.rb | 4 ---- config/recipes/utility.rb | 4 ++++ lib/tasks/db.rake | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 config/recipes/server.rb create mode 100644 config/recipes/utility.rb (limited to 'lib/tasks/db.rake') diff --git a/config/deploy.rb b/config/deploy.rb index 81b74a3..d6a52e2 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -10,7 +10,7 @@ load "config/recipes/rbenv" load "config/recipes/newrelic" load "config/recipes/monit" # general tasks -load "config/recipes/server" +load "config/recipes/utility" set :application, "parley" set :user, "deployer" diff --git a/config/recipes/server.rb b/config/recipes/server.rb deleted file mode 100644 index 6d71371..0000000 --- a/config/recipes/server.rb +++ /dev/null @@ -1,4 +0,0 @@ -desc "tail the logs on an app server (cap qa logs)" -task :logs, roles: :app do - stream "tail -f #{shared_path}/log/#{rails_env}.log" -end diff --git a/config/recipes/utility.rb b/config/recipes/utility.rb new file mode 100644 index 0000000..6d71371 --- /dev/null +++ b/config/recipes/utility.rb @@ -0,0 +1,4 @@ +desc "tail the logs on an app server (cap qa logs)" +task :logs, roles: :app do + stream "tail -f #{shared_path}/log/#{rails_env}.log" +end diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 6bb4bcb..38fb2c5 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,12 +1,13 @@ require "yaml" namespace :db do - desc 'backup database (rake db:backup["production"]' + desc 'backup database (rake db:backup["prod"])' task :backup, :env do |key, value| environment = value[:env] || 'qa' sh "cap #{environment} postgresql:backup" end + desc 'restore database to local' task :restore, :env do |key, value| environment = value[:env] || 'development' all_configuration = YAML.load_file(File.join(File.dirname(__FILE__), '../../config/database.yml' )) -- cgit v1.2.3