# Auto-delete old data (cron jobs)

You can use the provided cron jobs to automatically delete old data in order to keep the database size low and maintainable for many years.

{% hint style="info" %}
Most data usage comes from heatmaps and [recordings](/api/session-recording.md).
{% endhint %}

### How to run the cron jobs

{% hint style="warning" %}
Note: This assumes that your dashboard is installed at **/var/www/html/**.\
Update the paths accordingly if your dashboard is installed at a different location.\
\
You might first have to run **sh /var/www/html/server/cron/set\_exec\_permissions.sh** to make sure that cronjob can execute the scripts.
{% endhint %}

Edit the crontab file to set what scripts to execute when, by running **`crontab -e`**.\
Add the scripts you want to be executed, like this:

<pre data-title="crontab -e"><code># ... previous crontab content ...

# UXWizz cron jobs
0 2 * * * cd /var/www/html/server/cron; ./ust_del_record_60_days.sh >> /var/log/ust_cron.log 2>&#x26;1
<strong>0 3 * * * cd /var/www/html/server/cron; ./ust_del_heatmap_60_days.sh >> /var/log/ust_cron.log 2>&#x26;1
</strong>0 4 * * * cd /var/www/html/server/cron; ./ust_limit_record_number.sh >> /var/log/ust_cron.log 2>&#x26;1
# Backup the database every Sunday at 3AM
<strong>0 3 * * 0 cd /var/www/html/server/cron; ./ust_backup_dh.sh >> /var/log/ust_cron.log 2>&#x26;1
</strong></code></pre>

{% hint style="info" %}
You can use the `nano` editor for modifying this file. You can press CTRL+O to save the file and CTRL+X to exit.\
\
**Notes**

`0 3 * * *` = Every day at 3 AM\
Tool to understand the cron time syntax: <https://crontab.cronhub.io/>

**/var/www/html/server/cron/log.txt** Will contain the execution date and time logs for the scripts that were run.
{% endhint %}

### Built-in example scripts

{% hint style="danger" %}
**There are currently no cron job examples for Multi-DB Agency setups.**\
**Those cron jobs will only delete data in the main database.**
{% endhint %}

UXWizz comes with some helper and example scripts that can be used for cron jobs.&#x20;

{% code title="/var/www/html/" %}

```sh
###################
# Core scripts
###################
server/cron/ust_execute_query.sh
server/cron/set_exec_permissions.sh

###################
# Built-in example scripts to be used as cron jobs
###################

# Delete heatmap data older than 60 days (data saving)
server/cron/ust_del_heatmap_60_days.sh

# Delete recording data older than 60 days (data saving)
server/cron/ust_del_record_60_days.sh

# Delete all data older than 1 year (session retention)
server/cron/ust_del_visitors_1_year.sh

# Enforce domain record limit (delete sessions going over the set domain limit)
server/cron/ust_limit_record_number.sh

# Delete zero second recordings (potential bots)
server/cron/ust_del_zero_sec_rec.sh

# Create a backup of the main database (in /tmp/backups/)
server/cron/ust_backup_dh.sh

```

{% endcode %}

\
To change the retention numbers or create other scripts, you can copy one of the example .sh files and edit it. (e.g. change interval from 60 days to 6 months).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.uxwizz.com/installation/optimization-tips/auto-delete-old-data-cron-jobs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
