My ESP8266 devices are generating huge amount of logs so after some time LogAnalyzer database had over 5M records.

I've decided to delete old data, but before run purge script I want to backup these records.

The solution was quite simple:

mysqldump Syslog SystemEvents --where \
'FromHost LIKE "ESP" AND DATE(ReceivedAt) < "2018-01-01"' \
> /data/Dokumenty/Syslog-ESP-2017.sql

where Syslog is database, and SystemEvents is table.

You can also export to CSV (TSV) format if You prefer:

mysql -e "SELECT * FROM SystemEvents \
WHERE FromHost LIKE 'ESP' AND DATE(ReceivedAt) < '2018-01-01' \
INTO OUTFILE '/data/Dokumenty/Syslog-ESP-2017.csv' \
FIELDS TERMINATED BY '\t' ENCLOSED BY '\"' \
LINES TERMINATED BY '\n'" Syslog

After this I could delete whole year, instead of using script:

mysql -e "DELETE FROM SystemEvents \
WHERE FromHost LIKE "ESP" AND DATE(ReceivedAt) < '2018-01-01'" \
Syslog

Now I've only about 600k records ;-)

Just my blog...

Mon Di Mi Do Fr Sa So
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
eZ Publish™ copyright © 1999-2025 eZ Systems AS