From: Elan Ruusamäe Date: Fri, 16 Mar 2012 17:29:16 +0000 (+0000) Subject: - allow include_database to contain table regexp like mysqlhotcopy(1) X-Git-Tag: auto/ac/bacula-backup-mysql-0_4-1~1 X-Git-Url: https://git.pld-linux.org/?p=packages%2Fbacula-backup-mysql.git;a=commitdiff_plain;h=36d65868f951f708af7b0bb02efbcdd33b58c34f - allow include_database to contain table regexp like mysqlhotcopy(1) Changed files: bacula-backup-mysql -> 1.15 bacula-backup-mysql.conf -> 1.4 --- diff --git a/bacula-backup-mysql b/bacula-backup-mysql index a8136b8..247e29c 100644 --- a/bacula-backup-mysql +++ b/bacula-backup-mysql @@ -6,7 +6,7 @@ # # 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 @@ -26,7 +26,6 @@ use DBI; 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); @@ -41,13 +40,13 @@ unless ($<) { 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"; @@ -71,9 +70,13 @@ for my $cluster ($c->get('clusters', 'cluster')) { # 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); @@ -82,7 +85,7 @@ sub mysqlhotcopy { 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" @@ -235,15 +238,21 @@ which has not overriden the specific option. In CclusterE> sections, you should list databases to be backed up. You can use C option to implicitly list which databases to be backed up. If you omit C option, all databases are backed up -which can be seen with C query. To exclude databases from that +which can be seen with C query. To exclude databases from that list you can use C options. +Additionally C 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 cluster mysql + cluster eventum + cluster forums # client connection parameters, can be overriden per cluster @@ -264,6 +273,15 @@ list you can use C options. exclude_database mysql + # forums cluster: exclude phorum_forums and phorum_users tables + + user mysql + socket /var/lib/mysql/mysql.sock + + # include_database can also support table regexp for mysqlhotcopy: + include_database teensForum5./~(phorum_forums|phorum_users)/ + + =head1 AUTHOR Copyright (C) 2009-2012, Elan RuusamEe diff --git a/bacula-backup-mysql.conf b/bacula-backup-mysql.conf index 1237e00..6351f98 100644 --- a/bacula-backup-mysql.conf +++ b/bacula-backup-mysql.conf @@ -33,8 +33,13 @@ password socket /var/lib/mysql/mysql.sock + # exclude database has only effect if no include_database is selected exclude_database won2backup exclude_database test + include_database won2_ui include_database delfi_watson2 + + # include_database can also support table regexp for mysqlhotcopy: + include_database teensForum5./~(phorum_forums|phorum_users)/