Tagged: crontab

Run backup script to backup MySQL Database using cron

Problem: already add backup command in cron:

mysql -s -r -u root -e ‘show databases’ -N | while read dbname; do mysqldump -u root --complete-insert --single-transaction “$dbname” > /backup/sql/”$dbname”.sql; done

and add dbusername and dbpassword in ~/.my.cnf

user = dbusername
password = dbpassword

but fail to backup due to ‘INFORMATION_SCHEMA.GLOBAL_VARIABLES’ feature is disabled.

According to suggestion, enable MySQL 5.6 compatibility.

Solution: enter MySQL mode and enter

set global show_compatibility_56=on;

or add below directive to /etc/my.cnf :


Generate GoAccess report file daily via crontab

Problem: Want to generate GoAccess report file on website every day --

sudo cat /var/log/apache2/access.log | goaccess > /var/www/goaccess/index.html

above command although work in a normal case ( manually generate report in/var/www/goaccess/index.html ), for regular task like generate HTML reports in cron every day is not working -- above command put in cron file is not work and the file name is not in date format.

Solution: first ensure we let GoAccess know the datetime format setting for the report:

sudo vi ~/.goaccessrc

edit ~/.goaccessrc and fill with below code:

time-format %T
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"

And then in the crontab file change GoAccess command with

sudo goaccess -p ~/.goaccessrc   /var/log/apache2/access.log -a -o /var/www/goaccess/`date +\%Y\%m\%d\%H\%M\%S`.html 

Remember set up the time expression, mine one is running at 5:55 am

55 5 * * * sudo goaccess -p ~/.goaccessrc   /var/log/apache2/access.log -a -o /var/www/goaccess/`date +\%Y\%m\%d\%H\%M\%S`.html 

the filename format will be like below image