5

I run with a dedicated Debian server and I wish like to know what is the best method to clear my logs in my database?

Currently, I use the Magento cron every 5 minutes. It's work fine and when I check on my database in my cron_schedule table, the cron works every 5 minutes.

*/5 * * * * /bin/sh /path/to/magento/cron.sh

Now, I wish clear the following tables every five minutes :

dataflow_batch_export
dataflow_batch_import
log_customer
log_quote
log_summary
log_summary_type
log_url
log_url_info
log_visitor
log_visitor_info
log_visitor_online
report_viewed_product_index
report_compared_product_index
report_event

What is the best method for realize that?

2 Answers 2

6

In simple way,you can do it.

Create a php script at Magento application root dir where cron.php file is located.

the using mysql query truncate data from database table

add This php script at cronjob as per as your requirement

<?php
require_once 'app/Mage.php';
Mage::app("admin"); // run application as admin
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$query1 = "truncate table dataflow_batch_export";
$query2 = "truncate table dataflow_batch_import";
$query3 = "truncate table log_customer";
$query = "truncate table log_quote";
$query4 = "truncate table log_summary";
$query5 = "truncate table log_summary_type";
$query6 = "truncate table log_url";
$query7 = "truncate table log_url_info";
$query8 = "truncate table log_visitor";
$query9 = "truncate table log_visitor_info";
$query10 = "truncate table log_visitor_online";
$query11 = "truncate table report_viewed_product_index";
$query12 = "truncate table report_compared_product_index";
$query13 = "truncate table report_event";

$writeConnection->query($query1);
$writeConnection->query($query2);
$writeConnection->query($query3);
$writeConnection->query($query4);
$writeConnection->query($query5);
$writeConnection->query($query6);
$writeConnection->query($query7);
$writeConnection->query($query8);
$writeConnection->query($query9);
$writeConnection->query($query10);
$writeConnection->query($query11);
$writeConnection->query($query12);
$writeConnection->query($query13);
$writeConnection->query($query13);
0
0

I think there is magento setting already provided for it

System > Configuration > Advanced > System > Log Cleaning

You can configure your store to automatically clean up these logs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.