{
  "created": "2015-12-20T19:56:47Z",
  "hierarchy": [
    {
      "name": "ROOT",
      "type": "folder",
      "uri": "/ROOT"
    },
    {
      "name": "Logrotate Notes",
      "type": "article",
      "uri": "Logrotate_Notes"
    }
  ],
  "html": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"/><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/><meta name=\"name\" content=\"Nikhil's Personal Wiki\"/><meta name=\"description\" content=\"Logrotate Notes – Nikhil's Personal Wiki\"/><meta name=\"author\" content=\"Nikhil Anand\"/><meta name=\"theme-color\" content=\"#ffe9a00\"/><meta property=\"og:title\" content=\"Logrotate Notes – Nikhil's Personal Wiki\"/><meta property=\"og:description\" content=\"Logrotate Notes – Nikhil's Personal Wiki\"/><meta property=\"og:type\" content=\"website\"/><meta property=\"og:image\" content=\"/img/logo512.png\"/><meta property=\"og:site_name\" content=\"Nikhil's Personal Wiki\"/><link rel=\"og:image\" href=\"/img/logo512.png\"/><link rel=\"icon\" href=\"/img/favicon.png\"/><link rel=\"apple-touch-icon\" href=\"/img/logo192.png\"/><link rel=\"stylesheet\" href=\"/css/styles.css\"/><title>Logrotate Notes – Nikhil's Personal Wiki</title><script defer data-domain=\"wiki.nikhil.io\" src=\"https://plausible.io/js/plausible.js\"></script></head><body><noscript>👉 A few things won't work if you have JavaScript disabled.</noscript><div class=\"container article\"><header><nav><ul><li><a href=\"/archive\" class title=\"Archive\"><span>Archive</span></a></li><li><a href=\"/Home\" class title=\"Home\"><span>Home</span></a></li><li><a href=\"/random\" class title=\"See a random article\"><span>Random</span></a></li><li><a href=\"/Logrotate_Notes/raw.txt\" title=\"View Source\"><span>Raw</span></a></li><li><a href=\"/Logrotate_Notes/revisions\" class title=\"View revisions\"><span>Revisions</span></a></li><li><a href=\"/Logrotate_Notes/index.json\" title=\"View JSON Object\"><span>JSON</span></a></li></ul></nav></header><main><article><article-hierarchy><ul><li><a data-entity-type=\"folder\" href=\"/ROOT\" title=\"ROOT\">Root</a></li><li><a data-entity-type=\"article\" href=\"/Logrotate_Notes\" title=\"Logrotate Notes\">Logrotate Notes</a></li></ul></article-hierarchy><header><h1>Logrotate Notes</h1></header><article-content><p>This is a quick overview of <code>logrotate</code> which&hellip; umm&hellip; rotates log files. This was written for CentOS/RHEL 5.5.</p>\n<h2 id=\"pertinent-files--directories\">Pertinent Files &amp; Directories</h2>\n<table-wrapper>\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</table-wrapper>\n<h2 id=\"logrotate-options\">Logrotate Options</h2>\n<p>Quite simple, really. The <code>man</code> page elucidates all available options. Here&rsquo;s a quick table of what the most commonly used ones do.</p>\n<table-wrapper>\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</table-wrapper>\n<h3 id=\"other-kinda-important-options\">Other (kinda important) options</h3>\n<p>You&rsquo;ll see these used with Apache, for instance.</p>\n<table-wrapper>\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</table-wrapper>\n<h2 id=\"example\">Example</h2>\n<p>Here&rsquo;s a real-world application of the above. I want to rotate an already 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 configuration 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 actually happens.)</p>\n<h2 id=\"other-stuff\">Other Stuff</h2>\n<h3 id=\"leopard-and-snow-leopard\">Leopard and Snow Leopard</h3>\n<p>These use a new utility called <code>newsyslog</code>. It is invoked every minute by:</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 than <code>logrotate</code>&rsquo;s config :)</p>\n<h2 id=\"sources\">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</article-content></article></main><footer><p></p><ul><li>7,604 bytes</li><li>Created on Sunday, 20 December 2015 at 19:56 UTC</li><li>Modified on Thursday, 28 May 2026 at 13:06 UTC</li><br/><li><a href=\"https://github.com/afreeorange/wiki.nikhil.io.articles/edit/master/Logrotate Notes.md\" title=\"Edit this article\">Edit this article</a></li><li><a href=\"https://github.com/afreeorange/bock\" title=\"View the project that generates this wiki on Github\"><span>bock 6.3.0-alpha</span></a></li></ul></footer></div><script src=\"/js/table-sort.js\" defer></script><script type=\"text/javascript\">\n        document.body.addEventListener(\n          \"keypress\", (e) => e.key === \"f\"\n          ? window.location.assign(\"/archive\")\n          : null);\n      </script></body></html>",
  "id": "f5aaadd5-1ce8-52da-9eae-db03957462c8",
  "modified": "2026-05-28T13:06:19Z",
  "revisions": [
    {
      "authorEmail": "mail@nikhil.io",
      "authorName": "Nikhil Anand",
      "date": "2026-05-28T13:06:19Z",
      "id": "0a776ea7319ba88b21a667a8fa8b6baa85cd0c0c",
      "shortId": "0a776ea7",
      "subject": "Formatting fixes -- Claude\n",
      "content": "This is a quick overview of `logrotate` which... umm... rotates log files. This was written for CentOS/RHEL 5.5.\n\n## Pertinent Files & Directories\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\n## Logrotate Options\n\nQuite simple, really. The `man` page elucidates all available options. Here'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\n## Example\n\nHere's a real-world application of the above. I want to rotate an already 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 configuration 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 actually happens.)\n\n## Other Stuff\n\n### Leopard and Snow Leopard\n\nThese use a new utility called `newsyslog`. It is invoked every minute by:\n\n    /System/Library/LaunchDaemons/com.apple.newsyslog.plist\n\nThe config file for this is `/etc/newsyslog.conf` and is kinda nicer than `logrotate`'s config :)\n\n## Sources\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": "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": 7604,
  "source": "This is a quick overview of `logrotate` which... umm... rotates log files. This was written for CentOS/RHEL 5.5.\n\n## Pertinent Files & Directories\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\n## Logrotate Options\n\nQuite simple, really. The `man` page elucidates all available options. Here'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\n## Example\n\nHere's a real-world application of the above. I want to rotate an already 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 configuration 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 actually happens.)\n\n## Other Stuff\n\n### Leopard and Snow Leopard\n\nThese use a new utility called `newsyslog`. It is invoked every minute by:\n\n    /System/Library/LaunchDaemons/com.apple.newsyslog.plist\n\nThe config file for this is `/etc/newsyslog.conf` and is kinda nicer than `logrotate`'s config :)\n\n## Sources\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"
}
