Logrotate in linux to handle log data loss

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












We are using linux logrotate for rotating our log files,



Example :



/location/tomcat/logs/* /location/jboss/log/* 
copytruncate
daily
rotate 10
compress
size 20M
olddir rotated
create 0644 test test



As per the copy truncate definition given in LINUX,



copytruncate
Truncate the original log file in place after creating a copy,
instead of moving the old log file and optionally creating a new
one, It can be used when some program can not be told to close
its logfile and thus might continue writing (appending) to the
previous log file forever. Note that there is a very small time
slice between copying the file and truncating it, so some log-
ging data might be lost. When this option is used, the create
option will have no effect, as the old log file stays in place.


So there will be a data loss in log file during rotate process. I noticed around 5 to 20 seconds of log loss, Is there a way / configuration to do the same process without data loss?










share|improve this question



























    up vote
    2
    down vote

    favorite
    1












    We are using linux logrotate for rotating our log files,



    Example :



    /location/tomcat/logs/* /location/jboss/log/* 
    copytruncate
    daily
    rotate 10
    compress
    size 20M
    olddir rotated
    create 0644 test test



    As per the copy truncate definition given in LINUX,



    copytruncate
    Truncate the original log file in place after creating a copy,
    instead of moving the old log file and optionally creating a new
    one, It can be used when some program can not be told to close
    its logfile and thus might continue writing (appending) to the
    previous log file forever. Note that there is a very small time
    slice between copying the file and truncating it, so some log-
    ging data might be lost. When this option is used, the create
    option will have no effect, as the old log file stays in place.


    So there will be a data loss in log file during rotate process. I noticed around 5 to 20 seconds of log loss, Is there a way / configuration to do the same process without data loss?










    share|improve this question

























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      We are using linux logrotate for rotating our log files,



      Example :



      /location/tomcat/logs/* /location/jboss/log/* 
      copytruncate
      daily
      rotate 10
      compress
      size 20M
      olddir rotated
      create 0644 test test



      As per the copy truncate definition given in LINUX,



      copytruncate
      Truncate the original log file in place after creating a copy,
      instead of moving the old log file and optionally creating a new
      one, It can be used when some program can not be told to close
      its logfile and thus might continue writing (appending) to the
      previous log file forever. Note that there is a very small time
      slice between copying the file and truncating it, so some log-
      ging data might be lost. When this option is used, the create
      option will have no effect, as the old log file stays in place.


      So there will be a data loss in log file during rotate process. I noticed around 5 to 20 seconds of log loss, Is there a way / configuration to do the same process without data loss?










      share|improve this question















      We are using linux logrotate for rotating our log files,



      Example :



      /location/tomcat/logs/* /location/jboss/log/* 
      copytruncate
      daily
      rotate 10
      compress
      size 20M
      olddir rotated
      create 0644 test test



      As per the copy truncate definition given in LINUX,



      copytruncate
      Truncate the original log file in place after creating a copy,
      instead of moving the old log file and optionally creating a new
      one, It can be used when some program can not be told to close
      its logfile and thus might continue writing (appending) to the
      previous log file forever. Note that there is a very small time
      slice between copying the file and truncating it, so some log-
      ging data might be lost. When this option is used, the create
      option will have no effect, as the old log file stays in place.


      So there will be a data loss in log file during rotate process. I noticed around 5 to 20 seconds of log loss, Is there a way / configuration to do the same process without data loss?







      logs logrotate






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 '17 at 13:18









      John

      173




      173










      asked Mar 6 '17 at 12:16









      user219407

      111




      111




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote













          I know that in syslog-ng, you can set the output filename to use variables, including things like the date, so it would automatically start writing to a new file at 12:00am on the new day, with zero loss.



          It requires changing your syslog program to syslog-ng, though. But the flexibility sounds like exactly what you need.






          share|improve this answer



























            up vote
            0
            down vote













            You could move from logfile logging and rotating with logrotate to journald logging using systemd-cat -t indentifier cmdline. Setup log/entry sizes in /etc/systemd/journald.conf or use journalctl --vacuum-size=, --vacuum-time=, --vacuum-files=



            Another way is to logrotate once a day by using the prerotate/postrotate feature to stop the servers, rotate the log and start the servers again. The logrotation time is depending on your systemd logrotate.timer or (ana)cron job, which could be timed to 4am or whenever is low to zero traffic.



            prerotate
            # stop jboss/tomcat server
            endscript

            daily
            rotate 10
            compress
            size 20M

            postrotate
            #start servers
            endscript





            share|improve this answer




















            • I cannot stop the server, my need is while logrotate is doing truncate I should not loose the data, Is there a way for it? Can u suggest me any configuration? @Michael D
              – Harry
              Mar 6 '17 at 15:10











            • is using journald an option? Read this loggly.com/blog/why-journald
              – Michael D.
              Mar 6 '17 at 15:22

















            up vote
            0
            down vote













            This is how I do it for Catalina logs:



            /var/log/tomcat/catalina.out xargs kill -9
            cat /var/log/tomcat/tmp.log >> /var/log/tomcat/catalina.out
            rm /var/log/tomcat/tmp.log -f
            endscript



            You may optionally specify -s with tail to decrease refresh interval of tail command itself. And because you use -c option, it's fast.






            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f349471%2flogrotate-in-linux-to-handle-log-data-loss%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote













              I know that in syslog-ng, you can set the output filename to use variables, including things like the date, so it would automatically start writing to a new file at 12:00am on the new day, with zero loss.



              It requires changing your syslog program to syslog-ng, though. But the flexibility sounds like exactly what you need.






              share|improve this answer
























                up vote
                1
                down vote













                I know that in syslog-ng, you can set the output filename to use variables, including things like the date, so it would automatically start writing to a new file at 12:00am on the new day, with zero loss.



                It requires changing your syslog program to syslog-ng, though. But the flexibility sounds like exactly what you need.






                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  I know that in syslog-ng, you can set the output filename to use variables, including things like the date, so it would automatically start writing to a new file at 12:00am on the new day, with zero loss.



                  It requires changing your syslog program to syslog-ng, though. But the flexibility sounds like exactly what you need.






                  share|improve this answer












                  I know that in syslog-ng, you can set the output filename to use variables, including things like the date, so it would automatically start writing to a new file at 12:00am on the new day, with zero loss.



                  It requires changing your syslog program to syslog-ng, though. But the flexibility sounds like exactly what you need.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 6 '17 at 19:28









                  Aakin

                  112




                  112






















                      up vote
                      0
                      down vote













                      You could move from logfile logging and rotating with logrotate to journald logging using systemd-cat -t indentifier cmdline. Setup log/entry sizes in /etc/systemd/journald.conf or use journalctl --vacuum-size=, --vacuum-time=, --vacuum-files=



                      Another way is to logrotate once a day by using the prerotate/postrotate feature to stop the servers, rotate the log and start the servers again. The logrotation time is depending on your systemd logrotate.timer or (ana)cron job, which could be timed to 4am or whenever is low to zero traffic.



                      prerotate
                      # stop jboss/tomcat server
                      endscript

                      daily
                      rotate 10
                      compress
                      size 20M

                      postrotate
                      #start servers
                      endscript





                      share|improve this answer




















                      • I cannot stop the server, my need is while logrotate is doing truncate I should not loose the data, Is there a way for it? Can u suggest me any configuration? @Michael D
                        – Harry
                        Mar 6 '17 at 15:10











                      • is using journald an option? Read this loggly.com/blog/why-journald
                        – Michael D.
                        Mar 6 '17 at 15:22














                      up vote
                      0
                      down vote













                      You could move from logfile logging and rotating with logrotate to journald logging using systemd-cat -t indentifier cmdline. Setup log/entry sizes in /etc/systemd/journald.conf or use journalctl --vacuum-size=, --vacuum-time=, --vacuum-files=



                      Another way is to logrotate once a day by using the prerotate/postrotate feature to stop the servers, rotate the log and start the servers again. The logrotation time is depending on your systemd logrotate.timer or (ana)cron job, which could be timed to 4am or whenever is low to zero traffic.



                      prerotate
                      # stop jboss/tomcat server
                      endscript

                      daily
                      rotate 10
                      compress
                      size 20M

                      postrotate
                      #start servers
                      endscript





                      share|improve this answer




















                      • I cannot stop the server, my need is while logrotate is doing truncate I should not loose the data, Is there a way for it? Can u suggest me any configuration? @Michael D
                        – Harry
                        Mar 6 '17 at 15:10











                      • is using journald an option? Read this loggly.com/blog/why-journald
                        – Michael D.
                        Mar 6 '17 at 15:22












                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      You could move from logfile logging and rotating with logrotate to journald logging using systemd-cat -t indentifier cmdline. Setup log/entry sizes in /etc/systemd/journald.conf or use journalctl --vacuum-size=, --vacuum-time=, --vacuum-files=



                      Another way is to logrotate once a day by using the prerotate/postrotate feature to stop the servers, rotate the log and start the servers again. The logrotation time is depending on your systemd logrotate.timer or (ana)cron job, which could be timed to 4am or whenever is low to zero traffic.



                      prerotate
                      # stop jboss/tomcat server
                      endscript

                      daily
                      rotate 10
                      compress
                      size 20M

                      postrotate
                      #start servers
                      endscript





                      share|improve this answer












                      You could move from logfile logging and rotating with logrotate to journald logging using systemd-cat -t indentifier cmdline. Setup log/entry sizes in /etc/systemd/journald.conf or use journalctl --vacuum-size=, --vacuum-time=, --vacuum-files=



                      Another way is to logrotate once a day by using the prerotate/postrotate feature to stop the servers, rotate the log and start the servers again. The logrotation time is depending on your systemd logrotate.timer or (ana)cron job, which could be timed to 4am or whenever is low to zero traffic.



                      prerotate
                      # stop jboss/tomcat server
                      endscript

                      daily
                      rotate 10
                      compress
                      size 20M

                      postrotate
                      #start servers
                      endscript






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Mar 6 '17 at 13:45









                      Michael D.

                      1,489715




                      1,489715











                      • I cannot stop the server, my need is while logrotate is doing truncate I should not loose the data, Is there a way for it? Can u suggest me any configuration? @Michael D
                        – Harry
                        Mar 6 '17 at 15:10











                      • is using journald an option? Read this loggly.com/blog/why-journald
                        – Michael D.
                        Mar 6 '17 at 15:22
















                      • I cannot stop the server, my need is while logrotate is doing truncate I should not loose the data, Is there a way for it? Can u suggest me any configuration? @Michael D
                        – Harry
                        Mar 6 '17 at 15:10











                      • is using journald an option? Read this loggly.com/blog/why-journald
                        – Michael D.
                        Mar 6 '17 at 15:22















                      I cannot stop the server, my need is while logrotate is doing truncate I should not loose the data, Is there a way for it? Can u suggest me any configuration? @Michael D
                      – Harry
                      Mar 6 '17 at 15:10





                      I cannot stop the server, my need is while logrotate is doing truncate I should not loose the data, Is there a way for it? Can u suggest me any configuration? @Michael D
                      – Harry
                      Mar 6 '17 at 15:10













                      is using journald an option? Read this loggly.com/blog/why-journald
                      – Michael D.
                      Mar 6 '17 at 15:22




                      is using journald an option? Read this loggly.com/blog/why-journald
                      – Michael D.
                      Mar 6 '17 at 15:22










                      up vote
                      0
                      down vote













                      This is how I do it for Catalina logs:



                      /var/log/tomcat/catalina.out xargs kill -9
                      cat /var/log/tomcat/tmp.log >> /var/log/tomcat/catalina.out
                      rm /var/log/tomcat/tmp.log -f
                      endscript



                      You may optionally specify -s with tail to decrease refresh interval of tail command itself. And because you use -c option, it's fast.






                      share|improve this answer


























                        up vote
                        0
                        down vote













                        This is how I do it for Catalina logs:



                        /var/log/tomcat/catalina.out xargs kill -9
                        cat /var/log/tomcat/tmp.log >> /var/log/tomcat/catalina.out
                        rm /var/log/tomcat/tmp.log -f
                        endscript



                        You may optionally specify -s with tail to decrease refresh interval of tail command itself. And because you use -c option, it's fast.






                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          This is how I do it for Catalina logs:



                          /var/log/tomcat/catalina.out xargs kill -9
                          cat /var/log/tomcat/tmp.log >> /var/log/tomcat/catalina.out
                          rm /var/log/tomcat/tmp.log -f
                          endscript



                          You may optionally specify -s with tail to decrease refresh interval of tail command itself. And because you use -c option, it's fast.






                          share|improve this answer














                          This is how I do it for Catalina logs:



                          /var/log/tomcat/catalina.out xargs kill -9
                          cat /var/log/tomcat/tmp.log >> /var/log/tomcat/catalina.out
                          rm /var/log/tomcat/tmp.log -f
                          endscript



                          You may optionally specify -s with tail to decrease refresh interval of tail command itself. And because you use -c option, it's fast.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Aug 16 at 6:37

























                          answered Aug 15 at 8:31









                          Alireza Mohamadi

                          10816




                          10816



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f349471%2flogrotate-in-linux-to-handle-log-data-loss%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?