# 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 %}


---

# 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.boldminded.com/datagrab/docs/troubleshooting/datagrab-import.log-rotation.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.
