]> git.pld-linux.org Git - packages/bacula-backup-mysql.git/commitdiff
- the rewritten code using modules from CPAN
authorElan Ruusamäe <glen@pld-linux.org>
Wed, 13 May 2009 20:45:36 +0000 (20:45 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    bacula-backup-mysql -> 1.2
    bacula-backup-mysql.conf -> 1.2

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

index e41b5f8fd9fb63da0dff96c5599661306f5d7dd5..709c88b4e30dbcd87ff28d25a63711c6d84804a2 100644 (file)
@@ -1,17 +1,14 @@
 #!/usr/bin/perl -w
+package BBM;
 use strict;
 use POSIX qw(setuid setgid);
-
 use DBI;
 use File::Temp qw(tempdir);
 use File::Path qw(rmtree);
-use delfi::mycnf;
 
 # path to ini-style config
-my $config = '/etc/bacula/backup-mysql.conf';
-my $c = new delfi::mycnf($config);
-# force reading config file before we switch user
-$c->get("");
+my $config = '/etc/bacula/backup-mysql.apache';
+my $c = new BBM::Config($config);
 
 # how change to user mysql after we've read config
 unless ($<) {
@@ -84,28 +81,33 @@ sub backup_cluster {
        my $socket = $c->get($cluster, 'socket') || $c->get('client', 'socket');
 
        # get databases to backup
-       my @dbs;
+       my @include = $c->get($cluster, 'include_database');
+       my @exclude = $c->get($cluster, 'exclude_database');
 
-       my @include = $c->get($cluster, 'include_databases');
-       my @exclude = $c->get($cluster, 'exclude_databases');
+       # start with include list
+       my %dbs = map { $_ => 1 } @include;
        if (@exclude or !@include) {
-               my $dbh = new DB($user, $password, $socket);
+               my $dbh = new BBM::DB($user, $password, $socket);
                my $sth = $dbh->prepare("show databases");
                $sth->execute();
                while (my($dbname) = $sth->fetchrow_array) {
                        next if lc($dbname) eq 'information_schema';
-                       push @dbs, $dbname unless grep { m{^\Q$dbname\E$} } @exclude;
+                       $dbs{$dbname} = 1;
                }
                undef $dbh;
        }
 
+       # remove excluded databases
+       delete @dbs{@exclude};
+
        # now do the backup
-       foreach my $db (@dbs) {
+       foreach my $db (keys %dbs) {
                mysqlhotcopy($cluster, $db, $user, $password, $socket);
        }
 }
 
-package DB;
+package BBM::DB;
+use strict;
 
 # DB class for simple Database connection
 sub new {
@@ -118,3 +120,32 @@ sub new {
        my $dbh = DBI->connect("DBI:mysql:$dsn", $user, $password, { PrintError => 0, RaiseError => 1 });
        return $dbh;
 }
+
+package BBM::Config;
+use strict;
+use Config::General;
+
+sub new {
+       my $self = shift;
+       my $class = ref($self) || $self;
+       my $file = shift;
+
+       my $config = new Config::General(-ConfigFile => $file, -LowerCaseNames => 1);
+       my $this = { $config->getall() };
+       bless($this, $class);
+}
+
+sub get {
+       my ($self, $section, $key) = @_;
+       my $h = $self;
+
+       # descend to [cluster] if $section not present in root tree
+       unless (exists $h->{$section}) {
+               $h = $h->{cluster};
+       }
+
+       # pay attention if callee wanted arrays
+       return wantarray ? () : undef unless exists $h->{$section};
+       return wantarray ? () : undef unless exists $h->{$section}->{$key};
+       return $h->{$section}->{$key};
+}
index 2820aa6b5afe1ee51904cbd477422cc291a48b78..3bd0a42ad538e58a8b161316d28fadccc5dc41a3 100644 (file)
@@ -1,27 +1,34 @@
-; vim:ft=dosini
+# vim:ft=apachestyle
 
-[clusters]
-;cluster=won2
-;cluster=eventum
-cluster=default
+<clusters>
+#      cluster won2
+#      cluster eventum
+       cluster default
+</clusters>
 
-[client]
-user=mysql
-password=
+<client>
+       user mysql
+#      password
+</client>
 
-[options]
-tmpdir=/media/backup/tmp
-outdir=/media/backup/mysql
+<options>
+       tmpdir /media/backup/tmp
+       outdir /media/backup/mysql
+</options>
 
-[won2]
-user=mysql
-password=
-socket=/var/lib/mysql/mysql.sock
+<cluster won2>
+       user mysql
+       password
+       socket /var/lib/mysql/mysql.sock
 
-exclude_database=won2backup
-exclude_database=test
-include_database=won2_ui
-include_database=delfi_watson2
+       exclude_database won2backup
+       exclude_database test
+       include_database won2_ui
+       include_database delfi_watson2
+</cluster>
 
-[default]
-socket=/var/lib/mysql/mysql.sock
+<cluster default>
+       socket /var/lib/mysql/mysql.sock
+#      exclude_database mysql
+#      include_database mysql
+</cluster>
This page took 0.1442 seconds and 4 git commands to generate.