{"id":794,"date":"2026-08-03T22:50:03","date_gmt":"2026-08-03T22:50:03","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=794"},"modified":"2026-08-03T22:50:03","modified_gmt":"2026-08-03T22:50:03","slug":"logrotate-disk-space-management-vps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/","title":{"rendered":"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A full disk is one of the most common causes of VPS outages \u2014 and it is almost always self-inflicted. Application logs, database binlogs, and package manager caches grow silently until <code>\/<\/code> hits 100%, at which point services start failing with cryptic <code>No space left on device<\/code> errors, SSH logins break, and even <code>rm<\/code> refuses to work for the root user in some configurations. The fix is a two-part routine: find what is consuming space, then rotate and prune logs automatically with logrotate and journald limits. This guide covers both, with configs you can copy straight onto a Debian or Ubuntu VPS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The good news is that the tools are built into every Linux distribution \u2014 no extra agents or paid services required. If you are evaluating hosts for a workload that generates heavy logs, <a href=\"https:\/\/virtualserversvps.com\/#providers\">our comparison table<\/a> includes plans with larger NVMe allocations, which gives you more headroom before rotation policies matter.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Find What Is Eating the Disk<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Start with filesystem usage, then drill down:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df -h                              # which mount is full\ndu -xh --max-depth=1 \/ | sort -h   # largest top-level directories\ndu -xh --max-depth=2 \/var | sort -h | tail -10   # largest subdirs\nfind \/var\/log -type f -size +100M -exec ls -lh {} \\;   # huge log files<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a typical web VPS, <code>\/var\/log<\/code> and <code>\/var\/lib\/docker<\/code> are the usual suspects, followed by MySQL&#8217;s <code>ib_logfile*<\/code> and binary logs. The <code>-x<\/code> flag keeps <code>du<\/code> on one filesystem, so a large <code>\/proc<\/code> or mount point does not skew the numbers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Logrotate \u2014 Rotation, Compression, Retention<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Logrotate runs daily via cron and processes the configs in <code>\/etc\/logrotate.d\/<\/code> (plus the global defaults in <code>\/etc\/logrotate.conf<\/code>). The core directive set is small but powerful:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \/etc\/logrotate.d\/myapp\n\/var\/log\/myapp\/*.log {\n    daily\n    rotate 14          # keep 14 rotated files\n    compress           # gzip old logs\n    delaycompress      # keep yesterday's log uncompressed\n    missingok\n    notifempty\n    create 0640 www-data www-data\n    postrotate\n        systemctl reload myapp\n    endscript\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Two details matter in production. First, <code>create<\/code> restores the correct owner and permissions on the fresh log file so the app keeps writing after rotation. Second, the <code>postrotate<\/code> script tells the service to reopen its log handles \u2014 Nginx and Apache need <code>reload<\/code> or <code>USR1<\/code>; systemd services with <code>StandardOutput=append:<\/code> often need a restart instead. For services that reopen files on <code>SIGHUP<\/code>, use <code>copytruncate<\/code> instead: it copies and truncates without touching the file handle, at the cost of a few lost lines.\n\nWhen the log file is owned by a service user (common for PHP-FPM or containerized apps), add <code>su www-data www-data<\/code> to the config so rotation, compression, and <code>create<\/code> run as that user \u2014 otherwise logrotate may run as root and produce files the app cannot write to. If several services share one directory, wrap their <code>postrotate<\/code> scripts in <code>sharedscripts<\/code> so the reload runs once for the whole block rather than once per file. And if a service writes a high-volume log that must never grow beyond a fixed size regardless of time, replace <code>daily<\/code> with <code>size 100M<\/code> \u2014 rotation then triggers on file size instead of the clock.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Cap journald Before It Caps Your Disk<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">systemd-journald writes its own binary journal under <code>\/var\/log\/journal<\/code> and, left alone, can grow without bound. Set explicit size limits in <code>\/etc\/systemd\/journald.conf<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[Journal]\nSystemMaxUse=500M        # cap the journal at 500 MB total\nSystemMaxFileSize=100M   # individual file size before rotation\nMaxRetentionSec=2week    # drop entries older than two weeks\nCompress=yes<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apply with <code>systemctl restart systemd-journald<\/code> (or <code>systemctl kill -s USR1 systemd-journald<\/code> for a less disruptive reload). The journal will compact itself down to the new limit on the next rotation, freeing space without losing recent entries. A 500 MB cap plus two-week retention is a good default for most VPS workloads.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Prune the Other Log Producers<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Package caches:<\/strong> <code>apt clean<\/code> (or <code>dnf clean all<\/code>) after upgrades; keep <code>apt<\/code>&#8216;s lists under control with <code>apt-get autoclean<\/code>.<\/li><li><strong>Docker:<\/strong> add <code>{\"log-driver\":\"json-file\",\"log-opts\":{\"max-size\":\"10m\",\"max-file\":\"3\"}}<\/code> to <code>\/etc\/docker\/daemon.json<\/code>, then <code>docker system prune -af<\/code> weekly for dangling images and build cache.<\/li><li><strong>MySQL\/MariaDB:<\/strong> set <code>expire_logs_days=7<\/code> (or <code>binlog_expire_logs_seconds=604800<\/code> on 8.0+) to prune binary logs automatically.<\/li><li><strong>Old kernels:<\/strong> <code>apt autoremove --purge<\/code> removes superseded kernel packages that accumulate in <code>\/boot<\/code>.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Verify Rotation Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Never trust a rotation policy you have not tested. Logrotate ships with a dry-run mode and a force flag:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>logrotate -d \/etc\/logrotate.conf     # dry run: show what WOULD happen\nlogrotate -f \/etc\/logrotate.conf     # force rotation now\ndu -sh \/var\/log                      # confirm the directory shrank<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then add a simple disk-usage alert so you hear about the next slow leak before users do: a cron job that emails you when <code>\/<\/code> passes 80%, or a one-line check in your existing monitoring script. Together with logrotate, journald caps, and the prune list above, that is a complete disk-space routine that runs itself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Automating log rotation and disk monitoring is one of those admin tasks that quietly prevents the most embarrassing outage class there is. For the storage headroom that makes the whole system comfortable, <a href=\"https:\/\/virtualserversvps.com\/#providers\">see the full specs and pricing<\/a> on plans with larger NVMe allocations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Running these tools requires full shell access and cron control on an unmanaged server. <a href=\"https:\/\/interserver.net\/vps?id=1067805&amp;sid=virtualserversvps\" target=\"_blank\" rel=\"noreferrer noopener sponsored\">InterServer&#8217;s VPS plans<\/a> give you root access and flat pricing, so your log-rotation routine runs exactly as configured \u2014 no platform-level log managers getting in the way.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>A full disk is one of the most common causes of VPS outages \u2014 and it is almost always self-inflicted. Application logs, database binlogs, and package manager caches grow silently&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-794","post","type-post","status-publish","format-standard","hentry","category-vps-guides-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk\" \/>\n<meta property=\"og:description\" content=\"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-03T22:50:03+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/\",\"name\":\"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-08-03T22:50:03+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/","og_locale":"en_US","og_type":"article","og_title":"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk","og_description":"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk","og_url":"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-08-03T22:50:03+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/","url":"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/","name":"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-08-03T22:50:03+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/logrotate-disk-space-management-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Logrotate and Disk Space Management on a VPS: Keep Logs Useful Without Filling the Disk"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=794"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions"}],"predecessor-version":[{"id":795,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/794\/revisions\/795"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}