packages: bacula/bacula-backup-mysql, bacula/bacula-backup-mysql.conf - the...
glen
glen at pld-linux.org
Wed May 13 22:45:42 CEST 2009
Author: glen Date: Wed May 13 20:45:42 2009 GMT
Module: packages Tag: HEAD
---- Log message:
- the rewritten code using modules from CPAN
---- Files affected:
packages/bacula:
bacula-backup-mysql (1.1 -> 1.2) , bacula-backup-mysql.conf (1.1 -> 1.2)
---- Diffs:
================================================================
Index: packages/bacula/bacula-backup-mysql
diff -u packages/bacula/bacula-backup-mysql:1.1 packages/bacula/bacula-backup-mysql:1.2
--- packages/bacula/bacula-backup-mysql:1.1 Wed May 13 22:43:07 2009
+++ packages/bacula/bacula-backup-mysql Wed May 13 22:45:36 2009
@@ -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 @@
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 {
@@ -117,4 +119,33 @@
$dsn .= "mysql_socket=$socket" if $socket;
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: packages/bacula/bacula-backup-mysql.conf
diff -u packages/bacula/bacula-backup-mysql.conf:1.1 packages/bacula/bacula-backup-mysql.conf:1.2
--- packages/bacula/bacula-backup-mysql.conf:1.1 Wed May 13 22:44:02 2009
+++ packages/bacula/bacula-backup-mysql.conf Wed May 13 22:45:36 2009
@@ -1,27 +1,34 @@
-; vim:ft=dosini
+# vim:ft=apachestyle
-[clusters]
-;cluster=won2
-;cluster=eventum
-cluster=default
-
-[client]
-user=mysql
-password=
-
-[options]
-tmpdir=/media/backup/tmp
-outdir=/media/backup/mysql
-
-[won2]
-user=mysql
-password=
-socket=/var/lib/mysql/mysql.sock
-
-exclude_database=won2backup
-exclude_database=test
-include_database=won2_ui
-include_database=delfi_watson2
-
-[default]
-socket=/var/lib/mysql/mysql.sock
+<clusters>
+# cluster won2
+# cluster eventum
+ cluster default
+</clusters>
+
+<client>
+ user mysql
+# password
+</client>
+
+<options>
+ tmpdir /media/backup/tmp
+ outdir /media/backup/mysql
+</options>
+
+<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
+</cluster>
+
+<cluster default>
+ socket /var/lib/mysql/mysql.sock
+# exclude_database mysql
+# include_database mysql
+</cluster>
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/bacula/bacula-backup-mysql?r1=1.1&r2=1.2&f=u
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/bacula/bacula-backup-mysql.conf?r1=1.1&r2=1.2&f=u
More information about the pld-cvs-commit
mailing list