Shell Scripts

Various scripts and configs for the GNU/Linux operating system

MySQL Backup using logrotate

Thanks to Erik Thauvin for this one.

/path/to/mysql-backup.sql {
  notifempty
  daily
  nocreate
  rotate 15
  missingok
  compress
  postrotate
  # just if mysqld is really running
  if test -n "`ps acx|grep mysqld`"; then
    mysqldump --add-drop-table --add-locks --all --extended-insert --quick -A > /path/to/mysql-backup.sql
  fi
  endscript
}

Using logrotate

Here' how to use logroate with a specific config file.

#!/bin/sh
 
/usr/sbin/logrotate -s /path/to/logrotate.status /path/to/logrotate.conf