I wrote a rake task to delete data from main table and dumping it another table and also creating sql file and deleting data from main table.
All works except data is not pushed into .sql file, it just has the structure of the table. I don't know were I am going wrong. Any suggestions or help on this. Thanks in advance
namespace :db do
require 'json'
desc "Add two days back data to drls_wk12 and delete from drls"
task :drl_2days_task => :environment do
ActiveRecord::Base.transaction do
begin
back_date = (Date.today - 4).strftime("%Y-%m-%d")
output_file = File.join("/root/drl_backups/", "#{back_date}.sql")
#ActiveRecord::Base.connection.execute("TRUNCATE TABLE drls_wk12")
ActiveRecord::Base.connection.execute("insert into drls_wk12 select * from drls where day = '#{back_date}'")
system("/usr/bin/env mysqldump -u root test drls --where='day=#{back_date}' > #{output_file}")
ActiveRecord::Base.connection.execute("DELETE FROM drls WHERE day = '#{back_date}'")
rescue Exception => e
ActiveRecord::Rollback
puts "errors #{e.message}"
#logger.warn("errors #{e.message}")
end
end
end
end
Aucun commentaire:
Enregistrer un commentaire