From 84ee59c6137ebe0e870aa47351bc06708b1260a8 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 9 Aug 2013 13:56:47 -0600 Subject: extract backup_path and add hours and minute to backup file timestamp --- config/recipes/postgresql.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/recipes/postgresql.rb b/config/recipes/postgresql.rb index 6e80ebb..ee19b02 100644 --- a/config/recipes/postgresql.rb +++ b/config/recipes/postgresql.rb @@ -35,11 +35,12 @@ namespace :postgresql do desc "Backup the database and copy it locally" task :backup, roles: :db, only: {primary: true} do - filename = "#{rails_env}-#{Time.now.strftime('%Y-%m-%d')}.sql" + filename = "#{rails_env}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.sql" + backup_path = "#{shared_path}/backups" run "mkdir -p #{shared_path}/backups" - run "pg_dump --clean -h #{postgresql_host} -U #{postgresql_user} -W #{postgresql_database} > #{shared_path}/backups/#{filename}" do |channel, stream, data| + run "pg_dump --clean -h #{postgresql_host} -U #{postgresql_user} -W #{postgresql_database} > #{backup_path}/#{filename}" do |channel, stream, data| channel.send_data "#{postgresql_password}\n" end - download("#{shared_path}/backups/#{filename}", "tmp/#{filename}", :via => :scp) + download("#{backup_path}/#{filename}", "tmp/#{filename}", :via => :scp) end end -- cgit v1.2.3