Import access.csv into sqlite3 db

This commit is contained in:
Marcus Kammer 2023-11-05 13:43:06 +01:00
parent c1cabf167b
commit 278049a95b
Signed by: marcuskammer
GPG key ID: C374817BE285268F

View file

@ -421,11 +421,17 @@ write_files:
# Increase history limit
set -g history-limit 50000
- path: /home/cl/nginx_logs.sql
- path: /home/cl/access_logs.sql
owner: 'cl:cl'
defer: True
content: |
CREATE TABLE nginx_logs (
-- commands.sql
-- Set the mode to CSV to properly import CSV files
.mode csv
-- If the table doesn't exist, create it
CREATE TABLE IF NOT EXISTS access_logs (
timestamp TEXT,
ip_address TEXT,
remote_user TEXT,
@ -436,6 +442,9 @@ write_files:
http_user_agent TEXT
);
-- Import the data into the 'access_logs' table
.import '/var/log/nginx/access.csv' access_logs
- path: /home/cl/setup_sbcl.sh
owner: 'cl:cl'
permission: '0755'