]> git.openstreetmap.org Git - nominatim.git/commitdiff
cron script for log rotation
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 15 Apr 2012 17:11:35 +0000 (19:11 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 15 Apr 2012 17:11:35 +0000 (19:11 +0200)
utils/cron_logrotate.sh [new file with mode: 0755]

diff --git a/utils/cron_logrotate.sh b/utils/cron_logrotate.sh
new file mode 100755 (executable)
index 0000000..77102d9
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+#
+# Rotate query logs.
+
+dbname=nominatim
+
+basedir=`dirname $0`
+logfile=`date "+$basedir/../log/query-%F.log.gz"`
+
+# dump the old logfile
+pg_dump -a -F p -t backup_query_log $dbname | gzip -9 > $logfile || exit
+
+# remove the old logs
+psql -q -d $dbname -c 'DROP TABLE backup_query_log'
+
+# rotate
+psql -q -1 -d $dbname -c 'ALTER TABLE new_query_log RENAME TO backup_query_log;CREATE TABLE new_query_log as (select * from backup_query_log limit 0);GRANT SELECT, INSERT, UPDATE ON new_query_log TO "www-data"'
+psql -q -d $dbname -c 'ALTER INDEX idx_new_query_log_starttime RENAME TO idx_backup_query_log_starttime'
+psql -q -d $dbname -c 'CREATE INDEX idx_new_query_log_starttime ON new_query_log USING BTREE (starttime)'
+