Created
September 24, 2010 18:22
-
-
Save ivanoats/595791 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 '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