Created
May 6, 2009 14:51
-
-
Save r38y/107545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before "deploy", "db:dump" | |
before "deploy:migrations", "db:dump" | |
namespace :db do | |
task :backup_name, :roles => :db, :only => { :primary => true } do | |
now = Time.now | |
run "mkdir -p #{shared_path}/db_backups" | |
backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-') | |
set :backup_file, "#{shared_path}/db_backups/kotter-snapshot-#{backup_time}.sql" | |
end | |
desc "Backup your MySQL or PostgreSQL database to shared_path+/db_backups" | |
task :dump, :roles => :db, :only => {:primary => true} do | |
backup_name | |
run("cat #{shared_path}/config/database.yml") { |channel, stream, data| @environment_info = YAML.load(data)[rails_env] } | |
if @environment_info['adapter'] == 'mysql' | |
dbhost = @environment_info['host'] | |
dbhost = environment_dbhost.sub('-master', '') + '-replica' if dbhost != 'localhost' # added for Solo offering, which uses localhost | |
run "mysqldump --add-drop-table -u #{dbuser} -h #{dbhost} -p #{environment_database} | bzip2 -c > #{backup_file}.bz2" do |ch, stream, out | | |
ch.send_data "#{dbpass}\n" if out=~ /^Enter password:/ | |
end | |
else | |
run "pg_dump -W -c -U #{dbuser} -h #{environment_dbhost} #{environment_database} | bzip2 -c > #{backup_file}.bz2" do |ch, stream, out | | |
ch.send_data "#{dbpass}\n" if out=~ /^Password:/ | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment