Contents
- Cleaning starts with deciding what can go.
- Measure consumption and determine the protocol manager
- Delete the journal with its own tool
- Design permanent retention by storage type
- Solve text logs by rotating and reopening properly
- Deleted open files and unusual other claims
- Also fix the reason for the excessive growth
- Cleaning verification: location, history and new events
- Frequently asked questions
Cleaning starts with deciding what can go.
System logs help explain an outage, security event, or application error. Therefore, deleting them should not be the first automatic response to a full disk. First, determine which file system is full, who is creating the data, and what history is needed for operation and approved retention. For an ongoing incident, preserve relevant documentation before cleaning up.
Logs are not one-size-fits-all formats. Journals use their own structured files, traditional services can write to text, and containers can have a special logging driver. Additionally, database WALs or binlogs serve a different purpose than regular access logs, and deleting them can break recovery or replication. Don't judge by the .log extension alone.
In case of acute space shortage, create a backup to a suitable separate storage, not as another large archive on the same full volume. The copy should preserve the necessary times, content and access restrictions. Non-public logs should not be available over the web just because it is so easy to download the file.
Measure consumption and determine the protocol manager
Check the specific target volume and inode count. Then work your way from the general directory to the source you found. The depth of du's listing limits the view, not necessarily the number of items read, so choose a reasonable range on a large tree. Record the state before the change for later comparison.
df -hT /var/log
df -i /var/log
sudo du -x -h --max-depth=1 /var/log
sudo journalctl --disk-usageJournalctl --disk-usage shows journal usage, not the sum of all application files on the server. It does not automatically manage a large website access log. For a container, first determine the logging backend used and its management. Manual intervention in the engine's internal files can bypass proper accounting or interrupt logging.
If the total number of available files does not explain df, check for open deleted files and other storage mechanisms. It is not advisable to delete additional directories until you understand the difference. An open deleted file may still be taking up space even if it is no longer listed by its regular name.
Delete the journal with its own tool
For systemd journaling, use journalctl and supported retention. Vacuum removes older archived files according to the selected limit; active journaling behaves differently. Therefore, a specific size requirement may not exactly match the final value of all currently active data. It is not a good idea to manually truncate or edit binary journal files.
# Nejdřív čtecí kontrola rozsahu a spotřeby:
sudo journalctl --list-boots
sudo journalctl --disk-usage
# Až po potvrzení uchování potřebných dat: příklad odstranění archivů starších 14 dnů.
sudo journalctl --vacuum-time=14dFourteen days is an illustrative limit, not a recommendation for every service. The operation removes history and has no automatic rollback without a pre-prepared copy. If you need to convert active files to an archived state first, there is --rotate; understand which files will become candidates for deletion before combining it with vacuum.
After the operation, re-measure the same source and verify that the necessary history remains. Do not consider the entire journal directory not being emptied as an error: the goal is not zero size, but reasonable management of old data and continued functional writing. On the contrary, a completely silent system after a cleanup could indicate a broken collection.
Design permanent retention by storage type
A one-time vacuum does not address unlimited future growth. There are size, free margin, and maximum age parameters for journald. Consider whether the journal uses persistent storage in /var/log or volatile space under /run. SystemMaxUse and RuntimeMaxUse do not automatically apply to the same area.
# Pouze ilustrační obsah načítaného drop-inu journald:
[Journal]
SystemMaxUse=500M
SystemKeepFree=1G
MaxRetentionSec=14dThe sample is not a one-size-fits-all budget. On a small disk, a server with a required longer history, or a machine with high traffic, you may need a different value or remote collection. The parameters are not an absolute guarantee that the system will maintain the exact number of bytes at any given time. Verify the meaning and behavior of the version you are actually running.
Apply changes to the established configuration mechanism, record the original state, and use a documented application method. Do not make an unrelated change to Storage or the entire logging architecture at the same time as a minor cleanup. After application, verify the creation of new events and the availability of existing records.
Solve text logs by rotating and reopening properly
A service writing to a text log may still have the old descriptor open. Proper rotation therefore usually involves renaming it, creating a new file with appropriate permissions, and documenting instructions to the service to open it. The exact procedure depends on the program. Deleting the file alone may not free up space or restore proper writing.
# Kontrola konfigurace logrotate bez provedení rotace:
sudo logrotate --debug /etc/logrotate.conf
# Následně čtěte konkrétní konfiguraci služby v /etc/logrotate.d/.Use debug mode to test the rules and selected paths. This is not the same as forced production rotation. Check the number of copies, time and size limits, compression, owner, and postrotate. Incorrect permissions on a new file can stop logging even for otherwise functioning services. Too wide a glob in a rule can affect other types of data.
Copytruncate allows specific procedures without changing the open file, but there may be a window of lost records between copying and truncation. Do not consider it a universally safer option. Prefer documented application procedures. For example, NGINX supports reopening logs with an appropriate control signal; a restart of the entire site is not required for a normal rotation.
Deleted open files and unusual other claims
If df does not go down after removing the old log, use lsof +L1 and assign the descriptor to the actual process. The fix is to force the correct service to close or reopen the file as documented. Do not assume a suitable signal just because it works for another application. For example, the same signal may terminate a process elsewhere.
sudo lsof +L1Don't truncate a foreign /proc/PID/fd without knowing the specific file and the impact. It may be live data, not just a regular log. Also, snapshots may hold blocks after the old copy is deleted. If the space doesn't free up the expected step, revert to accounting for storage instead of another aggressive delete.
For database transaction logs, use database management and its recovery or replication policy. The name "log" does not mean that the file has no functional significance. The same applies to an audit queue that is still waiting to be delivered to a remote collector. Without knowing the state, deleting it could destroy the only remaining copy of events.
Also fix the reason for the excessive growth
High volume can be caused by a forgotten debug mode, a recurring service failure, overly detailed access logs, or an attack. Determine the frequency and type of events before reducing retention to a few minutes of history. It may be better to fix a specific error and maintain a useful level of logging.
You must not confuse noise reduction with disabling security auditing. Decide which events are necessary and which sensitive data should not be recorded at all. A secret token in a query cannot be safely resolved simply by deleting logs faster: it is necessary to adjust the way it is passed and, if necessary, deal with existing copies in accordance with operational policy.
If long history is needed, design an appropriate archive or remote repository with access control and readability testing. Successful archive creation does not guarantee recovery. The capacity plan should include growth, compression, retrieval time, and failure behavior of the target repository.
Cleaning verification: location, history and new events
After the intervention, compare the capacity of the same volume and the service status. Generate a suitable harmless control event or safe request and verify its new record. Don't just wait for the file to exist: it could have had the wrong owner and the service is no longer writing to it. At the same time, check that the necessary scope of older events is preserved.
- The vacancy corresponds to a specific confirmed cause.
- The deletion respected the approved retention and preservation of necessary evidence.
- The rotation or journal continues to actually accept new events.
- There is no large deleted open file and no new permissions errors.
- Future growth has budget and control thresholds, not just today's manual intervention.
In CH-J Tools you can use the disk overview and terminal for read checks as well as targeted management. The responsibility for the significance of individual data remains with the service administrator. Proper cleaning will return capacity without losing important information and eliminate the reason why the same problem would soon recur.
Frequently asked questions
Can I delete the entire /var/log?
Not as a general rule. Content has different owners, formats, and retention requirements. First, identify the specific source of consumption.
Why didn't the vacuum reach the exact size specified?
It manages archived files, and active files and other retention conditions can still contribute to the total consumption.
Why is a deleted log still taking up space?
A running process may be holding an open descriptor. Use documented reopening or other targeted service procedure.
Is copytruncate lossless?
Not generally. There is a window between copying and truncation in which some records may disappear.
Detailed documentation
systemd: journalctl, rotate and vacuum →
systemd: journald retention and storage →
logrotate: rotation, debug and copytruncate →