Huge Syslog Archive MySQL file

I or maybe you have a problem there is no disk space due to MySQL database on Security Onion Sensor Server. Upon investigating, I realized a table is huge around 34GB.

$ find / -type f -name '*.ARN' -size +1024M -ls
524481 36073464 -rw-rw---- 1 mysql mysql 36939788428 May 26 12:41 /var/lib/mysql/syslog_data/syslogs_archive_1004053.ARN

The table is related to ELSA including MySQL, Sphinx and syslog-ng.

To delete the huge file elegantly, we can use a script, /usr/bin/securityonion-elsa-reset-archive, but the target table of the script is fixed to ‘syslogs_archive_1’. So you can use the script after replacing the table name to found one above or type some commands directly as below.

$ mysql --defaults-file=/etc/mysql/debian.cnf syslog_data \
 -e "DROP TABLE syslog_data.syslogs_archive_1004053"
$ mysql --defaults-file=/etc/mysql/debian.cnf syslog_data \
 -e "DELETE FROM syslog.tables \
      WHERE table_name='syslog_data.syslogs_archive_10024053'"
$ rm /var/lib/mysql/syslog_data/syslogs_archive_1004053.ARN

If you want to remove all of tables, whose name is start with ‘syslogs_archives_1’, you can utilize the sql below.

SELECT CONCAT('DROP TABLE ', GROUP_CONCAT(table_name), ';') as statement 
  FROM information_schema.tables
 WHERE table_name LIKE 'syslogs_archive_1%'

Basically, you need to adjust a value of retention_days of ‘/etc/elsa_node.conf’ because the huge table belongs to ELSA.

BTW, the reason why the table in question became huge is still remain. I just tried delete it as above. Sorry for that.

Moving MySQL Database Folder

By default, MySQL database is stored on ubuntu on “/var/lib/mysql/” folder according to my.cnf. If you want to move the stored folder to another(e.g., /nsm/mysql/), you can refer the script below.

$ service mysql stop
$ cp -avrp /var/lib/mysql /nsm/
$ chown -R mysql:mysql /nsm/mysql/
$ vi /etc/mysql/my.cnf
– datadir=/var/lib/mysql
+ datadir=/nsm/mysql
$ service mysql start

If there is anything for restricting the MySQL database file or folder, you need to re-configure it such as SELinux or AppArmor(“Application Armor”).

$ vi /etc/apparmor.d/usr.sbin.mysqld
– /var/lib/mysql/ r,
– /var/lib/mysql/** rwk,
+ /nsm/mysql/ r,
+ /nsm/mysql/** rwk,
$ /etc/init.d/apparmor restart