#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
use File::Temp qw(tempdir);
use File::Path qw(rmtree);
-
# path to Apache HTTPd-style config
my $config = '/etc/bacula/backup-mysql.conf';
my $c = new BBM::Config($config);
chdir("/");
$) = "$gid $gid";
- $( = $gid;
- $> = $< = $uid;
+ $( = $gid;
+ $> = $< = $uid;
}
# setup tmpdir
my $backup_dir = $c->get('options', 'outdir') or die "'outdir' not defined in config\n";
-my $tmpdir = $c->get('options', 'tmpdir') or die "'tmpdir' not defined in config\n";
+my $tmpdir = $c->get('options', 'tmpdir') or die "'tmpdir' not defined in config\n";
if (!-d $backup_dir && !mkdir($backup_dir) && !-d $backup_dir) {
die "backup dir '$backup_dir' not present and can't be created\n";
# Usage: mysqlhotcopy $CLUSTER $DATABASE $USERNAME $PASSWORD $SOCKET
#
sub mysqlhotcopy {
- my ($cluster, $database, $user, $password, $socket) = @_;
+ my ($cluster, $db, $user, $password, $socket) = @_;
+
+ # strip $database to contain only db name, as the rest of the code assumes $database is just database name
+ # i.e: include_database teensForum5./~(phorum_forums|phorum_users)/
+ my ($database) = $db =~ /^([^\.]+)/;
- print ">>>> mysqlhotcopy $database\n";
+ print ">>>> mysqlhotcopy $db\n";
my $dstdir = tempdir("bbm.XXXXXX", DIR => $tmpdir);
push(@shell, '-u', $user) if $user;
push(@shell, '-p', $password) if $password;
push(@shell, '-S', $socket) if $socket;
- push(@shell, $database, $dstdir);
+ push(@shell, $db, $dstdir);
system(@shell) == 0 or die "mysqlhotcopy failed: $?\n";
# put it to "production dir"
In C<E<lt>clusterE<gt>> sections, you should list databases to be backed up.
You can use C<include_database> option to implicitly list which databases to be
backed up. If you omit C<include_database> option, all databases are backed up
-which can be seen with C<show tables> query. To exclude databases from that
+which can be seen with C<show tables> query. To exclude databases from that
list you can use C<exclude_database> options.
+Additionally C<include_database> supports table regexp, which is passed
+directly to mysqlhotcopy(1). This allows you to include or exclude tables from
+each database backup.
+
=head1 EXAMPLE CONFIGURATION
# clusters to backup
# there is nothing special about name "mysql", name just picked as convience
<clusters>
cluster mysql
+ cluster eventum
+ cluster forums
</clusters>
# client connection parameters, can be overriden per cluster
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>
+
=head1 AUTHOR
Copyright (C) 2009-2012, Elan RuusamE<auml>e <glen@delfi.ee>