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-2014 Free Software Foundation Europe e.V.
19 The main author of Bacula is Kern Sibbald, with contributions from many
20 others, a complete list can be found in the file AUTHORS.
22 You may use this file and others of this release according to the
23 license defined in the LICENSE file, which includes the Affero General
24 Public License, v3.0 ("AGPLv3") and some additional permissions and
25 terms pursuant to its AGPLv3 Section 7.
27 Bacula® is a registered trademark of Kern Sibbald.
31 my $cat = shift or die "Usage: $0 catalogname";
32 my $dir_conf='@sbindir@/dbcheck -B -c @sysconfdir@/bacula-dir.conf';
33 my $wd = "@working_dir@";
39 exec("echo .dump | sqlite3 '$wd/$args{db_name}.db' > '$wd/$args{db_name}.sql'");
40 print "Error while executing sqlite dump $!\n";
44 # TODO: use just ENV and drop the pg_service.conf file
50 if ($args{db_address}) {
51 $ENV{PGHOST}=$args{db_address};
53 if ($args{db_socket}) {
54 $ENV{PGHOST}=$args{db_socket};
57 $ENV{PGPORT}=$args{db_port};
60 $ENV{PGUSER}=$args{db_user};
62 if ($args{db_password}) {
63 $ENV{PGPASSWORD}=$args{db_password};
65 $ENV{PGDATABASE}=$args{db_name};
66 exec("HOME='$wd' pg_dump -c > '$wd/$args{db_name}.sql'");
67 print "Error while executing postgres dump $!\n";
68 return 1; # in case of error
75 unlink("$wd/.my.cnf");
76 open(MY, ">$wd/.my.cnf")
77 or die "Can't open $wd/.my.cnf for writing $@";
79 $args{db_address} = $args{db_address} || "localhost";
80 my $addr = "host=$args{db_address}";
81 if ($args{db_socket}) { # unix socket is fastest than net socket
82 $addr = "socket=$args{db_socket}";
88 password=$args{db_password}
91 print MY "port=$args{db_port}\n";
96 exec("HOME='$wd' mysqldump -f --opt $args{db_name} > '$wd/$args{db_name}.sql'");
97 print "Error while executing mysql dump $!\n";
104 if ($args{db_type} eq 'SQLite3') {
105 $ENV{PATH}="@SQLITE_BINDIR@:$ENV{PATH}";
107 } elsif ($args{db_type} eq 'PostgreSQL') {
108 $ENV{PATH}="@POSTGRESQL_BINDIR@:$ENV{PATH}";
110 } elsif ($args{db_type} eq 'MySQL') {
111 $ENV{PATH}="@MYSQL_BINDIR@:$ENV{PATH}";
114 die "This database type isn't supported";
118 open(FP, "$dir_conf -C '$cat'|") or die "Can't get catalog information $@";
132 if ($l =~ /catalog=(.+)/) {
133 if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
134 exit dump_catalog(%cfg);
139 if ($l =~ /(\w+)=(.+)/) {
144 if (exists $cfg{catalog} and $cfg{catalog} eq $cat) {
145 exit dump_catalog(%cfg);
148 print "Can't find your catalog ($cat) in director configuration\n";