bacula-backup-mysql - A hook for Bacula to backup mysql databases using mysqlhotcopy or mysqldump.
Job {
Name = "example.org-mysql"
...
# This prepares the backup
Client Run Before Job = "/usr/sbin/bacula-backup-mysql"
# This deletes the copy of the catalog
Client Run After Job = "/usr/sbin/bacula-backup-mysql -cleanup"
}
This is a script to be setup as Client Run Before Job
in Bacula.
Config starts with <clusters>
block, which you can define several database instances to be backed up.
Each cluster
should define connection dsn and databases to be backed up.
To define connection dsn, you can also define common options in <client>
section, those options would be shared for each cluster which has not overriden the specific option.
In <cluster>
sections, you should list databases to be backed up. You can use include_database
options to explicitly list which databases should be backed up, and exclude_database
options to explicitly list those that should not.
Additionally include_database
supports table regexp, which is passed directly to mysqlhotcopy(1). This allows you to include or exclude tables from each database backup.
Unless you only specify include_database
options, all databases which can be seen with a show tables
query are considered for backup; any exclude_database
options will reduce this list.
Since v0.6 it's possible to do SQL dump backups with mysqldump(1). Use this if you want to backup InnoDB databases. Option name is dump_type
, which takes values mysqlhotcopy
(default) and mysqldump
.
Since v0.7 you can pass arbitary options to mysqlhotcopy
or mysqldump
using mysqlhotcopy_options
or mysqldump_options
respectively. Use this to pass options like --old_server
.
Ordinarily, using include_database
and exclude database
options in the same cluster
cause the include_database
option to be unnecessary, as the existence of any exclude_database
options implicitly includes all available databases obtained from show databases
. However, when using a dump_type
of mysqlhotcopy
, the include_database
option can be further configured to specify the exact tables to be backed up, giving the user far more control over the process.
Dump type mysqlhotcopy
allows you to pass --record_log_pos log-pos-table
option to mysqlhotcopy
. The log-pos-table
table must already exist, see perldoc mysqlhotcopy
for the table schema. Please note that this option is not safe to use when backing up more than one database, because current operation backs up each database with separate mysqlhotcopy
call and so the log pos is saved with each call overwriting the previous.
# clusters to backup
# there is nothing special about name "mysql", name just picked as convience
<clusters>
cluster mysql
cluster eventum
cluster forums
cluster selected_dbs
</clusters>
# client connection parameters, can be overriden per cluster
<client>
user mysql
password secret
</client>
# global options, can be overriden per cluster
<options>
tmpdir /srv/bacula/tmp
outdir /srv/bacula/mysql
</options>
# mysql cluster: backup all but mysql database
<cluster mysql>
socket /var/lib/mysql/mysql.sock
exclude_database mysql
</cluster>
# forums cluster: exclude phorum_forums and phorum_users tables
<cluster forums>
user mysql
socket /var/lib/mysql/mysql.sock
# include_database can also support table regexp for mysqlhotcopy:
include_database teensForum5./~(phorum_forums|phorum_users)/
</cluster>
# selected_dbs cluster: backup all except mysql, and be specific about tables
# in the teensForum5 database
<cluster selected_dbs>
socket /var/lib/mysql/mysql.sock
exclude_database mysql
# can be specific about tables when using mysqlhotcopy:
include_database teensForum5./~(phorum_forums|phorum_users)/
</cluster>
If you find bugs in bacula-backup-mysql(1), file the reports into Bugtracker or even better, send Pull Request with a fix.
There are also bugs in mysqlhotcopy(1), see from Wiki if your version nees patching.
In mysqlhotcopy
mode record_log_pos
option is useless if cluster contains more than one database.
Copyright (C) 2009-2016, Elan Ruusamäe <[email protected]>
http://www.bacula.org/, Bacula wiki: Application specific backups: mysql