Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Created September 24, 2010 18:22
Show Gist options
  • Save ivanoats/595791 to your computer and use it in GitHub Desktop.
Save ivanoats/595791 to your computer and use it in GitHub Desktop.
require 'rake'
namespace :db do
desc "Dump the current database to a MySQL file"
task :dump_production do
File.open("db-backups/production_data-#{Time.now.strftime("%Y-%m-%d-%H%m")}.sql","w+") do |f|
f << 'mysqldump -uUSER_NAME -p -hMYSQL_HOST DB_NAME'
end
end #task database_dump
desc "Dump the local db to a MySQL file"
task :dump_dev do
File.open("db-backups/development_data-#{Time.now.strftime("%Y-%m-%d-%H%m")}.sql","w+") do |f|
f << 'mysqldump -uLOCAL_DB_USER LOCAL_DB_NAME'
end
end
desc "Import the latest production to dev local"
task :import_latest do
# figure out latest .sql file
Dir.chdir("db-backups")
latest = Dir.glob("*.sql").reduce do |memo,file|
File.mtime(memo) > File.mtime(file) ? memo : file
end
# import it into MySQL
puts latest
end
end #namespace db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment