diff options
Diffstat (limited to 'config/recipes')
| -rw-r--r-- | config/recipes/postgresql.rb | 11 | ||||
| -rw-r--r-- | config/recipes/utility.rb | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/config/recipes/postgresql.rb b/config/recipes/postgresql.rb index 63fa23b..8788c4b 100644 --- a/config/recipes/postgresql.rb +++ b/config/recipes/postgresql.rb @@ -32,4 +32,15 @@ namespace :postgresql do run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" end after "deploy:finalize_update", "postgresql:symlink" + + 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-%H-%M')}.dump" + backup_path = "#{shared_path}/backups" + run "mkdir -p #{shared_path}/backups" + + run "PGPASSWORD='#{postgresql_password}' pg_dump -Fc --no-acl --no-owner -h #{postgresql_host} -U #{postgresql_user} #{postgresql_database} > #{backup_path}/#{filename}" + download("#{backup_path}/#{filename}", "tmp/#{filename}", :via => :scp) + run_locally "cd tmp; rm database.dump; ln -s #{filename} database.dump" + end 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 |
