Skip to content

Backup event_log database content

akshay31057 edited this page Jul 2, 2017 · 3 revisions

Motivation

Currently, DB records are deleted after a particular row limit set by the administrator, but no backup is created for these deleted logs. It would be useful if a backup in a file is created for these logs for future reference.

Also, if these backups are mailed to the administrator when required or when cron runs, would be a cherry on the cake.

This feature can be used in collaboration with the clear log messages button feature, i.e you might want to take a backup of the logs that you are about to clear.

Upstream link : https://www.drupal.org/node/2883592

Description

This feature enables the administrator and privileged users to create a backup file that consists of current database records.

This can be done by enabling the Event Log Backup content sub-module in the modules section. Once the module is enabled, backup can be created and viewed by pressing the “View/Update and Save Backup Content” button.

The backup file is created at /sites/default/files folder. Every time the “View/Update and Save Backup Content” button is clicked, a new file named backup_#.txt is created where # is a suffixed incrementing integer starting from 0.

Moreover, the content of backup_#.txt file is mailed to the administrator.

Also, by checking the “Enable Backup Content in Cron Run” checkbox, the same set of actions are performed.

Implementation

A new sub-module named event_log_backup is added in the event_log folder. The .module file implements the desired action using hook api functions namely, hook_menu, hook_cron, hook_mail and hook_permission.

Details about this functions can be found at :

Besides the above hook api functions, some user defined functions in the sub-module are:

  • event_log_backup_read : Queries the database to fetch the events and saves to backup_#.txt

  • event_log_backup_send : Mails the content of backup_#.txt using drupal_mail().

Issues

  1. Added Sub-Module does not appear in the same section as the event log.
  2. No configuration option corresponding to the added sub-module.
  3. Path to backup_#.txt in the event_log_backup module is not working.

Solutions to issues

  1. Add a package name and dependencies to your .info file so that your sub-module appears under the right section, which is statistics in the event_log module case.

E.g : package = Statistics

dependencies[] = event_log

  1. Add configure = admin/config/event_log_backup
  2. Change the path to public://backup_#.txt instead of specifying the complete path. By doing so, a file is automatically created at sites/default/files/ and no permission issues arise.

Link to git issue

https://github.com/fresearchgroup/drupal-logger/issues/5