diff --git a/lib/fluent/plugin/buf_file.rb b/lib/fluent/plugin/buf_file.rb index d7e83c58bc..4172909509 100644 --- a/lib/fluent/plugin/buf_file.rb +++ b/lib/fluent/plugin/buf_file.rb @@ -197,10 +197,6 @@ def generate_chunk(metadata) def handle_broken_files(path, mode, e) log.error "found broken chunk file during resume.", :path => path, :mode => mode, :err_msg => e.message unique_id = Fluent::Plugin::Buffer::FileChunk.unique_id_from_path(path) - if @disable_chunk_backup - log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away" - return - end backup(unique_id) { |f| File.open(path, 'rb') { |chunk| chunk.set_encoding(Encoding::ASCII_8BIT) @@ -212,6 +208,7 @@ def handle_broken_files(path, mode, e) rescue => error log.error "backup failed. Delete corresponding files.", :err_msg => error.message ensure + log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away." if @disable_chunk_backup File.unlink(path, path + '.meta') rescue nil end diff --git a/lib/fluent/plugin/buf_file_single.rb b/lib/fluent/plugin/buf_file_single.rb index c798a294a0..f11c5df7e7 100644 --- a/lib/fluent/plugin/buf_file_single.rb +++ b/lib/fluent/plugin/buf_file_single.rb @@ -209,10 +209,6 @@ def generate_chunk(metadata) def handle_broken_files(path, mode, e) log.error "found broken chunk file during resume.", :path => path, :mode => mode, :err_msg => e.message unique_id, _ = Fluent::Plugin::Buffer::FileSingleChunk.unique_id_and_key_from_path(path) - if @disable_chunk_backup - log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away" - return - end backup(unique_id) { |f| File.open(path, 'rb') { |chunk| chunk.set_encoding(Encoding::ASCII_8BIT) @@ -224,6 +220,7 @@ def handle_broken_files(path, mode, e) rescue => error log.error "backup failed. Delete corresponding files.", :err_msg => error.message ensure + log.warn "disable_chunk_backup is true. #{dump_unique_id_hex(unique_id)} chunk is thrown away." if @disable_chunk_backup File.unlink(path) rescue nil end diff --git a/lib/fluent/plugin/buffer.rb b/lib/fluent/plugin/buffer.rb index 6f8ddcfa2c..d04ae08296 100644 --- a/lib/fluent/plugin/buffer.rb +++ b/lib/fluent/plugin/buffer.rb @@ -908,6 +908,12 @@ def statistics def backup(chunk_unique_id) unique_id = dump_unique_id_hex(chunk_unique_id) + + if @disable_chunk_backup + log.warn "disable_chunk_backup is true. #{unique_id} chunk is not backed up." + return + end + safe_owner_id = owner.plugin_id.gsub(/[ "\/\\:;|*<>?]/, '_') backup_base_dir = system_config.root_dir || DEFAULT_BACKUP_DIR backup_file = File.join(backup_base_dir, 'backup', "worker#{fluentd_worker_id}", safe_owner_id, "#{unique_id}.log")