{"id":4772,"date":"2026-03-19T12:49:24","date_gmt":"2026-03-19T12:49:24","guid":{"rendered":"https:\/\/netguide.io\/linux\/?p=4772"},"modified":"2026-03-19T12:49:25","modified_gmt":"2026-03-19T12:49:25","slug":"apache2-logrotate-ohne-restart-der-guide-zu-copytruncate","status":"publish","type":"post","link":"https:\/\/netguide.io\/linux\/de\/apache2-logrotate-ohne-restart-der-guide-zu-copytruncate\/","title":{"rendered":"Apache2 Logrotate ohne Restart: Der Guide zu\u00a0copytruncate"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Jeder Administrator kennt das: Logfiles wachsen unaufh\u00f6rlich. Standardm\u00e4\u00dfig verschiebt&nbsp;<strong>Logrotate<\/strong>&nbsp;die alte Logdatei und weist Apache \u00fcber ein Signal (<code>systemctl reload apache2<\/code>) an, eine neue Datei zu \u00f6ffnen. Das funktioniert meistens reibungslos, aber in Hochverf\u00fcgbarkeitsumgebungen oder bei extrem sensiblen Setups m\u00f6chte man manchmal selbst den kleinsten &#8220;Schluckauf&#8221; beim Reload vermeiden.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hier kommt die Option&nbsp;<strong><code>copytruncate<\/code><\/strong>&nbsp;ins Spiel.<\/p>\n\n\n\n<!DOCTYPE html>\n<html lang=\"de\">\n<head>\n<style>\n    :root {\n        --bg-color: #1e1e1e;\n        --text-color: #d4d4d4;\n        --accent-color: #4fc1ff;\n        --success-color: #6a9955;\n        --warn-color: #ce9178;\n        --terminal-header: #333333;\n    }\n\n    .terminal-container {\n        font-family: 'Fira Code', 'Courier New', Courier, monospace;\n        background-color: var(--bg-color);\n        color: var(--text-color);\n        border-radius: 8px;\n        box-shadow: 0 10px 30px rgba(0,0,0,0.5);\n        max-width: 700px;\n        margin: 20px auto;\n        overflow: hidden;\n        border: 1px solid #444;\n    }\n\n    .terminal-header {\n        background-color: var(--terminal-header);\n        padding: 10px;\n        display: flex;\n        gap: 8px;\n        align-items: center;\n    }\n\n    .dot { width: 12px; height: 12px; border-radius: 50%; }\n    .red { background: #ff5f56; }\n    .yellow { background: #ffbd2e; }\n    .green { background: #27c93f; }\n\n    .terminal-window {\n        padding: 20px;\n        min-height: 350px;\n    }\n\n    .line { margin-bottom: 8px; line-height: 1.4; opacity: 0; }\n    .command { color: var(--accent-color); }\n    .system { color: var(--success-color); }\n    .file-status { border-left: 2px solid #555; padding-left: 15px; margin: 15px 0; }\n\n    .bar-container {\n        width: 100%;\n        background: #333;\n        height: 10px;\n        border-radius: 5px;\n        margin-top: 5px;\n    }\n\n    .bar {\n        height: 100%;\n        width: 0%;\n        background: var(--accent-color);\n        transition: width 0.5s ease;\n    }\n\n    \/* Animation Steps *\/\n    @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }\n    .visible { animation: fadeIn 0.3s forwards; }\n\n    .status-badge {\n        display: inline-block;\n        padding: 2px 8px;\n        border-radius: 4px;\n        font-size: 0.8em;\n        font-weight: bold;\n        background: #2d4a2d;\n        color: #81b88b;\n    }\n<\/style>\n<\/head>\n<body>\n\n<div class=\"terminal-container\">\n    <div class=\"terminal-header\">\n        <div class=\"dot red\"><\/div>\n        <div class=\"dot yellow\"><\/div>\n        <div class=\"dot green\"><\/div>\n        <span style=\"margin-left: 10px; font-size: 0.9em; color: #888;\">bash \u2014 logrotate simulation<\/span>\n    <\/div>\n    <div class=\"terminal-window\" id=\"terminal-content\">\n        <\/div>\n<\/div>\n\n<script>\n    const content = document.getElementById('terminal-content');\n    \n    const steps = [\n        { text: '<span class=\"status-badge\">SERVICE: RUNNING<\/span> Apache2 PID: 1234 active', type: 'system' },\n        { text: '<span class=\"command\">root@server:~#<\/span> logrotate -f \/etc\/logrotate.d\/apache2', type: 'command' },\n        { text: 'Checking log size of <span class=\"command\">access.log<\/span>...', type: 'text' },\n        { text: '<div class=\"file-status\"><b>access.log (Inode: 9999)<\/b><div class=\"bar-container\"><div class=\"bar\" style=\"width: 90%; background: #ce9178;\"><\/div><\/div>94.2 MB [##########]<\/div>', type: 'text' },\n        { text: '<span class=\"system\">[STEP 1]<\/span> Copying content to access.log.1...', type: 'text' },\n        { text: '<div class=\"file-status\"><b>access.log.1 (Inode: 8888)<\/b><div class=\"bar-container\"><div class=\"bar\" style=\"width: 90%; background: #4fc1ff;\"><\/div><\/div>94.2 MB [##########]<\/div>', type: 'text' },\n        { text: '<span class=\"system\">[STEP 2]<\/span> Truncating original file (copytruncate)...', type: 'text' },\n        { text: '<div class=\"file-status\"><b>access.log (Inode: 9999)<\/b><div class=\"bar-container\"><div class=\"bar\" style=\"width: 2%; background: #6a9955;\"><\/div><\/div>0.0 KB [ ]<\/div>', type: 'text' },\n        { text: '<span class=\"system\">SUCCESS:<\/span> Rotation finished. Apache PID 1234 never stopped.', type: 'system' },\n        { text: '<span class=\"command\">root@server:~#<\/span> _', type: 'command' }\n    ];\n\n    let currentStep = 0;\n\n    function addStep() {\n        if (currentStep < steps.length) {\n            const div = document.createElement('div');\n            div.className = 'line visible';\n            div.innerHTML = steps[currentStep].text;\n            content.appendChild(div);\n            currentStep++;\n            setTimeout(addStep, 1200);\n        } else {\n            \/\/ Restart after 5 seconds\n            setTimeout(() => {\n                content.innerHTML = '';\n                currentStep = 0;\n                addStep();\n            }, 5000);\n        }\n    }\n\n    addStep();\n<\/script>\n\n<\/body>\n<\/html>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Wie funktioniert&nbsp;<code>copytruncate<\/code>&nbsp;technisch?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Normalerweise arbeitet Logrotate nach dem &#8220;Move-and-Signal&#8221;-Prinzip: Die Datei&nbsp;<code>access.log<\/code>&nbsp;wird in&nbsp;<code>access.log.1<\/code>&nbsp;umbenannt, und der Apache-Prozess wird informiert, dass er ein neues File anlegen soll.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bei&nbsp;<code>copytruncate<\/code>&nbsp;bleibt die urspr\u00fcngliche Datei physisch immer dieselbe (die Inode \u00e4ndert sich nicht). Der Ablauf sieht so aus:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Copy:<\/strong>\u00a0Logrotate erstellt eine exakte Kopie der aktuellen Logdatei (z. B.\u00a0<code>access.log<\/code>\u00a0wird nach\u00a0<code>access.log.1<\/code>\u00a0kopiert).<\/li>\n\n\n\n<li><strong>Truncate:<\/strong>\u00a0Direkt nach dem erfolgreichen Kopieren wird die urspr\u00fcngliche Logdatei auf 0 Bytes gek\u00fcrzt (geleert), anstatt sie zu l\u00f6schen oder zu verschieben.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Da Apache die Datei \u00fcber einen sogenannten File-Descriptor offen h\u00e4lt, schreibt er einfach weiter in dieselbe Datei. F\u00fcr den Webserver sieht es so aus, als w\u00e4re die Datei pl\u00f6tzlich leer geworden. Ein Reload des Dienstes ist somit nicht erforderlich.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Die Konfiguration: So setzt du es um<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Die Konfiguration f\u00fcr Apache-Logs findest du unter Linux normalerweise im Verzeichnis&nbsp;<code>\/etc\/logrotate.d\/apache2<\/code>. Um auf&nbsp;<code>copytruncate<\/code>&nbsp;umzustellen, musst du die Datei bearbeiten.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Schritt-f\u00fcr-Schritt-Anleitung:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u00d6ffne die Konfigurationsdatei mit Root-Rechten:<code>sudo nano \/etc\/logrotate.d\/apache2<\/code><\/li>\n\n\n\n<li>Ersetze die Standardanweisungen (oft\u00a0<code>sharedscripts<\/code>\u00a0kombiniert mit einem\u00a0<code>postrotate<\/code>-Block) durch\u00a0<code>copytruncate<\/code>.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Ein fertiges Beispiel k\u00f6nnte so aussehen:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/var\/log\/apache2\/*.log {\n    daily\n    missingok\n    rotate 14\n    compress\n    delaycompress\n    notifempty\n    create 640 root adm\n\n    # Hier ist die entscheidende Zeile:\n    copytruncate\n\n    # Der postrotate-Block mit 'reload' kann nun entfernt werden\n}\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Speichere die Datei und teste die Konfiguration auf Syntaxfehler:<code>sudo logrotate -d \/etc\/logrotate.d\/apache2<\/code><em>(Der Parameter\u00a0<code>-d<\/code>\u00a0steht f\u00fcr &#8220;Debug&#8221; &#8211; es wird nichts ver\u00e4ndert, nur simuliert.)<\/em><\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Vor- und Nachteile von&nbsp;<code>copytruncate<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Nichts in der IT ist ohne Kompromisse. Hier ist ein kurzer \u00dcberblick, wann du diese Methode w\u00e4hlen solltest.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td><strong>Feature<\/strong><\/td><td><strong>Vorteil<\/strong><\/td><td><strong>Nachteil<\/strong><\/td><\/tr><\/thead><tbody><tr><td><strong>Dienst-Stabilit\u00e4t<\/strong><\/td><td>Absolut kein Restart\/Reload von Apache n\u00f6tig.<\/td><td>&#8211;<\/td><\/tr><tr><td><strong>Datenintegrit\u00e4t<\/strong><\/td><td>&#8211;<\/td><td><strong>Minimaler Datenverlust m\u00f6glich:<\/strong>&nbsp;In der Millisekunde zwischen Copy und Truncate geschriebene Logs gehen verloren.<\/td><\/tr><tr><td><strong>Einfachheit<\/strong><\/td><td>Simpler Workflow ohne Signale an Prozesse.<\/td><td>Bei extrem gro\u00dfen Logfiles (viele GB) dauert der Kopiervorgang lange.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>Wichtig!<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Achtung beim Datenverlust:<\/strong>&nbsp;Da der Prozess des Kopierens und anschlie\u00dfenden Leerens nicht absolut atomar ist, k\u00f6nnen Log-Eintr\u00e4ge, die genau in diesem winzigen Zeitfenster eintreffen, im &#8220;Nirvana&#8221; landen. F\u00fcr normale Webseiten ist das vernachl\u00e4ssigbar, f\u00fcr rechtssicheres Logging oder Finanztransaktionen jedoch kritisch.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Fazit<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>copytruncate<\/code>&nbsp;ist die ideale L\u00f6sung, wenn du Apache2-Logs rotieren willst, ohne den Dienst auch nur f\u00fcr eine Millisekunde durch einen Reload zu beeinflussen. Es ist besonders n\u00fctzlich f\u00fcr Anwendungen, die empfindlich auf Signal-Handler reagieren oder wenn du eine sehr einfache Logrotate-Logik ohne komplexe Skripte bevorzugst.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jeder Administrator kennt das: Logfiles wachsen unaufh\u00f6rlich. Standardm\u00e4\u00dfig verschiebt&nbsp;Logrotate&nbsp;die alte Logdatei und weist Apache \u00fcber ein Signal (systemctl reload apache2) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4773,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[276,9],"tags":[491,493,87,67,489,91],"class_list":["post-4772","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-betriebssysteme","category-linux","tag-apache","tag-apache2","tag-debian","tag-linux","tag-logrotate","tag-ubuntu"],"uagb_featured_image_src":{"full":["https:\/\/netguide.io\/linux\/wp-content\/uploads\/sites\/2\/2026\/03\/logrotate-scaled.png",2560,1396,false],"thumbnail":["https:\/\/netguide.io\/linux\/wp-content\/uploads\/sites\/2\/2026\/03\/logrotate-150x150.png",150,150,true],"medium":["https:\/\/netguide.io\/linux\/wp-content\/uploads\/sites\/2\/2026\/03\/logrotate-300x164.png",300,164,true],"medium_large":["https:\/\/netguide.io\/linux\/wp-content\/uploads\/sites\/2\/2026\/03\/logrotate-768x419.png",768,419,true],"large":["https:\/\/netguide.io\/linux\/wp-content\/uploads\/sites\/2\/2026\/03\/logrotate-1024x559.png",1024,559,true],"1536x1536":["https:\/\/netguide.io\/linux\/wp-content\/uploads\/sites\/2\/2026\/03\/logrotate-scaled.png",1536,838,false],"2048x2048":["https:\/\/netguide.io\/linux\/wp-content\/uploads\/sites\/2\/2026\/03\/logrotate-scaled.png",2048,1117,false]},"uagb_author_info":{"display_name":"tobias.pries","author_link":"https:\/\/netguide.io\/linux\/author\/tobias-pries\/"},"uagb_comment_info":0,"uagb_excerpt":"Jeder Administrator kennt das: Logfiles wachsen unaufh\u00f6rlich. Standardm\u00e4\u00dfig verschiebt&nbsp;Logrotate&nbsp;die alte Logdatei und weist Apache \u00fcber ein Signal (systemctl reload apache2) [&hellip;]","_links":{"self":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/posts\/4772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/comments?post=4772"}],"version-history":[{"count":1,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/posts\/4772\/revisions"}],"predecessor-version":[{"id":4775,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/posts\/4772\/revisions\/4775"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/media\/4773"}],"wp:attachment":[{"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/media?parent=4772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/categories?post=4772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netguide.io\/linux\/wp-json\/wp\/v2\/tags?post=4772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}