Created
September 19, 2009 15:12
-
-
Save mrchrisadams/189503 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
require 'yaml' | |
desc "Copy the remote production database to the local development box" | |
task :backup do | |
filename = "#{application}.dump.#{Time.now.to_i}.sql.bz2" | |
file = "/tmp/#{filename}" | |
on_rollback { delete file } | |
db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), 'database.yml'))).result)['production'] | |
run "mysqldump -u #{db['username']} --password=#{db['password']} #{db['database']} | bzip2 -c > #{file}" do |ch, stream, out| | |
puts out | |
end | |
`mkdir -p #{File.dirname(__FILE__)}/../backups/` | |
get file, "backups/#{filename}" | |
run "rm #{file}" | |
end | |
desc "Copy the latest backup to the local development database" | |
task :import_backup do | |
filename = `ls -tr backups | tail -n 1`.chomp | |
if filename.empty? | |
logger.important "No backups found" | |
else | |
ddb = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), 'database.yml'))).result)['development'] | |
logger.debug "Loading backups/#{filename} into local development database" | |
`bzip2 -cd backups/#{filename} | mysql -u #{ddb['username']} --password=#{ddb['password']} #{ddb['database']}` | |
logger.debug "command finished" | |
end | |
end | |
desc "Backup the remote production database and import it to the local development database" | |
task :backup_and_import do | |
backup | |
import_backup | |
end |
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
### where would I pass in the environment variables to let rake to it's thing here? | |
rake aborted! | |
undefined local variable or method `application' for main:Object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment