The MySQL Extension is a Cedar Backup extension used to back up MySQL [24] databases via the Cedar Backup command line. It is intended to be run either immediately before or immediately after the standard collect action.
This extension always produces a full backup. There is currently no facility for making incremental backups. If/when someone has a need for this and can describe how to do it, I will update this extension or provide another.
The backup is done via the mysqldump command included with the MySQL product. Output can be compressed using gzip or bzip2. Administrators can configure the extension either to back up all databases or to back up only specific databases.
The extension assumes that all configured databases can be backed up by a single user. Often, the “root” database user will be used. An alternative is to create a separate MySQL “backup” user and grant that user rights to read (but not write) various databases as needed. This second option is probably your best choice.
The extension accepts a username and password in configuration.
However, you probably do not want to list those values in Cedar
Backup configuration. This is because Cedar Backup will provide these
values to mysqldump via the command-line
--user
and --password
switches,
which will be visible to other users in the process listing.
Instead, you should configure the username and password in one of MySQL's
configuration files. Typically, that would be done by putting a stanza like
this in /root/.my.cnf
:
[mysqldump] user = root password = <secret>
Of course, if you are executing the backup as a user other than root, then you would create the file in that user's home directory instead.
As a side note, it is also possible to configure .my.cnf
such that Cedar Backup can back up a remote database server:
[mysqldump] host = remote.host
For this to work, you will also need to grant privileges properly for the user which is executing the backup. See your MySQL documentation for more information about how this can be done.
Regardless of whether you are using ~/.my.cnf
or
/etc/cback.conf
to store database login and
password information, you should be careful about who is allowed to
view that information. Typically, this means locking down permissions
so that only the file owner can read the file contents (i.e. use mode
0600
).
To enable this extension, add the following section to the Cedar Backup configuration file:
<extensions> <action> <name>mysql</name> <module>CedarBackup2.extend.mysql</module> <function>executeAction</function> <index>99</index> </action> </extensions>
This extension relies on the options and collect configuration
sections in the standard Cedar Backup configuration file, and then
also requires its own mysql
configuration section.
This is an example MySQL configuration section:
<mysql> <compress_mode>bzip2</compress_mode> <all>Y</all> </mysql>
If you have decided to configure login information in Cedar Backup rather than using MySQL configuration, then you would add the username and password fields to configuration:
<mysql> <user>root</user> <password>password</password> <compress_mode>bzip2</compress_mode> <all>Y</all> </mysql>
The following elements are part of the MySQL configuration section:
user
Database user.
The database user that the backup should be executed as.
Even if you list more than one database (below) all backups
must be done as the same user. Typically, this would be
root
(i.e. the database root user, not the
system root user).
This value is optional. You should probably configure the username and password in MySQL configuration instead, as discussed above.
Restrictions: If provided, must be non-empty.
password
Password associated with the database user.
This value is optional. You should probably configure the username and password in MySQL configuration instead, as discussed above.
Restrictions: If provided, must be non-empty.
compress_mode
Compress mode.
MySQL databases dumps are just specially-formatted text files, and often compress quite well using gzip or bzip2. The compress mode describes how the backed-up data will be compressed, if at all.
Restrictions: Must be one of
none
, gzip
or
bzip2
.
all
Indicates whether to back up all databases.
If this value is Y
, then all MySQL
databases will be backed up. If this value is
N
, then one or more specific databases
must be specified (see below).
If you choose this option, the entire database backup will go into one big dump file.
Restrictions: Must be a boolean
(Y
or N
).
database
Named database to be backed up.
If you choose to specify individual databases rather than all databases, then each database will be backed up into its own dump file.
This field can be repeated as many times as is necessary. At
least one database must be configured if the all option
(above) is set to N
. You may not
configure any individual databases if the all option is set
to Y
.
Restrictions: Must be non-empty.