6 This script dumps your Bacula catalog in ASCII format
7 It works for MySQL, SQLite, and PostgreSQL
11 make_catalog_backup.pl MyCatalog
15 Bacula® - The Network Backup Solution
17 Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
19 The main author of Bacula is Kern Sibbald, with contributions from
20 many others, a complete list can be found in the file AUTHORS.
22 This program is Free Software; you can redistribute it and/or
23 modify it under the terms of version two of the GNU General Public
24 License as published by the Free Software Foundation plus additions
25 that are listed in the file LICENSE.
27 This program is distributed in the hope that it will be useful, but
28 WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
37 Bacula® is a registered trademark of Kern Sibbald.
38 The licensor of Bacula is the Free Software Foundation Europe
39 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
40 Switzerland, email:ftf@fsfeurope.org.
44 my $cat = shift or die "Usage: $0 catalogname";
45 my $dir_conf='@sbindir@/dbcheck -B -c @sysconfdir@/bacula-dir.conf';
46 my $wd = "@working_dir@";
52 exec("echo .dump | sqlite '$wd/$args{db_name}.db' > '$wd/$args{db_name}.sql'");
53 print "Error while executing sqlite dump $!\n";
61 exec("echo .dump | sqlite3 '$wd/$args{db_name}.db' > '$wd/$args{db_name}.sql'");
62 print "Error while executing sqlite dump $!\n";
66 # TODO: use just ENV and drop the pg_service.conf file
72 if ($args{db_address}) {
73 $ENV{PGHOST}=$args{db_address};
76 $ENV{PGPORT}=$args{db_port};
79 $ENV{PGDATABASE}=$args{db_name};
80 $ENV{PGUSER}=$args{db_user};
81 $ENV{PGPASSWORD}=$args{db_password};
82 exec("HOME='$wd' pg_dump -c > '$wd/$args{db_name}.sql'");
83 print "Error while executing postgres dump $!\n";
84 return 1; # in case of error
91 unlink("$wd/.my.cnf");
92 open(MY, ">$wd/.my.cnf")
93 or die "Can't open $wd/.my.cnf for writing $@";
94 $args{db_address} = $args{db_address} || "localhost";
96 host=$args{db_address}
98 password=$args{db_password}
100 if ($args{db_port}) {
101 print MY "port=%args{db_port}\n";
106 exec("HOME='$wd' mysqldump -f --opt $args{db_name} > '$wd/$args{db_name}.sql'");
107 print "Error while executing mysql dump $!\n";
114 if ($args{db_type} eq 'SQLite') {
116 } elsif ($args{db_type} eq 'SQLite3') {
118 } elsif ($args{db_type} eq 'PostgreSQL') {
120 } elsif ($args{db_type} eq 'MySQL') {
123 die "This database type isn't supported";
127 open(FP, "$dir_conf|") or die "Can't get catalog information $@";
141 if ($l =~ /catalog=(.+)/) {
142 if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
143 exit dump_catalog(%cfg);
148 if ($l =~ /(\w+)=(.+)/) {
153 if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
154 exit dump_catalog(%cfg);
157 print "Can't find your catalog ($cat) in director configuration\n";