crontab regular jobs: clapf, backup, apt-get, mysql

These crontab entries are for a common (email) server, they can be used in common on any server.

# m h  dom mon dow   command
PATH="/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

3 3 * * * mysql --defaults-file=/data/apps/clapf/current/var/lib/clapf/.my.cnf < /data/apps/clapf/current/share/clapf/purge-mysql.sql

1 2 * * * find /data/apps/clapf/current/var/lib/clapf/queue -type f -atime +31 -exec rm -f '{}' \;

1 2 * * * find <CLAPF WEBUI CACHE DIR> -type f  -atime +14 -exec rm -f '{}' \;

*/15 * * * * /root/bin/clapf-rrd.sh > /dev/null

0 3 * * * /root/bin/backup-mysql.sh

0 2 * * * mysqlcheck -A -s -o
30 2 * * * mysqlcheck -A -s -c

0 4 * * * /data/apps/postfixadmin/cleanup-cron.sh

0 9 * * * apt-get -qq update ; apt-get -qq upgrade -d

clapf-rrd.sh:

#!/bin/sh

# data export
/data/apps/clapf/current/libexec/clapf/process_syslog.pl `date +"%b %e %H"` < /var/log/mail.log >> /data/clapf/stat/clapf.stat
/data/apps/clapf/current/libexec/clapf/spamstat.pl `date +"%b %e %H"` < /var/log/mail.log | /data/apps/clapf/current/libexec/clapf/spamstat

# spam+ham
/data/apps/clapf/current/libexec/clapf/clapf-rrd-graph.sh /data/clapf/stat/clapf-ham-spam.rrd /data/clapf/stat/daily.png "Clapf daily graph" day
/data/apps/clapf/current/libexec/clapf/clapf-rrd-graph.sh /data/clapf/stat/clapf-ham-spam.rrd /data/clapf/stat/daily.png "Clapf weekly graph" week
/data/apps/clapf/current/libexec/clapf/clapf-rrd-graph.sh /data/clapf/stat/clapf-ham-spam.rrd /data/clapf/stat/daily.png "Clapf monthly graph" month

# spam ratio
/data/apps/clapf/current/libexec/clapf/clapf-rrd-update.sh /data/clapf/stat/clapf-spam-ratio.rrd `tail -1 /data/clapf/stat/clapf.stat | awk '{ print $1 ":" $9 ":0"}'`
/data/apps/clapf/current/libexec/clapf/clapf-rrd-graph-oneline.sh /data/clapf/stat/clapf-spam-ratio.rrd /data/clapf/stat/spam-ratio.png "spam ratio" month

# spam size
/data/apps/clapf/current/libexec/clapf/clapf-rrd-update.sh /data/clapf/stat/clapf-spam-size.rrd `tail -1 /data/clapf/stat/clapf.stat | awk '{ print $1 ":" $9 ":0"}'`
/data/apps/clapf/current/libexec/clapf/clapf-rrd-graph-oneline.sh /data/clapf/stat/clapf-spam-size.rrd /data/clapf/stat/spam-size.png "spam size" month

backup-mysql.sh:

#!/bin/sh
PATH="/root/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
BACKUPDIR="/data/backup/"
test -d $BACKUPDIR/mysql/dump || mkdir -p $BACKUPDIR/mysql/dump
test -d $BACKUPDIR/mysql/hotcopy || mkdir -p $BACKUPDIR/mysql/hotcopy
test -d $BACKUPDIR/tmp || mkdir -p $BACKUPDIR/tmp

for i in `mysql -e 'show databases'|egrep -v ^'(Database|information_schema)'`;do
    mysqldump $i > $BACKUPDIR/mysql/dump/$i.mysql ;
    # --noindices: indexes can be reconstructed by 'myisamchk -rq'
    rm -rf $BACKUPDIR/mysql/hotcopy/$i; mysqlhotcopy --flushlog --noindices -q --tmpdir=$BACKUPDIR/tmp/ $i $BACKUPDIR/mysql/hotcopy/ > /dev/null 2>/dev/null
done

backup-pgsql.sh:

#!/bin/sh
PATH="/root/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
BACKUPDIR="/data/backup/"
test -d $BACKUPDIR/pgsql || mkdir -p $BACKUPDIR/pgsql

for i in `psql -U $PGUSER -l | awk '{ print $1}' | grep -vE '^-|^List|^Name|template[0|1]|^\(|^$'`;do
    pg_dump -d -D -U $PGUSER $i |bzip2 -c > $BACKUPDIR/pgsql/$i.pgsql.bz2
done

# globalis beallitasok adatbazis mentese
pg_dumpall -g -U $PGUSER > $backupdir/$nowdate/pg-global.pgsql

# schema-kal
DATABASE=fmp_db

for schema in `pg_dump -U $PGUSER --schema-only $DATABASE |grep ^'CREATE SCHEMA'|awk '{ print $3 }'|tr -d \;`;do
    pg_dump -U $PGUSER -x --no-owner --file="$BACKUP_DIR/$DATABASE_${schema}.pgsql" -n "${schema}" "$DATABASE"
done
avatar

About tompos

Hungary, Budapest
This entry was posted in BSD, IT, Linux. Bookmark the permalink.

Leave a Reply