Clear systemd journal
  Admin   25 Agustus 2019   fix error

On any server, the logs can start to add up and take considerable amount of disk space. Systemd conveniently stores these in /var/log/journal and has a systemctl command to help clear them.

Take this example:

$ du -hs /var/log/journal/
4.1G	/var/log/journal/

4.1GB worth of journal files, with the oldest dating back over 2 months.

$ ls -lath /var/log/journal/*/ | tail -n 2
-rw-r-x---+ 1 root systemd-journal 8.0M Dec 24 05:15 user-xxx.journal

On this server, I really don't need that many logs, so let's clean them out. There are generally 2 ways to do this.

Clear systemd journals older than X days

The first one is time-based, clearing everything holder than say 10 days.

$ journalctl --vacuum-time=10d
...
Vacuuming done, freed 2.3G of archived journals on disk.

Alternatively, you can limit its total size.

Clear systemd journals if they exceed X storage

This example will keep 2GB worth of logs, clearing everything that exceeds this.

$ journalctl --vacuum-size=2G
...
Vacuuming done, freed 720.0M of archived journals on disk.

Afterwards, your /var/log/journal should be much smaller.

$ du -hs /var/log/journal
1.1G	/var/log/journal

Saves you some GBs on disk!

 

source : https://ma.ttias.be/clear-systemd-journal/

Tags :

ubuntu , terminal

Bagikan :