]> git.pld-linux.org Git - packages/bacula-backup-mysql.git/commitdiff
- allow include_database to contain table regexp like mysqlhotcopy(1)
authorElan Ruusamäe <glen@pld-linux.org>
Fri, 16 Mar 2012 17:29:16 +0000 (17:29 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    bacula-backup-mysql -> 1.15
    bacula-backup-mysql.conf -> 1.4

bacula-backup-mysql
bacula-backup-mysql.conf

index a8136b88e442bc79acc3837210eb0498a8049c9b..247e29c998cb512d437fc239698394fa92e68da7 100644 (file)
@@ -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 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
@@ -264,6 +273,15 @@ list you can use C<exclude_database> options.
     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>
index 1237e001e32464e67017fd43b18d5dd04ac62c86..6351f98afc1b0176ff676a7f83d42df7577af6d7 100644 (file)
        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)/
 </cluster>
This page took 0.069338 seconds and 4 git commands to generate.