From db29428a262612f75768cb24e02896ea7bc72a75 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sun, 7 Sep 2014 09:00:29 -0600 Subject: update database backup task to sync to s3 as well. --- lib/capistrano/tasks/db.rake | 16 ++++++++++++++++ lib/capistrano/tasks/postgresql.rake | 15 --------------- 2 files changed, 16 insertions(+), 15 deletions(-) create mode 100644 lib/capistrano/tasks/db.rake delete mode 100644 lib/capistrano/tasks/postgresql.rake (limited to 'lib') diff --git a/lib/capistrano/tasks/db.rake b/lib/capistrano/tasks/db.rake new file mode 100644 index 00000000..61c80a69 --- /dev/null +++ b/lib/capistrano/tasks/db.rake @@ -0,0 +1,16 @@ +set(:postgresql_host, "localhost") + +namespace :db do + desc "Backup the database and copy it locally" + task :backup do + filename = "#{fetch(:rails_env)}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump" + backup_path = "#{shared_path}/backups" + ask(:postgresql_password, "default") + on roles(:db) do + execute "mkdir -p #{shared_path}/backups" + execute "PGPASSWORD='#{fetch(:postgresql_password)}' pg_dump -Fc --no-acl --no-owner -h #{fetch(:postgresql_host)} -U deployer cakeside > #{backup_path}/#{filename}" + download!("#{backup_path}/#{filename}", "db/backups/", :via => :scp) + execute "s3cmd sync #{shared_path}/backups/*.dump s3://cakeside-logs/#{fetch(:rails_env)}/pg/" + end + end +end diff --git a/lib/capistrano/tasks/postgresql.rake b/lib/capistrano/tasks/postgresql.rake deleted file mode 100644 index 09257e28..00000000 --- a/lib/capistrano/tasks/postgresql.rake +++ /dev/null @@ -1,15 +0,0 @@ -set(:postgresql_host, "localhost") - -namespace :postgresql do - desc "Backup the database and copy it locally" - task :backup do - filename = "#{fetch(:rails_env)}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump" - backup_path = "#{shared_path}/backups" - ask(:postgresql_password, "default") - on roles(:db) do - execute "mkdir -p #{shared_path}/backups" - execute "PGPASSWORD='#{fetch(:postgresql_password)}' pg_dump -Fc --no-acl --no-owner -h #{fetch(:postgresql_host)} -U deployer cakeside > #{backup_path}/#{filename}" - download!("#{backup_path}/#{filename}", "db/backups/", :via => :scp) - end - end -end -- cgit v1.2.3