# 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](https://docs.uxwizz.com/api/session-recording).
{% 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).
