# DataGrab-import.log Rotation

Starting in version 6.0.5 of DataGrab you can now add `$config['datagrab_rotate_log'] = 'y';` to your ExpressionEngine `config.php` file. If enabled the log file from the previous import will be backed up with a timestamp in it's name. This will happen every time a new import is started.

Now that you have log rotation enabled, you might want to keep the log files from piling up. Create a file in the `system/user` folder called `cleanup-log.sh` . Make it executable with `chmod +x cleanup-log.sh` . Add this code to that file.

```bash
#!/usr/bin/env bash
set -euo pipefail

# Path to the log file you rotate
LOG_FILE="cache/DataGrab-import.log"

# Directory where the logs live
LOG_DIR=$(dirname "$LOG_FILE")

# The base name of the log (without directory)
LOG_BASE=$(basename "$LOG_FILE")

# Delete rotated logs (with timestamp suffix) older than 7 days
find "$LOG_DIR" -type f -name "${LOG_BASE}.*" -mtime +7 -print -delete

```

You will need to add an entry to your crontab to run this script periodically. You can run it as often as you like. Every 15 minutes, once a day, or once a week. The following will run every hour.

```
0 * * * * /path/to/system/user/cleanup-log.sh
```

{% hint style="info" %}
For more information about crontab, [see the docs](https://man7.org/linux/man-pages/man5/crontab.5.html).
{% endhint %}
