Created
April 24, 2013 19:05
-
-
Save jalexandre0/5454685 to your computer and use it in GitHub Desktop.
Housekeeping for postgresql and zabbix. I'm still using this after zabbix 2.0, and still working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Setting atual date | |
echo $(date +%d/%m/%Y-%H:%M) | |
#One year and month ago in Unix Timestamp | |
ONE_YEAR_AGO=$(expr `date +%s` - 31536000) | |
ONE_MONTH_AGO=$(expr `date +%s` - 2678400) | |
#Queries for one month ago | |
MONTH_TABLES="history history_uint history_str history_text history_log" | |
for table in $MONTH_TABLES | |
do | |
DELETES=$( /usr/bin/psql --dbname zabbix -c "delete from $table where clock < $ONE_MONTH_AGO ;" ) | |
echo " $DELETES from table $table " | |
done | |
#Queries for one year ago | |
YEAR_TABLES="alerts trends trends_uint" | |
for table in $YEAR_TABLES | |
do | |
DELETES=$(/usr/bin/psql --dbname zabbix -c "delete from $table where clock < $ONE_YEAR_AGO ;") | |
echo " $DELETES from table $table " | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment