mysqlbackups
============
AUTHOR: JT Moree
COPYRIGHT: Public Domain
INTRODUCTION
------------
This utility will loop over all the files found in /etc/mysqlbackups.d and
process each one as a separate database to be backed up. The databases
can be on other servers as long as you have the correct authentication
setup in mysql.
BACKUP FILES
------------
The backups will be placed in a configurable directory. Each host will
have its own directory under that directory. Files will be created under
the host directory named after the database and the time of the backup.
BINARY BACKUPS
--------------
As of version .8 there is an option to treat one of the backups in a special
way to allow for rotation and deletion of binary logs. To use this feature
*) Turn on log-bin in /etc/my.cnf
*) set BINDB=mysql in /etc/mysqlbackups.conf
*) copy EXAMPLE.mysql to /etc/mysqlbackups.d/mysql
*) edit /etc/mysqlbackups.d/mysql to turn on the options
*) enable mysqlbackups-binlogs in /etc/cron.d/mysqlbackups.cron
Assuming you run daily backups: you might want to keep 2 days of binary logs.
If the database is corrupted you can restore from yesterday's full backup then
replay the binary logs up to some point of the current day.
See mysqldump for more details.
The script mysqlbackups-binlogs will use rsync to copy the logs from where
mysql puts them into the backup directory in a subdirectory called bin.
Ex. /var/backups/mysql/localhost/bin
/var/backups/mysql/localhost/mysql
/var/backups/mysql/localhost/db1
/var/backups/mysql/localhost/db2
LOGS
----
There is a log file created in /var. You will want to put the logrotate
script in /etc/logrotate.d/
EXPIRING BACKUPS
----------------
The utility mysqlbackups-expire will walk the backups and delete older backups
based on the settings in the config files. (KEEPDAYS, KEEPNUMBER)
WARNING
In the case of putting multiple backups in the same folder (for example,
dumping individual tables from a database using the TAG parameter in separate
configs) the expire script may not differentiate between them. In this case
you must make certain to only put expiration settings on tagged backups.
I know it's difficult to understand. I'll rewrite it someday.
CONFIGURATION OPTIONS
---------------------
Global settings can be placed in /etc/mysqlbackups.conf. Settings for an
individual backup can be placed in /etc/mysqlbackups.d/<file>. Most of these are
easy to understand. Any global setting can be overridden in an individual backup.
MUSER=mysqluser
PASSWD=foo
HOST=mysqlserver.domain.dom
If no host is given it will try to connect through a local socket. This is the
default behavior of the mysql client.
DB=database
OPTS="--opt"
TAG="-schema-only"
this option will append a string onto the end of the files that are created.
Use this in the case that you want to backup the same database multiple times.
This is necessary because the backups use the database name.
### MYSQLEXPIRE OPTIONS
KEEPDAYS=
Can be any integer. Tells the expiration utility to keep backups for this many
days. Older backups will be deleted.
KEEPNUMBER=
Can be any integer. Tells the expiration utility to keep this number of
backups. Other backups will be deleted.
CRON AND SCHEDULING
-------------------
/etc/cron.d/mysqlbackups contains three lines for services to run.
The binary log backups are commented out by default.
The expiration job will expire (delete) backups based on the options set above. It will delete none if the options are unset.
The backup job looks for all the config files in /etc/mysqlbackups.d and runs a backup for each one.