{
  "created": "2015-12-20T19:56:47Z",
  "hierarchy": [
    {
      "name": "ROOT",
      "type": "folder",
      "uri": "/ROOT"
    },
    {
      "name": "Logrotate Notes",
      "type": "article",
      "uri": "Logrotate_Notes"
    }
  ],
  "html": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\"/>\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>\n    <meta property=\"og:image\" content=\"/img/logo512.png\"/>\n    <meta property=\"og:site_name\" content=\"Nikhil's Personal Wiki\"/>\n    <link rel=\"og:image\" href=\"/img/logo512.png\"/>\n    <link rel=\"icon\" href=\"/img/favicon.png\"/>\n    <link rel=\"apple-touch-icon\" href=\"/img/logo192.png\"/>\n    <link rel=\"stylesheet\" href=\"/css/styles.css\"/>\n    <link rel=\"stylesheet\" href=\"/css/highlight.css\"/>\n    <title>Logrotate Notes &ndash; Nikhil's Personal Wiki</title>\n    <script type=\"text/javascript\" id=\"MathJax-script\" defer src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js\"></script>\n    <script defer data-domain=\"wiki.nikhil.io\" src=\"https://plausible.io/js/plausible.js\"></script>\n  </head>\n  <body>\n    <noscript>\n      👉 A few things won&#8217;t work if you have JavaScript disabled.\n    </noscript>\n    <div class=\"container article\">\n      <header>\n        <nav>\n          <ul>\n            <li>\n              <a href=\"/archive\"  title=\"Archive\">\n                <span>Archive</span>\n              </a>\n            </li>\n            <li>\n              <a href=\"/Home\"  title=\"Home\">\n                <span>Home</span>\n              </a>\n            </li>\n            <li>\n              <a href=\"/random\"  title=\"See a random article\">\n                <span>Random</span>\n              </a>\n            </li>\n            \n            \n              \n                <li>\n                  <a href=\"/Logrotate_Notes/raw\"  title=\"View Source\">\n                    <span>Raw</span>\n                  </a>\n                </li>\n              \n              \n            \n            \n            \n            \n              \n                <li>\n                  <a href=\"/Logrotate_Notes/revisions\" >\n                    <span>Revisions</span>\n                  </a>\n                </li>\n              \n            \n            \n              \n                \n                  <li>\n                    <a href=\"/Logrotate_Notes/index.json\" title=\"View JSON Object\">\n                      <span>JSON</span>\n                    </a>\n                  </li>\n                \n              \n            \n          </ul>\n        </nav>\n      </header>\n      <main>\n        \n  <nav>\n  <ul>\n    \n      <li>\n        <a data-entity-type=\"folder\" href=\"/ROOT\" title=\"ROOT\">Root</a>\n      </li>\n    \n      <li>\n        <a data-entity-type=\"article\" href=\"/Logrotate_Notes\" title=\"Logrotate Notes\">Logrotate Notes</a>\n      </li>\n    \n    \n    \n    \n    \n  </ul>\n</nav>\n\n  <h1>Logrotate Notes\n    \n  </h1>\n  <p>This is a quick overview of <code>logrotate</code> which&hellip; umm&hellip; rotates log<br />\nfiles. This was written for CentOS/RHEL 5.5.</p>\n<h2>Pertinent Files &amp; Directories</h2>\n<table>\n<thead>\n<tr>\n<th>File/Dir</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>/usr/sbin/logrotate</code></td>\n<td>The command itself.</td>\n</tr>\n<tr>\n<td><code>/etc/cron.daily/logrotate</code></td>\n<td>Bash script that executes the <code>logrotate</code> command every day.</td>\n</tr>\n<tr>\n<td><code>/etc/logrotate.conf</code> and <code>/etc/logrotate.d/</code></td>\n<td>Rotation defaults if they are not defined for specific daemons. You can add rotate configs to this file, or put them in <code>/etc/logrotate.d</code></td>\n</tr>\n<tr>\n<td><code>/var/lib/logrotate.status</code></td>\n<td>Show when the specified log files were last rotated.</td>\n</tr>\n</tbody>\n</table>\n<h2>Logrotate Options</h2>\n<p>Quite simple, really. The <code>man</code> page elucidates all available options.<br />\nHere&rsquo;s a quick table of what the most commonly used ones do.</p>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>rotate &lt;number&gt;</code></td>\n<td>Keep specified number of logfiles before they are deleted and/or emailed to admin</td>\n</tr>\n<tr>\n<td><code>size=&lt;number&gt;</code></td>\n<td>Rotate logs when they reach this size.</td>\n</tr>\n<tr>\n<td></td>\n<td>This is done &lsquo;&lsquo;without regard&rsquo;&rsquo; for the last rotated time.</td>\n</tr>\n<tr>\n<td></td>\n<td>Use <code>minsize &lt;number&gt;</code> if you&rsquo;d like to balance both time and size.</td>\n</tr>\n<tr>\n<td></td>\n<td>Bytes are used without a specifier. 100k, 100M are also fine.</td>\n</tr>\n<tr>\n<td><code>daily</code></td>\n<td>Rotate daily. This is the default minimum granularity, unless you move <code>/etc/cron.daily/logrotate</code> to <code>/etc/cron.hourly/logrotate</code></td>\n</tr>\n<tr>\n<td><code>weekly</code></td>\n<td>Rotate weekly</td>\n</tr>\n<tr>\n<td><code>monthly</code></td>\n<td>Rotate monthly</td>\n</tr>\n<tr>\n<td><code>notifempty</code></td>\n<td>Don&rsquo;t rotate if empty (the reverse, <code>ifempty</code>, is default)</td>\n</tr>\n<tr>\n<td><code>missingok</code></td>\n<td>If log file is missing for some reason, move on without error</td>\n</tr>\n<tr>\n<td><code>compress</code></td>\n<td>Compress logfile after rotation.</td>\n</tr>\n<tr>\n<td></td>\n<td>Default is <code>gzip</code> with <code>-9</code> (maximum) compression.</td>\n</tr>\n<tr>\n<td></td>\n<td>The choice of compression program can be changed with <code>compresscmd</code> (e.g. <code>compresscmd bzip2</code>).</td>\n</tr>\n<tr>\n<td></td>\n<td>To pass options (like compression level), use <code>compressoptions</code>.</td>\n</tr>\n<tr>\n<td></td>\n<td>To change extension of compressed file, use <code>compressext</code></td>\n</tr>\n<tr>\n<td><code>dateext</code></td>\n<td>Use YYYYMMDD format instead of just tacking on numbers (like <code>.0</code>, <code>.1</code> and so on) to the rotated files.</td>\n</tr>\n<tr>\n<td><code>mail &lt;recipient&gt;</code></td>\n<td>Email recipient the file that will be deleted after a rotation cycle</td>\n</tr>\n<tr>\n<td><code>create &lt;mode&gt; &lt;owner&gt; &lt;group&gt;</code></td>\n<td>Create logfiles with the specified permissions and owner:group attributes.</td>\n</tr>\n<tr>\n<td><code>olddir &lt;directory&gt;</code></td>\n<td>Move all but the newest log file to this directory (nice to keep things organized)</td>\n</tr>\n</tbody>\n</table>\n<h3>Other (kinda important) options</h3>\n<p>You&rsquo;ll see these used with Apache, for instance.</p>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>prerotate</code></td>\n<td>Execute the a script &lsquo;&lsquo;before&rsquo;&rsquo; rotating a log. Should end this with <code>endscript</code>.</td>\n</tr>\n<tr>\n<td><code>postrotate</code></td>\n<td>Execute the a script &lsquo;&lsquo;after&rsquo;&rsquo; rotating a log. Should end this with <code>endscript</code>.</td>\n</tr>\n<tr>\n<td><code>sharedscripts</code></td>\n<td>Make sure that the script(s) specified in <code>prerotate</code> and/or <code>postrotate</code> run just &lsquo;&lsquo;once&rsquo;&rsquo; (i.e. not for &lsquo;&rsquo;every&rsquo;&rsquo; logfile)</td>\n</tr>\n<tr>\n<td><code>delaycompress</code></td>\n<td>Don&rsquo;t compress yesterday&rsquo;s logfile (if daily&hellip; you get the picture)</td>\n</tr>\n</tbody>\n</table>\n<h2>Example</h2>\n<p>Here&rsquo;s a real-world application of the above. I want to rotate an<br />\nalready huge log of OpenVPN connections (~32M in size) like so:</p>\n<ul>\n<li>I want to maintain <strong>60 days</strong> worth of logs</li>\n<li>Logfile <strong>size doesn&rsquo;t matter</strong> to me</li>\n<li>The files should be rotated in <strong>YYYYMMDD</strong> format</li>\n<li>They should be <strong>compressed</strong> (the default <code>gzip -9</code> is fine)</li>\n<li>They should be <strong>organized</strong>; older logfiles should be <strong>in a<br />\nseparate directory</strong></li>\n</ul>\n<p>The logfile is at <code>/var/log/openvpn/connections.log</code>. Here&rsquo;s the<br />\nconfiguration file I created for the above. It&rsquo;s <code>/etc/logrotate.d/openvpn</code>:</p>\n<pre><code>/var/log/openvpn/connections.log {  \n    daily  \n    rotate 60  \n    dateext  \n    compress  \n    olddir /var/log/openvpn/old  \n  \n    nomail  \n    missingok  \n    notifempty  \n    delaycompress  \n    create 640 root root  \n}\n</code></pre>\n<p>To test this, I run:</p>\n<pre><code>logrotate -d /etc/logrotate.d/openvpn\n</code></pre>\n<p>The <code>-d</code> switch runs it in verbose, debug, dry-run mode (i.e. nothing<br />\nactually happens.)</p>\n<h2>Other Stuff</h2>\n<h3>Leopard and Snow Leopard</h3>\n<p>These use a new utility called <code>newsyslog</code>. It is invoked every minute<br />\nby:</p>\n<pre><code>/System/Library/LaunchDaemons/com.apple.newsyslog.plist\n</code></pre>\n<p>The config file for this is <code>/etc/newsyslog.conf</code> and is kinda nicer<br />\nthan <code>logrotate</code>&rsquo;s config :)</p>\n<h2>Sources</h2>\n<ul>\n<li><a href=\"http://www.thegeekstuff.com/2010/07/logrotate-examples/\">Logrotate Examples</a></li>\n<li><a href=\"http://linuxers.org/howto/howto-use-logrotate-manage-log-files\">Using logrotate to manage log files</a></li>\n<li><a href=\"http://www.ducea.com/2006/06/06/rotating-linux-log-files-part-2-logrotate/\">Rotating Linux log files</a></li>\n</ul>\n\n\n      </main>\n      <footer>\n        <p>\n          \n        </p>\n        <ul>\n          \n  <li>7,693 bytes</li>\n  \n    <li>Created on Sunday, 20 December 2015 at 19:56 UTC</li>\n    <li>Modified on Tuesday, 13 January 2026 at 18:47 UTC</li>\n    <br/>\n    <li>\n      <a\n        href=\"https://github.com/afreeorange/wiki.nikhil.io.articles/edit/master/Logrotate Notes.md\"\n        title=\"Edit this article\">Edit this article</a>\n    </li>\n  \n\n          <li>\n            <a href=\"https://github.com/afreeorange/bock\" title=\"View the project that generates this wiki on Github\">bock\n            5.2.0-beta</a>\n          </li>\n        </ul>\n      </footer>\n    </div>\n    \n    \n      <script type=\"text/javascript\">\n        /**\n         * Quick shortcut to take me to the search box which is 90% of how I navigate\n         * this wiki anyway.\n         */\n        document.body.addEventListener(\n          \"keypress\", (e) => e.key === \"f\"\n          ? window.location.assign(\"/archive\")\n          : null);\n        window.MathJax = {\n          tex: {\n            inlineMath: [\n              [\n                '$', '$'\n              ],\n              [\n                '\\\\(', '\\\\)'\n              ]\n            ]\n          },\n          svg: {\n            fontCache: 'global'\n          }\n        };\n      </script>\n    \n  </body>\n</html></head></html>\n",
  "id": "f5aaadd5-1ce8-52da-9eae-db03957462c8",
  "modified": "2026-01-13T18:47:28Z",
  "revisions": [
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-01-13T18:47:28Z",
      "id": "2436477560f26e23d00a24add1cbfeafdca4af78",
      "shortId": "24364775",
      "subject": "No compression\n",
      "content": "This is a quick overview of `logrotate` which... umm... rotates log\nfiles. This was written for CentOS/RHEL 5.5.\n\nPertinent Files & Directories\n-----------------------------\n\n|                    File/Dir                   |                                                                  Purpose                                                                   |\n|-----------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|\n| `/usr/sbin/logrotate`                         | The command itself.                                                                                                                        |\n| `/etc/cron.daily/logrotate`                   | Bash script that executes the `logrotate` command every day.                                                                               |\n| `/etc/logrotate.conf` and `/etc/logrotate.d/` | Rotation defaults if they are not defined for specific daemons. You can add rotate configs to this file, or put them in `/etc/logrotate.d` |\n| `/var/lib/logrotate.status`                   | Show when the specified log files were last rotated.                                                                                       |\n\nLogrotate Options\n-----------------\n\nQuite simple, really. The `man` page elucidates all available options.\nHere's a quick table of what the most commonly used ones do.\n\n|              Option             |                                                              Purpose                                                               |\n|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `rotate <number>`               | Keep specified number of logfiles before they are deleted and/or emailed to admin                                                  |\n| `size=<number>`                 | Rotate logs when they reach this size.                                                                                             |\n|                                 | This is done ''without regard'' for the last rotated time.                                                                         |\n|                                 | Use `minsize <number>` if you'd like to balance both time and size.                                                                |\n|                                 | Bytes are used without a specifier. 100k, 100M are also fine.                                                                      |\n| `daily`                         | Rotate daily. This is the default minimum granularity, unless you move `/etc/cron.daily/logrotate` to `/etc/cron.hourly/logrotate` |\n| `weekly`                        | Rotate weekly                                                                                                                      |\n| `monthly`                       | Rotate monthly                                                                                                                     |\n| `notifempty`                    | Don't rotate if empty (the reverse, `ifempty`, is default)                                                                         |\n| `missingok`                     | If log file is missing for some reason, move on without error                                                                      |\n| `compress`                      | Compress logfile after rotation.                                                                                                   |\n|                                 | Default is `gzip` with `-9` (maximum) compression.                                                                                 |\n|                                 | The choice of compression program can be changed with `compresscmd` (e.g. `compresscmd bzip2`).                                    |\n|                                 | To pass options (like compression level), use `compressoptions`.                                                                   |\n|                                 | To change extension of compressed file, use `compressext`                                                                          |\n| `dateext`                       | Use YYYYMMDD format instead of just tacking on numbers (like `.0`, `.1` and so on) to the rotated files.                           |\n| `mail <recipient>`              | Email recipient the file that will be deleted after a rotation cycle                                                               |\n| `create <mode> <owner> <group>` | Create logfiles with the specified permissions and owner:group attributes.                                                         |\n| `olddir <directory>`            | Move all but the newest log file to this directory (nice to keep things organized)                                                 |\n\n### Other (kinda important) options\n\nYou'll see these used with Apache, for instance.\n\n|      Option     |                                                           Purpose                                                            |\n|-----------------|------------------------------------------------------------------------------------------------------------------------------|\n| `prerotate`     | Execute the a script ''before'' rotating a log. Should end this with `endscript`.                                            |\n| `postrotate`    | Execute the a script ''after'' rotating a log. Should end this with `endscript`.                                             |\n| `sharedscripts` | Make sure that the script(s) specified in `prerotate` and/or `postrotate` run just ''once'' (i.e. not for ''every'' logfile) |\n| `delaycompress` | Don't compress yesterday's logfile (if daily... you get the picture)                                                         |\n\nExample\n-------\n\nHere's a real-world application of the above. I want to rotate an\nalready huge log of OpenVPN connections (\\~32M in size) like so:\n\n*   I want to maintain **60 days** worth of logs\n*   Logfile **size doesn't matter** to me\n*   The files should be rotated in **YYYYMMDD** format\n*   They should be **compressed** (the default `gzip -9` is fine)\n*   They should be **organized**; older logfiles should be **in a\n    separate directory**\n\nThe logfile is at `/var/log/openvpn/connections.log`. Here's the\nconfiguration file I created for the above. It's `/etc/logrotate.d/openvpn`:\n\n    /var/log/openvpn/connections.log {  \n        daily  \n        rotate 60  \n        dateext  \n        compress  \n        olddir /var/log/openvpn/old  \n      \n        nomail  \n        missingok  \n        notifempty  \n        delaycompress  \n        create 640 root root  \n    }\n\nTo test this, I run:\n\n    logrotate -d /etc/logrotate.d/openvpn\n\nThe `-d` switch runs it in verbose, debug, dry-run mode (i.e. nothing\nactually happens.)\n\nOther Stuff\n-----------\n\n### Leopard and Snow Leopard\n\nThese use a new utility called `newsyslog`. It is invoked every minute\nby:\n\n    /System/Library/LaunchDaemons/com.apple.newsyslog.plist\n\nThe config file for this is `/etc/newsyslog.conf` and is kinda nicer\nthan `logrotate`'s config :)\n\nSources\n-------\n\n-   [Logrotate Examples](http://www.thegeekstuff.com/2010/07/logrotate-examples/)\n-   [Using logrotate to manage log files](http://linuxers.org/howto/howto-use-logrotate-manage-log-files)\n-   [Rotating Linux log files](http://www.ducea.com/2006/06/06/rotating-linux-log-files-part-2-logrotate/)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2015-12-27T07:27:56Z",
      "id": "1aa29105a45aa67523ffb61e73bcc415f935a47e",
      "shortId": "1aa29105",
      "subject": "Fix Markdown conversion\n\nSaw half a season of The Office\n",
      "content": "This is a quick overview of `logrotate` which... umm... rotates log\nfiles. This was written for CentOS/RHEL 5.5.\n\nPertinent Files & Directories\n-----------------------------\n\n|                    File/Dir                   |                                                                  Purpose                                                                   |\n|-----------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|\n| `/usr/sbin/logrotate`                         | The command itself.                                                                                                                        |\n| `/etc/cron.daily/logrotate`                   | Bash script that executes the `logrotate` command every day.                                                                               |\n| `/etc/logrotate.conf` and `/etc/logrotate.d/` | Rotation defaults if they are not defined for specific daemons. You can add rotate configs to this file, or put them in `/etc/logrotate.d` |\n| `/var/lib/logrotate.status`                   | Show when the specified log files were last rotated.                                                                                       |\n\nLogrotate Options\n-----------------\n\nQuite simple, really. The `man` page elucidates all available options.\nHere's a quick table of what the most commonly used ones do.\n\n|              Option             |                                                              Purpose                                                               |\n|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `rotate <number>`               | Keep specified number of logfiles before they are deleted and/or emailed to admin                                                  |\n| `size=<number>`                 | Rotate logs when they reach this size.                                                                                             |\n|                                 | This is done ''without regard'' for the last rotated time.                                                                         |\n|                                 | Use `minsize <number>` if you'd like to balance both time and size.                                                                |\n|                                 | Bytes are used without a specifier. 100k, 100M are also fine.                                                                      |\n| `daily`                         | Rotate daily. This is the default minimum granularity, unless you move `/etc/cron.daily/logrotate` to `/etc/cron.hourly/logrotate` |\n| `weekly`                        | Rotate weekly                                                                                                                      |\n| `monthly`                       | Rotate monthly                                                                                                                     |\n| `notifempty`                    | Don't rotate if empty (the reverse, `ifempty`, is default)                                                                         |\n| `missingok`                     | If log file is missing for some reason, move on without error                                                                      |\n| `compress`                      | Compress logfile after rotation.                                                                                                   |\n|                                 | Default is `gzip` with `-9` (maximum) compression.                                                                                 |\n|                                 | The choice of compression program can be changed with `compresscmd` (e.g. `compresscmd bzip2`).                                    |\n|                                 | To pass options (like compression level), use `compressoptions`.                                                                   |\n|                                 | To change extension of compressed file, use `compressext`                                                                          |\n| `dateext`                       | Use YYYYMMDD format instead of just tacking on numbers (like `.0`, `.1` and so on) to the rotated files.                           |\n| `mail <recipient>`              | Email recipient the file that will be deleted after a rotation cycle                                                               |\n| `create <mode> <owner> <group>` | Create logfiles with the specified permissions and owner:group attributes.                                                         |\n| `olddir <directory>`            | Move all but the newest log file to this directory (nice to keep things organized)                                                 |\n\n### Other (kinda important) options\n\nYou'll see these used with Apache, for instance.\n\n|      Option     |                                                           Purpose                                                            |\n|-----------------|------------------------------------------------------------------------------------------------------------------------------|\n| `prerotate`     | Execute the a script ''before'' rotating a log. Should end this with `endscript`.                                            |\n| `postrotate`    | Execute the a script ''after'' rotating a log. Should end this with `endscript`.                                             |\n| `sharedscripts` | Make sure that the script(s) specified in `prerotate` and/or `postrotate` run just ''once'' (i.e. not for ''every'' logfile) |\n| `delaycompress` | Don't compress yesterday's logfile (if daily... you get the picture)                                                         |\n\nExample\n-------\n\nHere's a real-world application of the above. I want to rotate an\nalready huge log of OpenVPN connections (\\~32M in size) like so:\n\n*   I want to maintain **60 days** worth of logs\n*   Logfile **size doesn't matter** to me\n*   The files should be rotated in **YYYYMMDD** format\n*   They should be **compressed** (the default `gzip -9` is fine)\n*   They should be **organized**; older logfiles should be **in a\n    separate directory**\n\nThe logfile is at `/var/log/openvpn/connections.log`. Here's the\nconfiguration file I created for the above. It's `/etc/logrotate.d/openvpn`:\n\n    /var/log/openvpn/connections.log {  \n        daily  \n        rotate 60  \n        dateext  \n        compress  \n        olddir /var/log/openvpn/old  \n      \n        nomail  \n        missingok  \n        notifempty  \n        delaycompress  \n        create 640 root root  \n    }\n\nTo test this, I run:\n\n    logrotate -d /etc/logrotate.d/openvpn\n\nThe `-d` switch runs it in verbose, debug, dry-run mode (i.e. nothing\nactually happens.)\n\nOther Stuff\n-----------\n\n### Leopard and Snow Leopard\n\nThese use a new utility called `newsyslog`. It is invoked every minute\nby:\n\n    /System/Library/LaunchDaemons/com.apple.newsyslog.plist\n\nThe config file for this is `/etc/newsyslog.conf` and is kinda nicer\nthan `logrotate`'s config :)\n\nSources\n-------\n\n-   [Logrotate Examples](http://www.thegeekstuff.com/2010/07/logrotate-examples/)\n-   [Using logrotate to manage log files](http://linuxers.org/howto/howto-use-logrotate-manage-log-files)\n-   [Rotating Linux log files](http://www.ducea.com/2006/06/06/rotating-linux-log-files-part-2-logrotate/)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2015-12-21T02:30:47Z",
      "id": "d658e80d1ecb97b196531c7b15a0f9af709c05de",
      "shortId": "d658e80d",
      "subject": "Incremental\n",
      "content": "This is a quick overview of `logrotate` which... umm... rotates log\nfiles. This is specific to CentOS/RHEL and was written for release 5.5.\n\nPertinent Files & Directories\n-----------------------------\n\n<table style=\"width:10%;\">\n<colgroup>\n<col width=\"4%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th align=\"left\"><p>File/Directory</p></th>\n<th align=\"left\"><p>Purpose |-------</p></th>\n<th align=\"left\"><p><code>/usr/sbin/logrotate</code></p></th>\n<th align=\"left\"><p>The command itself. |-------</p></th>\n<th align=\"left\"><p><code>/etc/cron.daily/logrotate</code></p></th>\n<th align=\"left\"><p>Bash script that executes the <code>logrotate</code> command every day. |-------</p></th>\n<th align=\"left\"><p><code>/etc/logrotate.conf</code> and <code>/etc/logrotate.d/</code></p></th>\n<th align=\"left\"><p>Rotation defaults if they are not defined for specific daemons. You can add rotate configs to this file, or put them in <code>/etc/logrotate.d</code> |-------</p></th>\n<th align=\"left\"><p><code>/var/lib/logrotate.status</code></p></th>\n<th align=\"left\"><p>Show when the specified log files were last rotated. |-------</p></th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n\nLogrotate Options\n-----------------\n\nQuite simple, really. The `man` page elucidates all available options.\nHere's a quick table of what the most commonly used ones do.\n\n<table style=\"width:10%;\">\n<colgroup>\n<col width=\"3%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th align=\"left\"><p>Option</p></th>\n<th align=\"left\"><p>Purpose |-------</p></th>\n<th align=\"left\"><p><code>rotate &lt;number&gt;</code></p></th>\n<th align=\"left\"><p>Keep specified number of logfiles before they are deleted and/or emailed to admin |-------</p></th>\n<th align=\"left\"><p><code>size=&lt;number&gt;</code></p></th>\n<th align=\"left\"><p>Rotate logs when they reach this size.</p>\n<ul>\n<li>This is done <em>without regard</em> for the last rotated time.</li>\n<li>Use <code>minsize &lt;number&gt;</code> if you'd like to balance both time and size.</li>\n<li>Bytes are used without a specifier. 100k, 100M are also fine.</li>\n</ul>\n<p>|-------</p></th>\n<th align=\"left\"><p><code>daily</code></p></th>\n<th align=\"left\"><p>Rotate daily. This is the default minimum granularity, unless you move <code>/etc/'''cron.daily'''/logrotate</code> to <code>/etc/'''cron.hourly'''/logrotate</code> |------</p></th>\n<th align=\"left\"><p><code>weekly</code></p></th>\n<th align=\"left\"><p>Rotate weekly |------</p></th>\n<th align=\"left\"><p><code>monthly</code></p></th>\n<th align=\"left\"><p>Rotate monthly |------</p></th>\n<th align=\"left\"><p><code>notifempty</code></p></th>\n<th align=\"left\"><p>Don't rotate if empty (the reverse, <code>ifempty</code>, is default) |------</p></th>\n<th align=\"left\"><p><code>missingok</code></p></th>\n<th align=\"left\"><p>If log file is missing for some reason, move on without error |------</p></th>\n<th align=\"left\"><p><code>compress</code></p></th>\n<th align=\"left\"><p>Compress logfile after rotation.</p>\n<ul>\n<li>Default is <code>gzip</code> with <code>-9</code> (maximum) compression.</li>\n<li>The choice of compression program can be changed with <code>compresscmd</code> (e.g. <code>compresscmd bzip2</code>).</li>\n<li>To pass options (like compression level), use <code>compressoptions</code>.</li>\n<li>To change extension of compressed file, use <code>compressext</code></li>\n</ul>\n<p>|------</p></th>\n<th align=\"left\"><p><code>dateext</code></p></th>\n<th align=\"left\"><p>Use YYYYMMDD format instead of just tacking on numbers (like <code>.0</code>, <code>.1</code> and so on) to the rotated files. |------</p></th>\n<th align=\"left\"><p><code>mail &lt;recipient&gt;</code></p></th>\n<th align=\"left\"><p>Email recipient the file that will be deleted after a rotation cycle |------</p></th>\n<th align=\"left\"><p><code>create &lt;mode&gt; &lt;owner&gt; &lt;group&gt;</code></p></th>\n<th align=\"left\"><p>Create logfiles with the specified permissions and owner:group attributes. |------</p></th>\n<th align=\"left\"><p><code>olddir &lt;directory&gt;</code></p></th>\n<th align=\"left\"><p>Move all but the newest log file to this directory (nice to keep things organized)</p></th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n\n### Other (kinda important) options\n\nYou'll see these used with Apache, for instance.\n\n<table style=\"width:10%;\">\n<colgroup>\n<col width=\"2%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th align=\"left\"><p>Option</p></th>\n<th align=\"left\"><p>Purpose |-------</p></th>\n<th align=\"left\"><p><code>prerotate</code></p></th>\n<th align=\"left\"><p>Execute the a script <em>before</em> rotating a log. Should end this with <code>endscript</code>. |-------</p></th>\n<th align=\"left\"><p><code>postrotate</code></p></th>\n<th align=\"left\"><p>Execute the a script <em>after</em> rotating a log. Should end this with <code>endscript</code>. |-------</p></th>\n<th align=\"left\"><p><code>sharedscripts</code></p></th>\n<th align=\"left\"><p>Make sure that the script(s) specified in <code>prerotate</code> and/or <code>postrotate</code> run just <em>once</em> (i.e. not for <em>every</em> logfile) |------</p></th>\n<th align=\"left\"><p><code>delaycompress</code></p></th>\n<th align=\"left\"><p>Don't compress yesterday's logfile (if daily... you get the picture)</p></th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n\nExample\n-------\n\nHere's a real-world application of the above. I want to rotate an\nalready huge log of OpenVPN connections (\\~32M in size) like so:\n\n-   I want to maintain **60 days** worth of logs\n-   Logfile **size doesn't matter** to me\n-   The files should be rotated in **YYYYMMDD** format\n-   They should be **compressed** (the default `gzip -9` is fine)\n-   They should be **organized**; older logfiles should be **in a\n    separate directory**\n\nThe logfile is at `/var/log/openvpn/connections.log`. Here's the\nconfiguration file I created for the above. It's\n`/etc/logrotate.d/openvpn`:\n\n` /var/log/openvpn/connections.log {`  \n`     daily`  \n`     rotate 60`  \n`     dateext`  \n`     compress`  \n`     olddir /var/log/openvpn/old`  \n` `  \n`     nomail`  \n`     missingok`  \n`     notifempty`  \n`     delaycompress`  \n`     create 640 root root`  \n` }`\n\nTo test this, I run:\n\n` logrotate -d /etc/logrotate.d/openvpn`\n\nThe `-d` switch runs it in verbose, debug, dry-run mode (i.e. nothing\nactually happens.)\n\nOther Stuff\n-----------\n\n### Leopard and Snow Leopard\n\nThese use a new utility called `newsyslog`. It is invoked every minute\nby:\n\n` /System/Library/LaunchDaemons/com.apple.newsyslog.plist`\n\nThe config file for this is `/etc/newsyslog.conf` and is kinda nicer\nthan `logrotate`'s config :)\n\nSources\n-------\n\n-   [Logrotate\n    Examples](http://www.thegeekstuff.com/2010/07/logrotate-examples/)\n-   [Using logrotate to manage log\n    files](http://linuxers.org/howto/howto-use-logrotate-manage-log-files)\n-   [Rotating Linux log\n    files](http://www.ducea.com/2006/06/06/rotating-linux-log-files-part-2-logrotate/)\n"
    },
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2015-12-20T19:56:47Z",
      "id": "359e4ba26f31c1a5e63c81b6fb1d0adeb4857aba",
      "shortId": "359e4ba2",
      "subject": "Logrotate Notes : First Draft\n",
      "content": "This is a quick overview of `logrotate` which... umm... rotates log\nfiles. This is specific to CentOS/RHEL and was written for release 5.5.\n\nPertinent Files & Directories\n-----------------------------\n\n<table style=\"width:10%;\">\n<colgroup>\n<col width=\"4%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th align=\"left\"><p>File/Directory</p></th>\n<th align=\"left\"><p>Purpose |-------</p></th>\n<th align=\"left\"><p><code>/usr/sbin/logrotate</code></p></th>\n<th align=\"left\"><p>The command itself. |-------</p></th>\n<th align=\"left\"><p><code>/etc/cron.daily/logrotate</code></p></th>\n<th align=\"left\"><p>Bash script that executes the <code>logrotate</code> command every day. |-------</p></th>\n<th align=\"left\"><p><code>/etc/logrotate.conf</code> and <code>/etc/logrotate.d/</code></p></th>\n<th align=\"left\"><p>Rotation defaults if they are not defined for specific daemons. You can add rotate configs to this file, or put them in <code>/etc/logrotate.d</code> |-------</p></th>\n<th align=\"left\"><p><code>/var/lib/logrotate.status</code></p></th>\n<th align=\"left\"><p>Show when the specified log files were last rotated. |-------</p></th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n\nLogrotate Options\n-----------------\n\nQuite simple, really. The `man` page elucidates all available options.\nHere's a quick table of what the most commonly used ones do.\n\n<table style=\"width:10%;\">\n<colgroup>\n<col width=\"3%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th align=\"left\"><p>Option</p></th>\n<th align=\"left\"><p>Purpose |-------</p></th>\n<th align=\"left\"><p><code>rotate &lt;number&gt;</code></p></th>\n<th align=\"left\"><p>Keep specified number of logfiles before they are deleted and/or emailed to admin |-------</p></th>\n<th align=\"left\"><p><code>size=&lt;number&gt;</code></p></th>\n<th align=\"left\"><p>Rotate logs when they reach this size.</p>\n<ul>\n<li>This is done <em>without regard</em> for the last rotated time.</li>\n<li>Use <code>minsize &lt;number&gt;</code> if you'd like to balance both time and size.</li>\n<li>Bytes are used without a specifier. 100k, 100M are also fine.</li>\n</ul>\n<p>|-------</p></th>\n<th align=\"left\"><p><code>daily</code></p></th>\n<th align=\"left\"><p>Rotate daily. This is the default minimum granularity, unless you move <code>/etc/'''cron.daily'''/logrotate</code> to <code>/etc/'''cron.hourly'''/logrotate</code> |------</p></th>\n<th align=\"left\"><p><code>weekly</code></p></th>\n<th align=\"left\"><p>Rotate weekly |------</p></th>\n<th align=\"left\"><p><code>monthly</code></p></th>\n<th align=\"left\"><p>Rotate monthly |------</p></th>\n<th align=\"left\"><p><code>notifempty</code></p></th>\n<th align=\"left\"><p>Don't rotate if empty (the reverse, <code>ifempty</code>, is default) |------</p></th>\n<th align=\"left\"><p><code>missingok</code></p></th>\n<th align=\"left\"><p>If log file is missing for some reason, move on without error |------</p></th>\n<th align=\"left\"><p><code>compress</code></p></th>\n<th align=\"left\"><p>Compress logfile after rotation.</p>\n<ul>\n<li>Default is <code>gzip</code> with <code>-9</code> (maximum) compression.</li>\n<li>The choice of compression program can be changed with <code>compresscmd</code> (e.g. <code>compresscmd bzip2</code>).</li>\n<li>To pass options (like compression level), use <code>compressoptions</code>.</li>\n<li>To change extension of compressed file, use <code>compressext</code></li>\n</ul>\n<p>|------</p></th>\n<th align=\"left\"><p><code>dateext</code></p></th>\n<th align=\"left\"><p>Use YYYYMMDD format instead of just tacking on numbers (like <code>.0</code>, <code>.1</code> and so on) to the rotated files. |------</p></th>\n<th align=\"left\"><p><code>mail &lt;recipient&gt;</code></p></th>\n<th align=\"left\"><p>Email recipient the file that will be deleted after a rotation cycle |------</p></th>\n<th align=\"left\"><p><code>create &lt;mode&gt; &lt;owner&gt; &lt;group&gt;</code></p></th>\n<th align=\"left\"><p>Create logfiles with the specified permissions and owner:group attributes. |------</p></th>\n<th align=\"left\"><p><code>olddir &lt;directory&gt;</code></p></th>\n<th align=\"left\"><p>Move all but the newest log file to this directory (nice to keep things organized)</p></th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n\n### Other (kinda important) options\n\nYou'll see these used with Apache, for instance.\n\n<table style=\"width:10%;\">\n<colgroup>\n<col width=\"2%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n<col width=\"0%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th align=\"left\"><p>Option</p></th>\n<th align=\"left\"><p>Purpose |-------</p></th>\n<th align=\"left\"><p><code>prerotate</code></p></th>\n<th align=\"left\"><p>Execute the a script <em>before</em> rotating a log. Should end this with <code>endscript</code>. |-------</p></th>\n<th align=\"left\"><p><code>postrotate</code></p></th>\n<th align=\"left\"><p>Execute the a script <em>after</em> rotating a log. Should end this with <code>endscript</code>. |-------</p></th>\n<th align=\"left\"><p><code>sharedscripts</code></p></th>\n<th align=\"left\"><p>Make sure that the script(s) specified in <code>prerotate</code> and/or <code>postrotate</code> run just <em>once</em> (i.e. not for <em>every</em> logfile) |------</p></th>\n<th align=\"left\"><p><code>delaycompress</code></p></th>\n<th align=\"left\"><p>Don't compress yesterday's logfile (if daily... you get the picture)</p></th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n\nExample\n-------\n\nHere's a real-world application of the above. I want to rotate an\nalready huge log of OpenVPN connections (\\~32M in size) like so:\n\n-   I want to maintain **60 days** worth of logs\n-   Logfile **size doesn't matter** to me\n-   The files should be rotated in **YYYYMMDD** format\n-   They should be **compressed** (the default `gzip -9` is fine)\n-   They should be **organized**; older logfiles should be **in a\n    separate directory**\n\nThe logfile is at `/var/log/openvpn/connections.log`. Here's the\nconfiguration file I created for the above. It's\n`/etc/logrotate.d/openvpn`:\n\n` /var/log/openvpn/connections.log {`  \n`     daily`  \n`     rotate 60`  \n`     dateext`  \n`     compress`  \n`     olddir /var/log/openvpn/old`  \n` `  \n`     nomail`  \n`     missingok`  \n`     notifempty`  \n`     delaycompress`  \n`     create 640 root root`  \n` }`\n\nTo test this, I run:\n\n` logrotate -d /etc/logrotate.d/openvpn`\n\nThe `-d` switch runs it in verbose, debug, dry-run mode (i.e. nothing\nactually happens.)\n\nOther Stuff\n-----------\n\n### Leopard and Snow Leopard\n\nThese use a new utility called `newsyslog`. It is invoked every minute\nby:\n\n` /System/Library/LaunchDaemons/com.apple.newsyslog.plist`\n\nThe config file for this is `/etc/newsyslog.conf` and is kinda nicer\nthan `logrotate`'s config :)\n\nSources\n-------\n\n-   [Logrotate\n    Examples](http://www.thegeekstuff.com/2010/07/logrotate-examples/)\n-   [Using logrotate to manage log\n    files](http://linuxers.org/howto/howto-use-logrotate-manage-log-files)\n-   [Rotating Linux log\n    files](http://www.ducea.com/2006/06/06/rotating-linux-log-files-part-2-logrotate/)\n\n[Category:Nikhil's Notes](Category:Nikhil's_Notes \"wikilink\")\n[Category:From a past sysadmin\nlife](Category:From_a_past_sysadmin_life \"wikilink\")\n"
    }
  ],
  "sizeInBytes": 7693,
  "source": "This is a quick overview of `logrotate` which... umm... rotates log\nfiles. This was written for CentOS/RHEL 5.5.\n\nPertinent Files & Directories\n-----------------------------\n\n|                    File/Dir                   |                                                                  Purpose                                                                   |\n|-----------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|\n| `/usr/sbin/logrotate`                         | The command itself.                                                                                                                        |\n| `/etc/cron.daily/logrotate`                   | Bash script that executes the `logrotate` command every day.                                                                               |\n| `/etc/logrotate.conf` and `/etc/logrotate.d/` | Rotation defaults if they are not defined for specific daemons. You can add rotate configs to this file, or put them in `/etc/logrotate.d` |\n| `/var/lib/logrotate.status`                   | Show when the specified log files were last rotated.                                                                                       |\n\nLogrotate Options\n-----------------\n\nQuite simple, really. The `man` page elucidates all available options.\nHere's a quick table of what the most commonly used ones do.\n\n|              Option             |                                                              Purpose                                                               |\n|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `rotate <number>`               | Keep specified number of logfiles before they are deleted and/or emailed to admin                                                  |\n| `size=<number>`                 | Rotate logs when they reach this size.                                                                                             |\n|                                 | This is done ''without regard'' for the last rotated time.                                                                         |\n|                                 | Use `minsize <number>` if you'd like to balance both time and size.                                                                |\n|                                 | Bytes are used without a specifier. 100k, 100M are also fine.                                                                      |\n| `daily`                         | Rotate daily. This is the default minimum granularity, unless you move `/etc/cron.daily/logrotate` to `/etc/cron.hourly/logrotate` |\n| `weekly`                        | Rotate weekly                                                                                                                      |\n| `monthly`                       | Rotate monthly                                                                                                                     |\n| `notifempty`                    | Don't rotate if empty (the reverse, `ifempty`, is default)                                                                         |\n| `missingok`                     | If log file is missing for some reason, move on without error                                                                      |\n| `compress`                      | Compress logfile after rotation.                                                                                                   |\n|                                 | Default is `gzip` with `-9` (maximum) compression.                                                                                 |\n|                                 | The choice of compression program can be changed with `compresscmd` (e.g. `compresscmd bzip2`).                                    |\n|                                 | To pass options (like compression level), use `compressoptions`.                                                                   |\n|                                 | To change extension of compressed file, use `compressext`                                                                          |\n| `dateext`                       | Use YYYYMMDD format instead of just tacking on numbers (like `.0`, `.1` and so on) to the rotated files.                           |\n| `mail <recipient>`              | Email recipient the file that will be deleted after a rotation cycle                                                               |\n| `create <mode> <owner> <group>` | Create logfiles with the specified permissions and owner:group attributes.                                                         |\n| `olddir <directory>`            | Move all but the newest log file to this directory (nice to keep things organized)                                                 |\n\n### Other (kinda important) options\n\nYou'll see these used with Apache, for instance.\n\n|      Option     |                                                           Purpose                                                            |\n|-----------------|------------------------------------------------------------------------------------------------------------------------------|\n| `prerotate`     | Execute the a script ''before'' rotating a log. Should end this with `endscript`.                                            |\n| `postrotate`    | Execute the a script ''after'' rotating a log. Should end this with `endscript`.                                             |\n| `sharedscripts` | Make sure that the script(s) specified in `prerotate` and/or `postrotate` run just ''once'' (i.e. not for ''every'' logfile) |\n| `delaycompress` | Don't compress yesterday's logfile (if daily... you get the picture)                                                         |\n\nExample\n-------\n\nHere's a real-world application of the above. I want to rotate an\nalready huge log of OpenVPN connections (\\~32M in size) like so:\n\n*   I want to maintain **60 days** worth of logs\n*   Logfile **size doesn't matter** to me\n*   The files should be rotated in **YYYYMMDD** format\n*   They should be **compressed** (the default `gzip -9` is fine)\n*   They should be **organized**; older logfiles should be **in a\n    separate directory**\n\nThe logfile is at `/var/log/openvpn/connections.log`. Here's the\nconfiguration file I created for the above. It's `/etc/logrotate.d/openvpn`:\n\n    /var/log/openvpn/connections.log {  \n        daily  \n        rotate 60  \n        dateext  \n        compress  \n        olddir /var/log/openvpn/old  \n      \n        nomail  \n        missingok  \n        notifempty  \n        delaycompress  \n        create 640 root root  \n    }\n\nTo test this, I run:\n\n    logrotate -d /etc/logrotate.d/openvpn\n\nThe `-d` switch runs it in verbose, debug, dry-run mode (i.e. nothing\nactually happens.)\n\nOther Stuff\n-----------\n\n### Leopard and Snow Leopard\n\nThese use a new utility called `newsyslog`. It is invoked every minute\nby:\n\n    /System/Library/LaunchDaemons/com.apple.newsyslog.plist\n\nThe config file for this is `/etc/newsyslog.conf` and is kinda nicer\nthan `logrotate`'s config :)\n\nSources\n-------\n\n-   [Logrotate Examples](http://www.thegeekstuff.com/2010/07/logrotate-examples/)\n-   [Using logrotate to manage log files](http://linuxers.org/howto/howto-use-logrotate-manage-log-files)\n-   [Rotating Linux log files](http://www.ducea.com/2006/06/06/rotating-linux-log-files-part-2-logrotate/)\n",
  "title": "Logrotate Notes",
  "untracked": false,
  "uri": "/Logrotate_Notes",
  "relativePath": "Logrotate Notes.md"
}
