是否有用于备份数据库中数据的rake任务?
我已经备份了我的架构,但我想备份数据.这是一个小型的MySQL数据库.
以下脚本是从eycap获取的简化版本,特别是来自此文件.
set :dbuser "user" set :dbhost "host" set :database "db" namespace :db do desc "Get the database password from user" task :get_password do set(:dbpass) do Capistrano::CLI.ui.ask "Enter mysql password: " end end task :backup_name, :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/#{database}-snapshot-#{backup_time}.sql" end desc "Dump database to backup file" task :dump, :roles => :db, :only => {:primary => true} do backup_name run "mysqldump --add-drop-table -u #{dbuser} -h #{dbhost} -p#{dbpass} #{database} | bzip2 -c > #{backup_file}.bz2" end end
编辑:是的,我想我错过了你正在寻找一个rake任务而不是一个capistrano任务的观点,但我手头没有一个rake,对不起.