Setting up Auto-Archiving in Matomo is very important to ensure that your reports are pre-processed automatically and for your Matomo reports to load very fast. Usually you setup the auto archiving to be executed by a cron on Linux (or a scheduled task on Windows). But on Linux systems you can also setup the Matomo auto-archiving using systemd by following the steps below:

Steps to setup auto-archiving with systemd

1. Setup a ‘service’ file which tells systemd what command to run

On most distributions that use systemd, the service and timer files are kept in /etc/systemd/system/ (if not, check the documentation of your specific flavour of Linux).

In this folder, let’s create a matomo.service file with the following content:

[Unit]
Description=Matomo Auto-Archiving

[Service]
Type=oneshot
ExecStart=/usr/bin/php /path/to/matomo/console core:archive --url=https://example.com/matomo/

2. Setup a ‘timer’ file, which tells systemd when to run the command

Then in the same folder, let’s create a matomo.timer file with the following content:

[Unit]
Description=Hourly run of Matomo Auto-Archiving

[Timer]
OnCalendar=*:05:00
RandomizedDelaySec=10m
Persistent=true

[Install]
WantedBy=timers.target

3. start the timer and make it automatically restart on system reboot

Run the following 2 commands:

$ sudo systemctl start matomo.timer
$ sudo systemctl enable matomo.timer

A note on auto-archiving logs and systemd

Using systemd means that the Matomo archiving command output is logged with journald. This means you can use the full range of journalctl commands to review the messages.

However, you also need to keep in mind that systemd does not allow for email based log alerts as standard. Therefore, if you do you use this method instead of cron you may want to set up an external logging tool to monitor systemd logs and send alerts from there to avoid gaps in your archiving if anything goes wrong.

Previous FAQ: How to monitor errors from Matomo CRON tabs?