# What happens when truncating file?

**URL:** <https://discuss.elastic.co/t/what-happens-when-truncating-file/150668>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [October 2, 2018, 9:05am UTC](https://discuss.elastic.co/t/what-happens-when-truncating-file/150668 "2018-10-02T09:05:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iqjumps](https://avatars.discourse-cdn.com/v4/letter/i/74df32/32.png) [@iqjumps](https://discuss.elastic.co/u/iqjumps)\
**Post date:** [October 2, 2018, 9:05am UTC](https://discuss.elastic.co/t/what-happens-when-truncating-file/150668/1 "2018-10-02T09:05:11Z")

</div>

I use logrotate utility and it executes ftruncate(fdcurr, 0) in copytruncate mode  
When it truncates file which Filebeat was reading, Will Filebeat's offset reset to zero or throw error?

Thanks

---

<div class="post-metadata">

**Author:** ![kvch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvch/32/72058_2.png) [@kvch](https://discuss.elastic.co/u/kvch)\
**Post date:** [October 2, 2018, 10:13am UTC](https://discuss.elastic.co/t/what-happens-when-truncating-file/150668/2 "2018-10-02T10:13:31Z")

</div>

It will resume to read the file from the beginning. It also emits the following message: `"File was truncated. Begin reading file from offset 0"`.

---

<div class="post-metadata">

**Author:** ![iqjumps](https://avatars.discourse-cdn.com/v4/letter/i/74df32/32.png) [@iqjumps](https://discuss.elastic.co/u/iqjumps)\
**Post date:** [October 4, 2018, 1:55am UTC](https://discuss.elastic.co/t/what-happens-when-truncating-file/150668/3 "2018-10-04T01:55:21Z")

</div>

Looks good. Thanks a lot

---

<div class="post-metadata">

**Author:** ![kvch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvch/32/72058_2.png) [@kvch](https://discuss.elastic.co/u/kvch)\
**Post date:** [October 4, 2018, 9:12am UTC](https://discuss.elastic.co/t/what-happens-when-truncating-file/150668/4 "2018-10-04T09:12:43Z")

</div>

But please note, if Filebeat hasn't finished processing the file and logrotate truncates the file, it can lead to log loss.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 1, 2018, 9:12am UTC](https://discuss.elastic.co/t/what-happens-when-truncating-file/150668/5 "2018-11-01T09:12:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
