rake db:dump で invalid byte sequence in UTF-8 エラーが出る

症状

rake db:dump RAILS_ENV=production --trace
** Invoke db:dump (first_time)
** Invoke db:schema:dump (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:schema:dump
** Invoke db:data:dump (first_time)
** Invoke environment
** Execute db:data:dump
invalid byte sequence in UTF-8
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:225:in `count'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:225:in `binary?'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:234:in `visit_String'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:103:in `accept'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `block in visit_Array'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `each'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `visit_Array'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:103:in `accept'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `block in visit_Array'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `each'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `visit_Array'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:103:in `accept'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `block in visit_Array'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `each'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:313:in `visit_Array'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:103:in `accept'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:67:in `push'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych.rb:242:in `dump'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/psych/core_ext.rb:14:in `psych_to_yaml'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/yaml_db.rb:26:in `chunk_records'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/yaml_db.rb:48:in `block in dump_table_records'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:190:in `block in each_table_page'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:186:in `each'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:186:in `each_table_page'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/yaml_db.rb:46:in `dump_table_records'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:171:in `dump_table'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:151:in `block in dump'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:149:in `each'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:149:in `dump'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb:14:in `dump'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/tasks/yaml_db_tasks.rake:21:in `block (3 levels) in <top (required)>'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:197:in `block in invoke_prerequisites'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:195:in `each'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:195:in `invoke_prerequisites'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:174:in `block in invoke_with_call_chain'
/home/redmine/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/bin/rake:19:in `load'
/home/redmine/.rvm/gems/ruby-1.9.3-p448@global/bin/rake:19:in `<main>'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `eval'
/home/redmine/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:dump => db:data:dump

 

対処

    DBに不正な文字が入っているために起きている場合がある。
      
    1. 不正な文字が入っているテーブルを特定するため、デバック文字を入れる
 vi /home/redmine/.rvm/gems/ruby-1.9.3-p448/gems/yaml_db-0.2.3/lib/serialization_helper.rb
164行目あたりの def self.dump_table(io, table)にて
print '<foo '
print table
print ' foo>
を挿入する。
        2.  rake db:dump RAILS_ENV=production を実行する。
        3. エラーが起きているテーブルが分かったら、テスト用DBでリストアしたデータを
           使ってトライ&エラーで不正なレコードを特定し、修正する。


コメント

このブログの人気の投稿

pip install mojimoji failed

Windows Server 2008 R2 & PHP 5.6(64bit)

rake db:migrate RAILS_ENV=production にて uninitialized constant Backlogs::IssueQueryPatch::RbRelease のエラーが出る