/etc/bacula/scripts/make_catalog_backup.pl is in bacula-director-mysql 5.2.6+dfsg-9.1ubuntu3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | #!/usr/bin/env perl
use strict;
=head1 SCRIPT
This script dumps your Bacula catalog in ASCII format
It works for MySQL, SQLite, and PostgreSQL
=head1 USAGE
make_catalog_backup.pl MyCatalog
=head1 LICENSE
Bacula® - The Network Backup Solution
Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation plus additions
that are listed in the file LICENSE.
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 GNU
General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
Bacula® is a registered trademark of Kern Sibbald.
The licensor of Bacula is the Free Software Foundation Europe
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
Switzerland, email:ftf@fsfeurope.org.
=cut
my $cat = shift or die "Usage: $0 catalogname";
my $dir_conf='/usr/sbin/dbcheck -B -c /etc/bacula/bacula-dir.conf';
my $wd = "/var/lib/bacula";
sub dump_sqlite3
{
my %args = @_;
exec("echo .dump | sqlite3 '$wd/$args{db_name}.db' > '$wd/$args{db_name}.sql'");
print "Error while executing sqlite dump $!\n";
return 1;
}
# TODO: use just ENV and drop the pg_service.conf file
sub dump_pgsql
{
my %args = @_;
umask(0077);
if ($args{db_address}) {
$ENV{PGHOST}=$args{db_address};
}
if ($args{db_socket}) {
$ENV{PGHOST}=$args{db_socket};
}
if ($args{db_port}) {
$ENV{PGPORT}=$args{db_port};
}
$ENV{PGDATABASE}=$args{db_name};
$ENV{PGUSER}=$args{db_user};
$ENV{PGPASSWORD}=$args{db_password};
exec("HOME='$wd' pg_dump -c > '$wd/$args{db_name}.sql'");
print "Error while executing postgres dump $!\n";
return 1; # in case of error
}
sub dump_mysql
{
my %args = @_;
umask(0077);
unlink("$wd/.my.cnf");
open(MY, ">$wd/.my.cnf")
or die "Can't open $wd/.my.cnf for writing $@";
$args{db_address} = $args{db_address} || "localhost";
my $addr = "host=$args{db_address}";
if ($args{db_socket}) { # unix socket is fastest than net socket
$addr = "socket=$args{db_socket}";
}
print MY "[client]
$addr
user=$args{db_user}
password=$args{db_password}
";
if ($args{db_port}) {
print MY "port=$args{db_port}\n";
}
close(MY);
exec("HOME='$wd' mysqldump -f --opt $args{db_name} > '$wd/$args{db_name}.sql'");
print "Error while executing mysql dump $!\n";
return 1;
}
sub dump_catalog
{
my %args = @_;
if ($args{db_type} eq 'SQLite3') {
$ENV{PATH}="/usr/bin:$ENV{PATH}";
dump_sqlite3(%args);
} elsif ($args{db_type} eq 'PostgreSQL') {
$ENV{PATH}="/usr/bin:$ENV{PATH}";
dump_pgsql(%args);
} elsif ($args{db_type} eq 'MySQL') {
$ENV{PATH}="/usr/bin:$ENV{PATH}";
dump_mysql(%args);
} else {
die "This database type isn't supported";
}
}
open(FP, "$dir_conf -C '$cat'|") or die "Can't get catalog information $@";
# catalog=MyCatalog
# db_type=SQLite
# db_name=regress
# db_driver=
# db_user=regress
# db_password=
# db_address=
# db_port=0
# db_socket=
my %cfg;
while(my $l = <FP>)
{
if ($l =~ /catalog=(.+)/) {
if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
exit dump_catalog(%cfg);
}
%cfg = (); # reset
}
if ($l =~ /(\w+)=(.+)/) {
$cfg{$1}=$2;
}
}
if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
exit dump_catalog(%cfg);
}
print "Can't find your catalog ($cat) in director configuration\n";
exit 1;
|